Add --extension option to generator.
[apps/agl-service-can-low-level.git] / example_unions / decode.c
index b20df84..b9f4af5 100644 (file)
@@ -17,7 +17,7 @@
 const pb_field_t* decode_unionmessage_type(pb_istream_t *stream)
 {
     pb_wire_type_t wire_type;
-    int tag;
+    uint32_t tag;
     bool eof;
 
     while (pb_decode_tag(stream, &wire_type, &tag, &eof))
@@ -44,10 +44,14 @@ const pb_field_t* decode_unionmessage_type(pb_istream_t *stream)
 
 bool decode_unionmessage_contents(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct)
 {
-    pb_field_t field = {}; /* NB: Could get rid of this wrapper by fixing issue #2. */
-    field.ptr = fields;
+    pb_istream_t substream;
+    bool status;
+    if (!pb_make_string_substream(stream, &substream))
+        return false;
     
-    return pb_dec_submessage(stream, &field, dest_struct);
+    status = pb_decode(&substream, fields, dest_struct);
+    pb_close_string_substream(stream, &substream);
+    return status;
 }
 
 int main()
@@ -81,7 +85,7 @@ int main()
     
     if (!status)
     {
-        printf("Decoding failed.\n");
+        printf("Decode failed: %s\n", PB_GET_ERROR(&stream));
         return 1;
     }