Lines Matching refs:stream
34 typedef bool (*pb_decoder_t)(pb_istream_t *stream, const pb_field_t *field, void *dest) checkreturn;
36 static bool checkreturn buf_read(pb_istream_t *stream, uint8_t *buf, size_t count);
37 static bool checkreturn pb_decode_varint32(pb_istream_t *stream, uint32_t *dest);
38 static bool checkreturn read_raw_value(pb_istream_t *stream, pb_wire_type_t wire_type, uint8_t *buf…
42 static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fiel…
43 static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fi…
44 static bool checkreturn decode_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_itera…
45 static bool checkreturn default_extension_decoder(pb_istream_t *stream, pb_extension_t *extension, …
46 static bool checkreturn decode_extension(pb_istream_t *stream, uint32_t tag, pb_wire_type_t wire_ty…
49 static bool checkreturn pb_dec_varint(pb_istream_t *stream, const pb_field_t *field, void *dest);
50 static bool checkreturn pb_dec_uvarint(pb_istream_t *stream, const pb_field_t *field, void *dest);
51 static bool checkreturn pb_dec_svarint(pb_istream_t *stream, const pb_field_t *field, void *dest);
52 static bool checkreturn pb_dec_fixed32(pb_istream_t *stream, const pb_field_t *field, void *dest);
53 static bool checkreturn pb_dec_fixed64(pb_istream_t *stream, const pb_field_t *field, void *dest);
54 static bool checkreturn pb_dec_bytes(pb_istream_t *stream, const pb_field_t *field, void *dest);
55 static bool checkreturn pb_dec_string(pb_istream_t *stream, const pb_field_t *field, void *dest);
56 static bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field, void *dest…
57 static bool checkreturn pb_skip_varint(pb_istream_t *stream);
58 static bool checkreturn pb_skip_string(pb_istream_t *stream);
80 static bool checkreturn buf_read(pb_istream_t *stream, uint8_t *buf, size_t count) in buf_read() argument
82 uint8_t *source = (uint8_t*)stream->state; in buf_read()
83 stream->state = source + count; in buf_read()
94 bool checkreturn pb_read(pb_istream_t *stream, uint8_t *buf, size_t count) in pb_read() argument
97 if (buf == NULL && stream->callback != buf_read) in pb_read()
103 if (!pb_read(stream, tmp, 16)) in pb_read()
109 return pb_read(stream, tmp, count); in pb_read()
113 if (stream->bytes_left < count) in pb_read()
114 PB_RETURN_ERROR(stream, "end-of-stream"); in pb_read()
117 if (!stream->callback(stream, buf, count)) in pb_read()
118 PB_RETURN_ERROR(stream, "io error"); in pb_read()
120 if (!buf_read(stream, buf, count)) in pb_read()
124 stream->bytes_left -= count; in pb_read()
130 static bool checkreturn pb_readbyte(pb_istream_t *stream, uint8_t *buf) in pb_readbyte() argument
132 if (stream->bytes_left == 0) in pb_readbyte()
133 PB_RETURN_ERROR(stream, "end-of-stream"); in pb_readbyte()
136 if (!stream->callback(stream, buf, 1)) in pb_readbyte()
137 PB_RETURN_ERROR(stream, "io error"); in pb_readbyte()
139 *buf = *(uint8_t*)stream->state; in pb_readbyte()
140 stream->state = (uint8_t*)stream->state + 1; in pb_readbyte()
143 stream->bytes_left--; in pb_readbyte()
150 pb_istream_t stream; in pb_istream_from_buffer() local
152 stream.callback = NULL; in pb_istream_from_buffer()
154 stream.callback = &buf_read; in pb_istream_from_buffer()
156 stream.state = buf; in pb_istream_from_buffer()
157 stream.bytes_left = bufsize; in pb_istream_from_buffer()
159 stream.errmsg = NULL; in pb_istream_from_buffer()
161 return stream; in pb_istream_from_buffer()
168 static bool checkreturn pb_decode_varint32(pb_istream_t *stream, uint32_t *dest) in pb_decode_varint32() argument
173 if (!pb_readbyte(stream, &byte)) in pb_decode_varint32()
190 PB_RETURN_ERROR(stream, "varint overflow"); in pb_decode_varint32()
192 if (!pb_readbyte(stream, &byte)) in pb_decode_varint32()
204 bool checkreturn pb_decode_varint(pb_istream_t *stream, uint64_t *dest) in pb_decode_varint() argument
213 PB_RETURN_ERROR(stream, "varint overflow"); in pb_decode_varint()
215 if (!pb_readbyte(stream, &byte)) in pb_decode_varint()
226 bool checkreturn pb_skip_varint(pb_istream_t *stream) in pb_skip_varint() argument
231 if (!pb_read(stream, &byte, 1)) in pb_skip_varint()
237 bool checkreturn pb_skip_string(pb_istream_t *stream) in pb_skip_string() argument
240 if (!pb_decode_varint32(stream, &length)) in pb_skip_string()
243 return pb_read(stream, NULL, length); in pb_skip_string()
246 bool checkreturn pb_decode_tag(pb_istream_t *stream, pb_wire_type_t *wire_type, uint32_t *tag, bool… in pb_decode_tag() argument
253 if (!pb_decode_varint32(stream, &temp)) in pb_decode_tag()
255 if (stream->bytes_left == 0) in pb_decode_tag()
272 bool checkreturn pb_skip_field(pb_istream_t *stream, pb_wire_type_t wire_type) in pb_skip_field() argument
276 case PB_WT_VARINT: return pb_skip_varint(stream); in pb_skip_field()
277 case PB_WT_64BIT: return pb_read(stream, NULL, 8); in pb_skip_field()
278 case PB_WT_STRING: return pb_skip_string(stream); in pb_skip_field()
279 case PB_WT_32BIT: return pb_read(stream, NULL, 4); in pb_skip_field()
280 default: PB_RETURN_ERROR(stream, "invalid wire_type"); in pb_skip_field()
287 static bool checkreturn read_raw_value(pb_istream_t *stream, pb_wire_type_t wire_type, uint8_t *buf… in read_raw_value() argument
298 if (!pb_read(stream, buf, 1)) return false; in read_raw_value()
304 return pb_read(stream, buf, 8); in read_raw_value()
308 return pb_read(stream, buf, 4); in read_raw_value()
310 default: PB_RETURN_ERROR(stream, "invalid wire_type"); in read_raw_value()
317 bool checkreturn pb_make_string_substream(pb_istream_t *stream, pb_istream_t *substream) in pb_make_string_substream() argument
320 if (!pb_decode_varint32(stream, &size)) in pb_make_string_substream()
323 *substream = *stream; in pb_make_string_substream()
325 PB_RETURN_ERROR(stream, "parent stream too short"); in pb_make_string_substream()
328 stream->bytes_left -= size; in pb_make_string_substream()
332 void pb_close_string_substream(pb_istream_t *stream, pb_istream_t *substream) in pb_close_string_substream() argument
334 stream->state = substream->state; in pb_close_string_substream()
337 stream->errmsg = substream->errmsg; in pb_close_string_substream()
409 static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fiel… in decode_static_field() argument
420 return func(stream, iter->pos, iter->pData); in decode_static_field()
424 return func(stream, iter->pos, iter->pData); in decode_static_field()
434 if (!pb_make_string_substream(stream, &substream)) in decode_static_field()
447 pb_close_string_substream(stream, &substream); in decode_static_field()
450 PB_RETURN_ERROR(stream, "array overflow"); in decode_static_field()
460 PB_RETURN_ERROR(stream, "array overflow"); in decode_static_field()
463 return func(stream, iter->pos, pItem); in decode_static_field()
467 PB_RETURN_ERROR(stream, "invalid field type"); in decode_static_field()
474 static bool checkreturn allocate_field(pb_istream_t *stream, void *pData, size_t data_size, size_t … in allocate_field() argument
484 PB_RETURN_ERROR(stream, "realloc failed"); in allocate_field()
505 static bool checkreturn decode_pointer_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fie… in decode_pointer_field() argument
510 PB_RETURN_ERROR(stream, "no malloc support"); in decode_pointer_field()
525 return func(stream, iter->pos, iter->pData); in decode_pointer_field()
529 if (!allocate_field(stream, iter->pData, iter->pos->data_size, 1)) in decode_pointer_field()
533 return func(stream, iter->pos, *(void**)iter->pData); in decode_pointer_field()
547 if (!pb_make_string_substream(stream, &substream)) in decode_pointer_field()
576 pb_close_string_substream(stream, &substream); in decode_pointer_field()
587 if (!allocate_field(stream, iter->pData, iter->pos->data_size, *size)) in decode_pointer_field()
592 return func(stream, iter->pos, pItem); in decode_pointer_field()
596 PB_RETURN_ERROR(stream, "invalid field type"); in decode_pointer_field()
601 static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fi… in decode_callback_field() argument
612 return pb_skip_field(stream, wire_type); in decode_callback_field()
618 if (!pb_make_string_substream(stream, &substream)) in decode_callback_field()
624 PB_RETURN_ERROR(stream, "callback failed"); in decode_callback_field()
627 pb_close_string_substream(stream, &substream); in decode_callback_field()
640 if (!read_raw_value(stream, wire_type, buffer, &size)) in decode_callback_field()
648 static bool checkreturn decode_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_itera… in decode_field() argument
653 return decode_static_field(stream, wire_type, iter); in decode_field()
656 return decode_pointer_field(stream, wire_type, iter); in decode_field()
659 return decode_callback_field(stream, wire_type, iter); in decode_field()
662 PB_RETURN_ERROR(stream, "invalid field type"); in decode_field()
668 static bool checkreturn default_extension_decoder(pb_istream_t *stream, in default_extension_decoder() argument
685 return decode_field(stream, wire_type, &iter); in default_extension_decoder()
690 static bool checkreturn decode_extension(pb_istream_t *stream, in decode_extension() argument
694 size_t pos = stream->bytes_left; in decode_extension()
696 while (extension != NULL && pos == stream->bytes_left) in decode_extension()
700 status = extension->type->decode(stream, extension, tag, wire_type); in decode_extension()
702 status = default_extension_decoder(stream, extension, tag, wire_type); in decode_extension()
797 bool checkreturn pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[], void *dest_struc… in pb_decode_noinit() argument
805 while (stream->bytes_left) in pb_decode_noinit()
811 if (!pb_decode_tag(stream, &wire_type, &tag, &eof)) in pb_decode_noinit()
831 size_t pos = stream->bytes_left; in pb_decode_noinit()
833 if (!decode_extension(stream, tag, wire_type, &iter)) in pb_decode_noinit()
836 if (pos != stream->bytes_left) in pb_decode_noinit()
845 if (!pb_skip_field(stream, wire_type)) in pb_decode_noinit()
856 if (!decode_field(stream, wire_type, &iter)) in pb_decode_noinit()
882 PB_RETURN_ERROR(stream, "missing required field"); in pb_decode_noinit()
887 PB_RETURN_ERROR(stream, "missing required field"); in pb_decode_noinit()
893 bool checkreturn pb_decode(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct) in pb_decode() argument
897 status = pb_decode_noinit(stream, fields, dest_struct); in pb_decode()
907 bool pb_decode_delimited(pb_istream_t *stream, const pb_field_t fields[], void *dest_struct) in pb_decode_delimited() argument
912 if (!pb_make_string_substream(stream, &substream)) in pb_decode_delimited()
916 pb_close_string_substream(stream, &substream); in pb_decode_delimited()
978 bool pb_decode_svarint(pb_istream_t *stream, int64_t *dest) in pb_decode_svarint() argument
981 if (!pb_decode_varint(stream, &value)) in pb_decode_svarint()
992 bool pb_decode_fixed32(pb_istream_t *stream, void *dest) in pb_decode_fixed32() argument
998 if (!pb_read(stream, lebytes, 4)) in pb_decode_fixed32()
1007 return pb_read(stream, (uint8_t*)dest, 4); in pb_decode_fixed32()
1011 bool pb_decode_fixed64(pb_istream_t *stream, void *dest) in pb_decode_fixed64() argument
1017 if (!pb_read(stream, lebytes, 8)) in pb_decode_fixed64()
1030 return pb_read(stream, (uint8_t*)dest, 8); in pb_decode_fixed64()
1034 static bool checkreturn pb_dec_varint(pb_istream_t *stream, const pb_field_t *field, void *dest) in pb_dec_varint() argument
1037 if (!pb_decode_varint(stream, &value)) in pb_dec_varint()
1046 default: PB_RETURN_ERROR(stream, "invalid data_size"); in pb_dec_varint()
1052 static bool checkreturn pb_dec_uvarint(pb_istream_t *stream, const pb_field_t *field, void *dest) in pb_dec_uvarint() argument
1055 if (!pb_decode_varint(stream, &value)) in pb_dec_uvarint()
1062 default: PB_RETURN_ERROR(stream, "invalid data_size"); in pb_dec_uvarint()
1068 static bool checkreturn pb_dec_svarint(pb_istream_t *stream, const pb_field_t *field, void *dest) in pb_dec_svarint() argument
1071 if (!pb_decode_svarint(stream, &value)) in pb_dec_svarint()
1078 default: PB_RETURN_ERROR(stream, "invalid data_size"); in pb_dec_svarint()
1084 static bool checkreturn pb_dec_fixed32(pb_istream_t *stream, const pb_field_t *field, void *dest) in pb_dec_fixed32() argument
1087 return pb_decode_fixed32(stream, dest); in pb_dec_fixed32()
1090 static bool checkreturn pb_dec_fixed64(pb_istream_t *stream, const pb_field_t *field, void *dest) in pb_dec_fixed64() argument
1093 return pb_decode_fixed64(stream, dest); in pb_dec_fixed64()
1096 static bool checkreturn pb_dec_bytes(pb_istream_t *stream, const pb_field_t *field, void *dest) in pb_dec_bytes() argument
1101 if (!pb_decode_varint32(stream, &size)) in pb_dec_bytes()
1107 PB_RETURN_ERROR(stream, "no malloc support"); in pb_dec_bytes()
1109 if (!allocate_field(stream, dest, PB_BYTES_ARRAY_T_ALLOCSIZE(size), 1)) in pb_dec_bytes()
1117 PB_RETURN_ERROR(stream, "bytes overflow"); in pb_dec_bytes()
1122 return pb_read(stream, bdest->bytes, size); in pb_dec_bytes()
1125 static bool checkreturn pb_dec_string(pb_istream_t *stream, const pb_field_t *field, void *dest) in pb_dec_string() argument
1130 if (!pb_decode_varint32(stream, &size)) in pb_dec_string()
1139 PB_RETURN_ERROR(stream, "no malloc support"); in pb_dec_string()
1141 if (!allocate_field(stream, dest, alloc_size, 1)) in pb_dec_string()
1149 PB_RETURN_ERROR(stream, "string overflow"); in pb_dec_string()
1152 status = pb_read(stream, (uint8_t*)dest, size); in pb_dec_string()
1157 static bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t *field, void *dest) in pb_dec_submessage() argument
1163 if (!pb_make_string_substream(stream, &substream)) in pb_dec_submessage()
1167 PB_RETURN_ERROR(stream, "invalid field descriptor"); in pb_dec_submessage()
1176 pb_close_string_substream(stream, &substream); in pb_dec_submessage()