Decoding unknown field should succeed.

This commit is contained in:
Bo Yang 2017-01-10 11:00:03 -08:00
parent e259b515a5
commit 60d4f8af48
4 changed files with 17 additions and 1 deletions

View file

@ -400,6 +400,11 @@ class Message
$number = GPBWire::getTagFieldNumber($tag);
$field = $this->desc->getFieldByNumber($number);
// Check whether we retrieved a known field
if ($field === NULL) {
continue;
}
if (!$this->parseFieldFromStream($tag, $input, $field)) {
return false;
}

View file

@ -155,7 +155,11 @@ class Descriptor
public function getFieldByNumber($number)
{
if (!isset($this->field[$number])) {
return NULL;
} else {
return $this->field[$number];
}
}
public function setClass($klass)

View file

@ -167,4 +167,10 @@ class EncodeDecodeTest extends TestBase
$this->assertEquals($original, $msg->getOptionalInt64());
}
}
public function testDecodeFieldNonExist() {
$data = hex2bin('c80501');
$m = new TestMessage();
$m->decode($data);
}
}

View file

@ -92,7 +92,8 @@ message TestMessage {
int32 a = 1;
}
// NestedMessage nested_message = 90;
// Reserved for non-existing field test.
// int32 non_exist = 89;
}
enum TestEnum {