More unittests
[apps/agl-service-can-low-level.git] / pb_encode.c
index 2a4d8e1..e83e068 100644 (file)
@@ -67,6 +67,10 @@ bool checkreturn pb_write(pb_ostream_t *stream, const uint8_t *buf, size_t count
 
 /* Main encoding stuff */
 
+/* Callbacks don't need this function because they usually know the data type
+ * without examining the field structure.
+ * Therefore it is static for now.
+ */
 static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *field,
                          const void *pData, size_t count, pb_encoder_t func)
 {
@@ -74,7 +78,10 @@ static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *fie
     const void *p;
     size_t size;
     
-    if (PB_LTYPE(field->type) < PB_LTYPE_LAST_PACKABLE)
+    if (count == 0)
+        return true;
+    
+    if (PB_LTYPE(field->type) <= PB_LTYPE_LAST_PACKABLE)
     {
         if (!pb_encode_tag(stream, PB_WT_STRING, field->tag))
             return false;