Cleanup of comments.
This commit is contained in:
15
pb_decode.c
15
pb_decode.c
@@ -3,11 +3,13 @@
|
|||||||
* 2011 Petteri Aimonen <jpa@kapsi.fi>
|
* 2011 Petteri Aimonen <jpa@kapsi.fi>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* 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)
|
#if !defined(__GNUC__) || ( __GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
|
||||||
#define checkreturn
|
#define checkreturn
|
||||||
#else
|
#else
|
||||||
/* Verify that we remember to check all return values for proper error propagation */
|
|
||||||
#define checkreturn __attribute__((warn_unused_result))
|
#define checkreturn __attribute__((warn_unused_result))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -15,11 +17,10 @@
|
|||||||
#include "pb.h"
|
#include "pb.h"
|
||||||
#include "pb_decode.h"
|
#include "pb_decode.h"
|
||||||
|
|
||||||
typedef bool (*pb_decoder_t)(pb_istream_t *stream, const pb_field_t *field, void *dest) checkreturn;
|
|
||||||
|
|
||||||
/* --- Function pointers to field decoders ---
|
/* --- Function pointers to field decoders ---
|
||||||
* Order in the array must match pb_action_t LTYPE numbering.
|
* Order in the array must match pb_action_t LTYPE numbering.
|
||||||
*/
|
*/
|
||||||
|
typedef bool (*pb_decoder_t)(pb_istream_t *stream, const pb_field_t *field, void *dest) checkreturn;
|
||||||
static const pb_decoder_t PB_DECODERS[PB_LTYPES_COUNT] = {
|
static const pb_decoder_t PB_DECODERS[PB_LTYPES_COUNT] = {
|
||||||
&pb_dec_varint,
|
&pb_dec_varint,
|
||||||
&pb_dec_svarint,
|
&pb_dec_svarint,
|
||||||
@@ -32,9 +33,9 @@ static const pb_decoder_t PB_DECODERS[PB_LTYPES_COUNT] = {
|
|||||||
NULL /* extensions */
|
NULL /* extensions */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**************
|
/*******************************
|
||||||
* pb_istream *
|
* pb_istream_t implementation *
|
||||||
**************/
|
*******************************/
|
||||||
|
|
||||||
static bool checkreturn buf_read(pb_istream_t *stream, uint8_t *buf, size_t count)
|
static bool checkreturn buf_read(pb_istream_t *stream, uint8_t *buf, size_t count)
|
||||||
{
|
{
|
||||||
|
|||||||
27
pb_encode.c
27
pb_encode.c
@@ -7,19 +7,20 @@
|
|||||||
#include "pb.h"
|
#include "pb.h"
|
||||||
#include "pb_encode.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)
|
#if !defined(__GNUC__) || ( __GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)
|
||||||
#define checkreturn
|
#define checkreturn
|
||||||
#else
|
#else
|
||||||
/* Verify that we remember to check all return values for proper error propagation */
|
|
||||||
#define checkreturn __attribute__((warn_unused_result))
|
#define checkreturn __attribute__((warn_unused_result))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef bool (*pb_encoder_t)(pb_ostream_t *stream, const pb_field_t *field, const void *src) checkreturn;
|
|
||||||
|
|
||||||
/* --- Function pointers to field encoders ---
|
/* --- Function pointers to field encoders ---
|
||||||
* Order in the array must match pb_action_t LTYPE numbering.
|
* Order in the array must match pb_action_t LTYPE numbering.
|
||||||
*/
|
*/
|
||||||
|
typedef bool (*pb_encoder_t)(pb_ostream_t *stream, const pb_field_t *field, const void *src) checkreturn;
|
||||||
static const pb_encoder_t PB_ENCODERS[PB_LTYPES_COUNT] = {
|
static const pb_encoder_t PB_ENCODERS[PB_LTYPES_COUNT] = {
|
||||||
&pb_enc_varint,
|
&pb_enc_varint,
|
||||||
&pb_enc_svarint,
|
&pb_enc_svarint,
|
||||||
@@ -32,7 +33,9 @@ static const pb_encoder_t PB_ENCODERS[PB_LTYPES_COUNT] = {
|
|||||||
NULL /* extensions */
|
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)
|
static bool checkreturn buf_write(pb_ostream_t *stream, const uint8_t *buf, size_t count)
|
||||||
{
|
{
|
||||||
@@ -49,7 +52,7 @@ pb_ostream_t pb_ostream_from_buffer(uint8_t *buf, size_t bufsize)
|
|||||||
{
|
{
|
||||||
pb_ostream_t stream;
|
pb_ostream_t stream;
|
||||||
#ifdef PB_BUFFER_ONLY
|
#ifdef PB_BUFFER_ONLY
|
||||||
stream.callback = (void*)1; /* Just some marker value */
|
stream.callback = (void*)1; /* Just a marker value */
|
||||||
#else
|
#else
|
||||||
stream.callback = &buf_write;
|
stream.callback = &buf_write;
|
||||||
#endif
|
#endif
|
||||||
@@ -82,7 +85,9 @@ bool checkreturn pb_write(pb_ostream_t *stream, const uint8_t *buf, size_t count
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Main encoding stuff */
|
/*************************
|
||||||
|
* Encode a single field *
|
||||||
|
*************************/
|
||||||
|
|
||||||
/* Encode a static array. Handles the size calculations and possible packing. */
|
/* 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,
|
static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *field,
|
||||||
@@ -277,6 +282,10 @@ static bool checkreturn encode_extension_field(pb_ostream_t *stream,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*********************
|
||||||
|
* Encode all fields *
|
||||||
|
*********************/
|
||||||
|
|
||||||
bool checkreturn pb_encode(pb_ostream_t *stream, const pb_field_t fields[], const void *src_struct)
|
bool checkreturn pb_encode(pb_ostream_t *stream, const pb_field_t fields[], const void *src_struct)
|
||||||
{
|
{
|
||||||
const pb_field_t *field = fields;
|
const pb_field_t *field = fields;
|
||||||
@@ -319,7 +328,9 @@ bool pb_encode_delimited(pb_ostream_t *stream, const pb_field_t fields[], const
|
|||||||
return pb_encode_submessage(stream, fields, src_struct);
|
return pb_encode_submessage(stream, fields, src_struct);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper functions */
|
/********************
|
||||||
|
* Helper functions *
|
||||||
|
********************/
|
||||||
bool checkreturn pb_encode_varint(pb_ostream_t *stream, uint64_t value)
|
bool checkreturn pb_encode_varint(pb_ostream_t *stream, uint64_t value)
|
||||||
{
|
{
|
||||||
uint8_t buffer[10];
|
uint8_t buffer[10];
|
||||||
|
|||||||
Reference in New Issue
Block a user