Check for supported GCC CCFLAGS when building tests.
[apps/agl-service-can-low-level.git] / pb_encode.c
index cbf7a66..c2d0e2c 100644 (file)
@@ -195,9 +195,9 @@ static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *fie
     return true;
 }
 
-/* Encode a field with static allocation, i.e. one whose data is stored
- * in the structure itself. */
-static bool checkreturn encode_static_field(pb_ostream_t *stream,
+/* Encode a field with static or pointer allocation, i.e. one whose data
+ * is available to the encoder directly. */
+static bool checkreturn encode_basic_field(pb_ostream_t *stream,
     const pb_field_t *field, const void *pData)
 {
     pb_encoder_t func;
@@ -226,7 +226,7 @@ static bool checkreturn encode_static_field(pb_ostream_t *stream,
     {
         case PB_HTYPE_REQUIRED:
             if (!pData)
-                return false;
+                PB_RETURN_ERROR(stream, "missing required field");
             if (!pb_encode_tag_for_field(stream, field))
                 return false;
             if (!func(stream, field, pData))
@@ -285,7 +285,7 @@ static bool checkreturn encode_field(pb_ostream_t *stream,
     {
         case PB_ATYPE_STATIC:
         case PB_ATYPE_POINTER:
-            return encode_static_field(stream, field, pData);
+            return encode_basic_field(stream, field, pData);
         
         case PB_ATYPE_CALLBACK:
             return encode_callback_field(stream, field, pData);
@@ -499,7 +499,12 @@ bool checkreturn pb_encode_submessage(pb_ostream_t *stream, const pb_field_t fie
     bool status;
     
     if (!pb_encode(&substream, fields, src_struct))
+    {
+#ifndef PB_NO_ERRMSG
+        stream->errmsg = substream.errmsg;
+#endif
         return false;
+    }
     
     size = substream.bytes_written;
     
@@ -598,14 +603,14 @@ bool checkreturn pb_enc_fixed32(pb_ostream_t *stream, const pb_field_t *field, c
 
 bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *field, const void *src)
 {
-    const pb_bytes_array_t *bytes = (const pb_bytes_array_t*)src;
-
     if (PB_ATYPE(field->type) == PB_ATYPE_POINTER)
     {
-        return pb_encode_string(stream, *(const uint8_t**)bytes->bytes, bytes->size);
+        const pb_bytes_ptr_t *bytes = (const pb_bytes_ptr_t*)src;
+        return pb_encode_string(stream, bytes->bytes, bytes->size);
     }
     else
     {
+        const pb_bytes_array_t *bytes = (const pb_bytes_array_t*)src;
         if (bytes->size + offsetof(pb_bytes_array_t, bytes) > field->data_size)
             PB_RETURN_ERROR(stream, "bytes size exceeded");