#include "pb_encode.h"
#include <string.h>
-#ifdef __GNUC__
-/* Verify that we remember to check all return values for proper error propagation */
-#define checkreturn __attribute__((warn_unused_result))
+/* The warn_unused_result attribute appeared first in gcc-3.4.0 */
+#if !defined(__GNUC__) || ( __GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
+ #define checkreturn
#else
-#define checkreturn
+ /* Verify that we remember to check all return values for proper error propagation */
+ #define checkreturn __attribute__((warn_unused_result))
#endif
-
typedef bool (*pb_encoder_t)(pb_ostream_t *stream, const pb_field_t *field, const void *src) checkreturn;
/* --- Function pointers to field encoders ---
}
else
{
- pb_ostream_t sizestream = {0};
+ pb_ostream_t sizestream = {0,0,0,0};
p = pData;
for (i = 0; i < count; i++)
{
size = sizestream.bytes_written;
}
- if (!pb_encode_varint(stream, size))
+ if (!pb_encode_varint(stream, (uint64_t)size))
return false;
if (stream->callback == NULL)
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)
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);
bool checkreturn pb_encode_submessage(pb_ostream_t *stream, const pb_field_t fields[], const void *src_struct)
{
/* First calculate the message size using a non-writing substream. */
- pb_ostream_t substream = {0};
+ pb_ostream_t substream = {0,0,0,0};
size_t size;
bool status;
size = substream.bytes_written;
- if (!pb_encode_varint(stream, size))
+ if (!pb_encode_varint(stream, (uint64_t)size))
return false;
if (stream->callback == NULL)