Apparently some compilers don't want to automatically cast size_t to uint64_t.
[apps/agl-service-can-low-level.git] / pb_encode.c
index 1817373..be909ec 100644 (file)
@@ -110,7 +110,7 @@ static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *fie
             size = sizestream.bytes_written;
         }
         
-        if (!pb_encode_varint(stream, size))
+        if (!pb_encode_varint(stream, (uint64_t)size))
             return false;
         
         if (stream->callback == NULL)
@@ -235,8 +235,12 @@ bool checkreturn pb_encode_svarint(pb_ostream_t *stream, int64_t value)
 bool checkreturn pb_encode_fixed32(pb_ostream_t *stream, const void *value)
 {
     #ifdef __BIG_ENDIAN__
-    uint8_t *bytes = value;
-    uint8_t lebytes[4] = {bytes[3], bytes[2], bytes[1], bytes[0]};
+    const uint8_t *bytes = value;
+    uint8_t lebytes[4];
+    lebytes[0] = bytes[3];
+    lebytes[1] = bytes[2];
+    lebytes[2] = bytes[1];
+    lebytes[3] = bytes[0];
     return pb_write(stream, lebytes, 4);
     #else
     return pb_write(stream, (uint8_t*)value, 4);
@@ -246,9 +250,16 @@ bool checkreturn pb_encode_fixed32(pb_ostream_t *stream, const void *value)
 bool checkreturn pb_encode_fixed64(pb_ostream_t *stream, const void *value)
 {
     #ifdef __BIG_ENDIAN__
-    uint8_t *bytes[8] = value;
-    uint8_t lebytes[8] = {bytes[7], bytes[6], bytes[5], bytes[4], 
-                          bytes[3], bytes[2], bytes[1], bytes[0]};
+    const uint8_t *bytes = value;
+    uint8_t lebytes[8];
+    lebytes[0] = bytes[7];
+    lebytes[1] = bytes[6];
+    lebytes[2] = bytes[5];
+    lebytes[3] = bytes[4];
+    lebytes[4] = bytes[3];
+    lebytes[5] = bytes[2];
+    lebytes[6] = bytes[1];
+    lebytes[7] = bytes[0];
     return pb_write(stream, lebytes, 8);
     #else
     return pb_write(stream, (uint8_t*)value, 8);
@@ -258,7 +269,7 @@ bool checkreturn pb_encode_fixed64(pb_ostream_t *stream, const void *value)
 bool checkreturn pb_encode_tag(pb_ostream_t *stream, pb_wire_type_t wiretype, int field_number)
 {
     int tag = wiretype | (field_number << 3);
-    return pb_encode_varint(stream, tag);
+    return pb_encode_varint(stream, (uint64_t)tag);
 }
 
 bool checkreturn pb_encode_tag_for_field(pb_ostream_t *stream, const pb_field_t *field)
@@ -294,7 +305,7 @@ bool checkreturn pb_encode_tag_for_field(pb_ostream_t *stream, const pb_field_t
 
 bool checkreturn pb_encode_string(pb_ostream_t *stream, const uint8_t *buffer, size_t size)
 {
-    if (!pb_encode_varint(stream, size))
+    if (!pb_encode_varint(stream, (uint64_t)size))
         return false;
     
     return pb_write(stream, buffer, size);
@@ -312,7 +323,7 @@ bool checkreturn pb_encode_submessage(pb_ostream_t *stream, const pb_field_t fie
     
     size = substream.bytes_written;
     
-    if (!pb_encode_varint(stream, size))
+    if (!pb_encode_varint(stream, (uint64_t)size))
         return false;
     
     if (stream->callback == NULL)