Commit 60d4f8af authored by Bo Yang's avatar Bo Yang

Decoding unknown field should succeed.

parent e259b515
......@@ -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;
}
......
......@@ -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)
......
......@@ -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);
}
}
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment