X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=pb_encode.c;h=90236524a921ddca7eba6b5fae31a5068077a2a3;hb=0074deba9a2ff99c877abe1293f72a9ed76f46c1;hp=e97d04fb00240061e111e5dc1a8279a66a35612b;hpb=cd3af3272d170f4990ef745316faa7600571ef4e;p=apps%2Fagl-service-can-low-level.git diff --git a/pb_encode.c b/pb_encode.c index e97d04fb..90236524 100644 --- a/pb_encode.c +++ b/pb_encode.c @@ -7,16 +7,28 @@ #include "pb.h" #include "pb_encode.h" -/* The warn_unused_result attribute appeared first in gcc-3.4.0 */ +/* Use the GCC warn_unused_result attribute to check that all return values + * are propagated correctly. On other compilers and gcc before 3.4.0 just + * ignore the annotation. + */ #if !defined(__GNUC__) || ( __GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 4) #define checkreturn #else - /* Verify that we remember to check all return values for proper error propagation */ #define checkreturn __attribute__((warn_unused_result)) #endif +/************************************** + * Declarations internal to this file * + **************************************/ typedef bool (*pb_encoder_t)(pb_ostream_t *stream, const pb_field_t *field, const void *src) checkreturn; +static bool checkreturn buf_write(pb_ostream_t *stream, const uint8_t *buf, size_t count); +static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *field, const void *pData, size_t count, pb_encoder_t func); +static bool checkreturn encode_field(pb_ostream_t *stream, const pb_field_t *field, const void *pData); +static bool checkreturn default_extension_encoder(pb_ostream_t *stream, const pb_extension_t *extension); +static bool checkreturn encode_extension_field(pb_ostream_t *stream, const pb_field_t *field, const void *pData); + + /* --- Function pointers to field encoders --- * Order in the array must match pb_action_t LTYPE numbering. */ @@ -32,7 +44,9 @@ static const pb_encoder_t PB_ENCODERS[PB_LTYPES_COUNT] = { NULL /* extensions */ }; -/* pb_ostream_t implementation */ +/******************************* + * pb_ostream_t implementation * + *******************************/ static bool checkreturn buf_write(pb_ostream_t *stream, const uint8_t *buf, size_t count) { @@ -49,7 +63,7 @@ pb_ostream_t pb_ostream_from_buffer(uint8_t *buf, size_t bufsize) { pb_ostream_t stream; #ifdef PB_BUFFER_ONLY - stream.callback = (void*)1; /* Just some marker value */ + stream.callback = (void*)1; /* Just a marker value */ #else stream.callback = &buf_write; #endif @@ -82,7 +96,9 @@ bool checkreturn pb_write(pb_ostream_t *stream, const uint8_t *buf, size_t count return true; } -/* Main encoding stuff */ +/************************* + * Encode a single field * + *************************/ /* Encode a static array. Handles the size calculations and possible packing. */ static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *field, @@ -277,6 +293,10 @@ static bool checkreturn encode_extension_field(pb_ostream_t *stream, return true; } +/********************* + * Encode all fields * + *********************/ + bool checkreturn pb_encode(pb_ostream_t *stream, const pb_field_t fields[], const void *src_struct) { const pb_field_t *field = fields; @@ -319,7 +339,9 @@ bool pb_encode_delimited(pb_ostream_t *stream, const pb_field_t fields[], const return pb_encode_submessage(stream, fields, src_struct); } -/* Helper functions */ +/******************** + * Helper functions * + ********************/ bool checkreturn pb_encode_varint(pb_ostream_t *stream, uint64_t value) { uint8_t buffer[10];