14#if (defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))) || \
15 (defined(__IAR_SYSTEMS_ICC__) && (__VER__ >= 9040001))
16 #define checkreturn __attribute__((warn_unused_result))
41#ifdef PB_WITHOUT_64BIT
42#define pb_int64_t int32_t
43#define pb_uint64_t uint32_t
45#define pb_int64_t int64_t
46#define pb_uint64_t uint64_t
56 stream->state = dest + count;
70 static const int marker = 0;
71 stream.callback = ▮
76 stream.max_size = bufsize;
77 stream.bytes_written = 0;
86 if (count > 0 && stream->callback !=
NULL)
88 if (stream->bytes_written + count < stream->bytes_written ||
89 stream->bytes_written + count > stream->max_size)
98 if (!stream->callback(stream, buf, count))
103 stream->bytes_written += count;
117 const char *p = (
const char *)pSize;
119 for (i = 0; i <
sizeof(
bool); i++)
132#ifndef PB_ENCODE_ARRAYS_UNPACKED
144#ifndef PB_ENCODE_ARRAYS_UNPACKED
163 void *pData_orig = field->pData;
164 for (i = 0; i < count; i++)
168 field->pData = (
char*)field->pData + field->data_size;
170 field->pData = pData_orig;
171 size = sizestream.bytes_written;
177 if (stream->callback ==
NULL)
181 for (i = 0; i < count; i++)
194 field->pData = (
char*)field->pData + field->data_size;
200 for (i = 0; i < count; i++)
211 void *pData_orig = field->pData;
212 field->pData = *(
void*
const*)field->pData;
225 field->pData = pData_orig;
235 field->pData = (
char*)field->pData + field->data_size;
258 return *(
const pb_size_t*)field->pSize == 0;
263 return *(
const pb_size_t*)field->pSize == 0;
271 else if (field->descriptor->default_value)
286 const char *p = (
const char*)field->pData;
287 for (i = 0; i < field->data_size; i++)
299 const pb_bytes_array_t *bytes = (
const pb_bytes_array_t*)field->pData;
300 return bytes->size == 0;
304 return *(
const char*)field->pData ==
'\0';
311 return field->data_size == 0;
321 pb_field_iter_t iter;
337 return field->pData ==
NULL;
343 const pb_extension_t *extension = *(
const pb_extension_t*
const *)field->pData;
344 return extension ==
NULL;
348 pb_callback_t *pCallback = (pb_callback_t*)field->pData;
349 return pCallback->funcs.encode ==
NULL;
353 return field->descriptor->field_callback ==
NULL;
409 if (field->descriptor->field_callback !=
NULL)
411 if (!field->descriptor->field_callback(
NULL, stream, field))
423 if (*(
const pb_size_t*)field->pSize != field->tag)
476 pb_field_iter_t iter;
489 const pb_extension_t *extension = *(
const pb_extension_t*
const *)field->pData;
494 if (extension->type->encode)
495 status = extension->type->encode(stream, extension);
502 extension = extension->next;
514 pb_field_iter_t iter;
546 if (!
pb_encode(stream, fields, src_struct))
553 return pb_encode(stream, fields, src_struct);
561 if (!
pb_encode(&stream, fields, src_struct))
564 *
size = stream.bytes_written;
580 while (i < 4 && (
low != 0 ||
high != 0))
617#ifdef PB_WITHOUT_64BIT
639#if defined(PB_LITTLE_ENDIAN_8BIT) && PB_LITTLE_ENDIAN_8BIT == 1
646 bytes[1] = (
pb_byte_t)((val >> 8) & 0xFF);
647 bytes[2] = (
pb_byte_t)((val >> 16) & 0xFF);
648 bytes[3] = (
pb_byte_t)((val >> 24) & 0xFF);
653#ifndef PB_WITHOUT_64BIT
656#if defined(PB_LITTLE_ENDIAN_8BIT) && PB_LITTLE_ENDIAN_8BIT == 1
663 bytes[1] = (
pb_byte_t)((val >> 8) & 0xFF);
664 bytes[2] = (
pb_byte_t)((val >> 16) & 0xFF);
665 bytes[3] = (
pb_byte_t)((val >> 24) & 0xFF);
666 bytes[4] = (
pb_byte_t)((val >> 32) & 0xFF);
667 bytes[5] = (
pb_byte_t)((val >> 40) & 0xFF);
668 bytes[6] = (
pb_byte_t)((val >> 48) & 0xFF);
669 bytes[7] = (
pb_byte_t)((val >> 56) & 0xFF);
731 if (!
pb_encode(&substream, fields, src_struct))
734 stream->errmsg = substream.errmsg;
739 size = substream.bytes_written;
744 if (stream->callback ==
NULL)
747 if (stream->bytes_written +
size > stream->max_size)
752 substream.callback = stream->callback;
753 substream.state = stream->state;
754 substream.max_size =
size;
755 substream.bytes_written = 0;
757 substream.errmsg =
NULL;
760 status =
pb_encode(&substream, fields, src_struct);
762 stream->bytes_written += substream.bytes_written;
763 stream->state = substream.state;
765 stream->errmsg = substream.errmsg;
768 if (substream.bytes_written !=
size)
794 else if (field->data_size ==
sizeof(
uint32_t))
795 value = *(
const uint32_t*)field->pData;
812 else if (field->data_size ==
sizeof(
int32_t))
813 value = *(
const int32_t*)field->pData;
814 else if (field->data_size ==
sizeof(
pb_int64_t))
821#ifdef PB_WITHOUT_64BIT
833#ifdef PB_CONVERT_DOUBLE_FLOAT
836 return pb_encode_float_as_double(stream, *(
float*)field->pData);
840 if (field->data_size ==
sizeof(
uint32_t))
844#ifndef PB_WITHOUT_64BIT
845 else if (field->data_size ==
sizeof(
uint64_t))
858 const pb_bytes_array_t *bytes =
NULL;
860 bytes = (
const pb_bytes_array_t*)field->pData;
869 bytes->size > field->data_size -
offsetof(pb_bytes_array_t, bytes))
880 size_t max_size = (
size_t)field->data_size;
881 const char *str = (
const char*)field->pData;
910 while (
size < max_size && *p !=
'\0')
922#ifdef PB_VALIDATE_UTF8
923 if (!pb_validate_utf8(str))
932 if (field->submsg_desc ==
NULL)
938 pb_callback_t *
callback = (pb_callback_t*)field->pSize - 1;
954#ifdef PB_CONVERT_DOUBLE_FLOAT
955bool pb_encode_float_as_double(pb_ostream_t *stream,
float value)
966 exponent = (
int)((in.i >> 23) & 0xFF) - 127;
967 mantissa = in.i & 0x7FFFFF;
974 else if (exponent == -127)
985 while (!(mantissa & 0x800000))
990 mantissa &= 0x7FFFFF;
996 mantissa |= (
uint64_t)(exponent + 1023) << 52;
bool callback(pb_istream_t *stream, uint8_t *buf, size_t count)
MOSAPI int(2, 3) sprintf(char *__restrict str
#define PB_LTYPE_SUBMSG_W_CB
#define PB_GET_ERROR(stream)
#define PB_LTYPE_EXTENSION
#define PB_ATYPE_CALLBACK
bool pb_default_field_callback(pb_istream_t *istream, pb_ostream_t *ostream, const pb_field_t *field)
#define PB_HTYPE_REQUIRED
#define PB_LTYPE_LAST_PACKABLE
#define PB_HTYPE_OPTIONAL
#define PB_HTYPE_REPEATED
#define PB_LTYPE_FIXED_LENGTH_BYTES
#define PB_RETURN_ERROR(stream, msg)
#define PB_LTYPE_IS_SUBMSG(x)
#define PB_LTYPE_SUBMESSAGE
bool pb_field_iter_next(pb_field_iter_t *iter)
bool pb_field_iter_begin_extension_const(pb_field_iter_t *iter, const pb_extension_t *extension)
bool pb_field_iter_begin(pb_field_iter_t *iter, const pb_msgdesc_t *desc, void *message)
bool pb_field_iter_begin_const(pb_field_iter_t *iter, const pb_msgdesc_t *desc, const void *message)
static bool buf_write(pb_ostream_t *stream, const pb_byte_t *buf, size_t count)
static bool encode_extension_field(pb_ostream_t *stream, const pb_field_iter_t *field)
bool pb_encode_ex(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_struct, unsigned int flags)
static bool pb_encode_varint_32(pb_ostream_t *stream, uint32_t low, uint32_t high)
bool pb_encode_tag_for_field(pb_ostream_t *stream, const pb_field_iter_t *field)
static bool encode_callback_field(pb_ostream_t *stream, const pb_field_iter_t *field)
static bool pb_enc_string(pb_ostream_t *stream, const pb_field_iter_t *field)
static bool pb_check_proto3_default_value(const pb_field_iter_t *field)
bool pb_encode_varint(pb_ostream_t *stream, uint64_t value)
static bool encode_field(pb_ostream_t *stream, pb_field_iter_t *field)
bool pb_encode_submessage(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_struct)
static bool encode_basic_field(pb_ostream_t *stream, const pb_field_iter_t *field)
bool pb_write(pb_ostream_t *stream, const pb_byte_t *buf, size_t count)
bool pb_get_encoded_size(size_t *size, const pb_msgdesc_t *fields, const void *src_struct)
static bool pb_enc_fixed(pb_ostream_t *stream, const pb_field_iter_t *field)
static bool pb_enc_fixed_length_bytes(pb_ostream_t *stream, const pb_field_iter_t *field)
pb_ostream_t pb_ostream_from_buffer(pb_byte_t *buf, size_t bufsize)
static bool pb_enc_submessage(pb_ostream_t *stream, const pb_field_iter_t *field)
bool pb_encode_fixed64(pb_ostream_t *stream, const void *value)
static bool default_extension_encoder(pb_ostream_t *stream, const pb_extension_t *extension)
bool pb_encode_tag(pb_ostream_t *stream, pb_wire_type_t wiretype, uint32_t field_number)
static bool pb_enc_bytes(pb_ostream_t *stream, const pb_field_iter_t *field)
bool pb_encode_fixed32(pb_ostream_t *stream, const void *value)
static bool safe_read_bool(const void *pSize)
bool pb_encode_svarint(pb_ostream_t *stream, int64_t value)
bool pb_encode(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_struct)
static bool pb_enc_bool(pb_ostream_t *stream, const pb_field_iter_t *field)
bool pb_encode_string(pb_ostream_t *stream, const pb_byte_t *buffer, size_t size)
static bool encode_array(pb_ostream_t *stream, pb_field_iter_t *field)
static bool pb_enc_varint(pb_ostream_t *stream, const pb_field_iter_t *field)
#define PB_OSTREAM_SIZING
#define PB_ENCODE_NULLTERMINATED
#define PB_ENCODE_DELIMITED
static void * memcpy(void *s1, const void *s2, size_t n)
unsigned long long uint64_t