Add a 'found' field to pb_extension_t.

Update issue 112
Status: FixedInGit
This commit is contained in:
Petteri Aimonen
2014-04-05 11:11:05 +03:00
parent 70dee34da6
commit e5b855fec5
4 changed files with 8 additions and 2 deletions

4
pb.h
View File

@@ -341,6 +341,10 @@ struct _pb_extension_t {
* If this extension does not match a field, the next handler is * If this extension does not match a field, the next handler is
* automatically called. */ * automatically called. */
pb_extension_t *next; pb_extension_t *next;
/* The decoder sets this to true if the extension was found.
* Ignored for encoding. */
bool found;
}; };
/* Memory allocation functions to use. You can define pb_realloc and /* Memory allocation functions to use. You can define pb_realloc and

View File

@@ -670,7 +670,6 @@ static bool checkreturn default_extension_decoder(pb_istream_t *stream,
{ {
const pb_field_t *field = (const pb_field_t*)extension->type->arg; const pb_field_t *field = (const pb_field_t*)extension->type->arg;
pb_field_iterator_t iter; pb_field_iterator_t iter;
bool dummy;
if (field->tag != tag) if (field->tag != tag)
return true; return true;
@@ -681,7 +680,7 @@ static bool checkreturn default_extension_decoder(pb_istream_t *stream,
iter.required_field_index = 0; iter.required_field_index = 0;
iter.dest_struct = extension->dest; iter.dest_struct = extension->dest;
iter.pData = extension->dest; iter.pData = extension->dest;
iter.pSize = &dummy; iter.pSize = &extension->found;
return decode_field(stream, wire_type, &iter); return decode_field(stream, wire_type, &iter);
} }

View File

@@ -49,7 +49,9 @@ int main(int argc, char **argv)
} }
/* Check that the extensions decoded properly */ /* Check that the extensions decoded properly */
TEST(ext1.found)
TEST(extensionfield1 == 12345) TEST(extensionfield1 == 12345)
TEST(ext2.found)
TEST(strcmp(extensionfield2.test1, "test") == 0) TEST(strcmp(extensionfield2.test1, "test") == 0)
TEST(extensionfield2.test2 == 54321) TEST(extensionfield2.test2 == 54321)

View File

@@ -27,6 +27,7 @@
-dependenttrans -dependenttrans
-kepttrans -kepttrans
-branchstate -branchstate
-immediatetrans
# These tests give false positives, compiler typically has # These tests give false positives, compiler typically has
# better warnings for these. # better warnings for these.