Lines Matching refs:stream

24 static bool checkreturn buf_read(pb_istream_t *stream, pb_byte_t *buf, size_t count);
25 static bool checkreturn pb_decode_varint32_eof(pb_istream_t *stream, uint32_t *dest, bool *eof);
26 static bool checkreturn read_raw_value(pb_istream_t *stream, pb_wire_type_t wire_type, pb_byte_t *b…
27 static bool checkreturn decode_basic_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field…
28 static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fiel…
29 static bool checkreturn decode_pointer_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fie…
30 static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fi…
31 static bool checkreturn decode_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iter_…
32 static bool checkreturn default_extension_decoder(pb_istream_t *stream, pb_extension_t *extension, …
33 static bool checkreturn decode_extension(pb_istream_t *stream, uint32_t tag, pb_wire_type_t wire_ty…
36 static bool checkreturn pb_dec_bool(pb_istream_t *stream, const pb_field_iter_t *field);
37 static bool checkreturn pb_dec_varint(pb_istream_t *stream, const pb_field_iter_t *field);
38 static bool checkreturn pb_dec_bytes(pb_istream_t *stream, const pb_field_iter_t *field);
39 static bool checkreturn pb_dec_string(pb_istream_t *stream, const pb_field_iter_t *field);
40 static bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_iter_t *field);
41 static bool checkreturn pb_dec_fixed_length_bytes(pb_istream_t *stream, const pb_field_iter_t *fiel…
42 static bool checkreturn pb_skip_varint(pb_istream_t *stream);
43 static bool checkreturn pb_skip_string(pb_istream_t *stream);
46 static bool checkreturn allocate_field(pb_istream_t *stream, void *pData, size_t data_size, size_t …
48 static bool checkreturn pb_release_union_field(pb_istream_t *stream, pb_field_iter_t *field);
68 static bool checkreturn buf_read(pb_istream_t *stream, pb_byte_t *buf, size_t count) in buf_read() argument
70 const pb_byte_t *source = (const pb_byte_t*)stream->state; in buf_read()
71 stream->state = (pb_byte_t*)stream->state + count; in buf_read()
81 bool checkreturn pb_read(pb_istream_t *stream, pb_byte_t *buf, size_t count) in pb_read() argument
87 if (buf == NULL && stream->callback != buf_read) in pb_read()
93 if (!pb_read(stream, tmp, 16)) in pb_read()
99 return pb_read(stream, tmp, count); in pb_read()
103 if (stream->bytes_left < count) in pb_read()
104 PB_RETURN_ERROR(stream, "end-of-stream"); in pb_read()
107 if (!stream->callback(stream, buf, count)) in pb_read()
108 PB_RETURN_ERROR(stream, "io error"); in pb_read()
110 if (!buf_read(stream, buf, count)) in pb_read()
114 if (stream->bytes_left < count) in pb_read()
115 stream->bytes_left = 0; in pb_read()
117 stream->bytes_left -= count; in pb_read()
124 static bool checkreturn pb_readbyte(pb_istream_t *stream, pb_byte_t *buf) in pb_readbyte() argument
126 if (stream->bytes_left == 0) in pb_readbyte()
127 PB_RETURN_ERROR(stream, "end-of-stream"); in pb_readbyte()
130 if (!stream->callback(stream, buf, 1)) in pb_readbyte()
131 PB_RETURN_ERROR(stream, "io error"); in pb_readbyte()
133 *buf = *(const pb_byte_t*)stream->state; in pb_readbyte()
134 stream->state = (pb_byte_t*)stream->state + 1; in pb_readbyte()
137 stream->bytes_left--; in pb_readbyte()
144 pb_istream_t stream; in pb_istream_from_buffer() local
153 stream.callback = NULL; in pb_istream_from_buffer()
155 stream.callback = &buf_read; in pb_istream_from_buffer()
158 stream.state = state.state; in pb_istream_from_buffer()
159 stream.bytes_left = msglen; in pb_istream_from_buffer()
161 stream.errmsg = NULL; in pb_istream_from_buffer()
163 return stream; in pb_istream_from_buffer()
170 static bool checkreturn pb_decode_varint32_eof(pb_istream_t *stream, uint32_t *dest, bool *eof) in pb_decode_varint32_eof() argument
175 if (!pb_readbyte(stream, &byte)) in pb_decode_varint32_eof()
177 if (stream->bytes_left == 0) in pb_decode_varint32_eof()
201 if (!pb_readbyte(stream, &byte)) in pb_decode_varint32_eof()
213 PB_RETURN_ERROR(stream, "varint overflow"); in pb_decode_varint32_eof()
220 PB_RETURN_ERROR(stream, "varint overflow"); in pb_decode_varint32_eof()
236 bool checkreturn pb_decode_varint32(pb_istream_t *stream, uint32_t *dest) in pb_decode_varint32() argument
238 return pb_decode_varint32_eof(stream, dest, NULL); in pb_decode_varint32()
242 bool checkreturn pb_decode_varint(pb_istream_t *stream, uint64_t *dest) in pb_decode_varint() argument
250 if (!pb_readbyte(stream, &byte)) in pb_decode_varint()
254 PB_RETURN_ERROR(stream, "varint overflow"); in pb_decode_varint()
265 bool checkreturn pb_skip_varint(pb_istream_t *stream) in pb_skip_varint() argument
270 if (!pb_read(stream, &byte, 1)) in pb_skip_varint()
276 bool checkreturn pb_skip_string(pb_istream_t *stream) in pb_skip_string() argument
279 if (!pb_decode_varint32(stream, &length)) in pb_skip_string()
284 PB_RETURN_ERROR(stream, "size too large"); in pb_skip_string()
287 return pb_read(stream, NULL, (size_t)length); in pb_skip_string()
290 bool checkreturn pb_decode_tag(pb_istream_t *stream, pb_wire_type_t *wire_type, uint32_t *tag, bool… in pb_decode_tag() argument
297 if (!pb_decode_varint32_eof(stream, &temp, eof)) in pb_decode_tag()
307 bool checkreturn pb_skip_field(pb_istream_t *stream, pb_wire_type_t wire_type) in pb_skip_field() argument
311 case PB_WT_VARINT: return pb_skip_varint(stream); in pb_skip_field()
312 case PB_WT_64BIT: return pb_read(stream, NULL, 8); in pb_skip_field()
313 case PB_WT_STRING: return pb_skip_string(stream); in pb_skip_field()
314 case PB_WT_32BIT: return pb_read(stream, NULL, 4); in pb_skip_field()
315 default: PB_RETURN_ERROR(stream, "invalid wire_type"); in pb_skip_field()
322 static bool checkreturn read_raw_value(pb_istream_t *stream, pb_wire_type_t wire_type, pb_byte_t *b… in read_raw_value() argument
333 PB_RETURN_ERROR(stream, "varint overflow"); in read_raw_value()
335 if (!pb_read(stream, buf, 1)) in read_raw_value()
342 return pb_read(stream, buf, 8); in read_raw_value()
346 return pb_read(stream, buf, 4); in read_raw_value()
354 default: PB_RETURN_ERROR(stream, "invalid wire_type"); in read_raw_value()
361 bool checkreturn pb_make_string_substream(pb_istream_t *stream, pb_istream_t *substream) in pb_make_string_substream() argument
364 if (!pb_decode_varint32(stream, &size)) in pb_make_string_substream()
367 *substream = *stream; in pb_make_string_substream()
369 PB_RETURN_ERROR(stream, "parent stream too short"); in pb_make_string_substream()
372 stream->bytes_left -= (size_t)size; in pb_make_string_substream()
376 bool checkreturn pb_close_string_substream(pb_istream_t *stream, pb_istream_t *substream) in pb_close_string_substream() argument
383 stream->state = substream->state; in pb_close_string_substream()
386 stream->errmsg = substream->errmsg; in pb_close_string_substream()
395 static bool checkreturn decode_basic_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field… in decode_basic_field() argument
401 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
403 return pb_dec_bool(stream, field); in decode_basic_field()
409 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
411 return pb_dec_varint(stream, field); in decode_basic_field()
415 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
417 return pb_decode_fixed32(stream, field->pData); in decode_basic_field()
421 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
426 return pb_decode_double_as_float(stream, (float*)field->pData); in decode_basic_field()
431 PB_RETURN_ERROR(stream, "invalid data_size"); in decode_basic_field()
433 return pb_decode_fixed64(stream, field->pData); in decode_basic_field()
438 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
440 return pb_dec_bytes(stream, field); in decode_basic_field()
444 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
446 return pb_dec_string(stream, field); in decode_basic_field()
451 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
453 return pb_dec_submessage(stream, field); in decode_basic_field()
457 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
459 return pb_dec_fixed_length_bytes(stream, field); in decode_basic_field()
462 PB_RETURN_ERROR(stream, "invalid field type"); in decode_basic_field()
466 static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fiel… in decode_static_field() argument
471 return decode_basic_field(stream, wire_type, field); in decode_static_field()
476 return decode_basic_field(stream, wire_type, field); in decode_static_field()
488 if (!pb_make_string_substream(stream, &substream)) in decode_static_field()
503 PB_RETURN_ERROR(stream, "array overflow"); in decode_static_field()
504 if (!pb_close_string_substream(stream, &substream)) in decode_static_field()
516 PB_RETURN_ERROR(stream, "array overflow"); in decode_static_field()
518 return decode_basic_field(stream, wire_type, field); in decode_static_field()
543 PB_RETURN_ERROR(stream, "failed to set defaults"); in decode_static_field()
549 return decode_basic_field(stream, wire_type, field); in decode_static_field()
552 PB_RETURN_ERROR(stream, "invalid field type"); in decode_static_field()
561 static bool checkreturn allocate_field(pb_istream_t *stream, void *pData, size_t data_size, size_t … in allocate_field() argument
566 PB_RETURN_ERROR(stream, "invalid size"); in allocate_field()
590 PB_RETURN_ERROR(stream, "size too large"); in allocate_field()
600 PB_RETURN_ERROR(stream, "realloc failed"); in allocate_field()
623 static bool checkreturn decode_pointer_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fie… in decode_pointer_field() argument
628 PB_RETURN_ERROR(stream, "no malloc support"); in decode_pointer_field()
652 return decode_basic_field(stream, wire_type, field); in decode_pointer_field()
656 if (!allocate_field(stream, field->pField, field->data_size, 1)) in decode_pointer_field()
661 return decode_basic_field(stream, wire_type, field); in decode_pointer_field()
674 if (!pb_make_string_substream(stream, &substream)) in decode_pointer_field()
682 stream->errmsg = "too many array entries"; in decode_pointer_field()
723 if (!pb_close_string_substream(stream, &substream)) in decode_pointer_field()
734 PB_RETURN_ERROR(stream, "too many array entries"); in decode_pointer_field()
736 if (!allocate_field(stream, field->pField, field->data_size, (size_t)(*size + 1))) in decode_pointer_field()
742 return decode_basic_field(stream, wire_type, field); in decode_pointer_field()
746 PB_RETURN_ERROR(stream, "invalid field type"); in decode_pointer_field()
751 static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fi… in decode_callback_field() argument
754 return pb_skip_field(stream, wire_type); in decode_callback_field()
761 if (!pb_make_string_substream(stream, &substream)) in decode_callback_field()
769 PB_SET_ERROR(stream, substream.errmsg ? substream.errmsg : "callback failed"); in decode_callback_field()
774 if (!pb_close_string_substream(stream, &substream)) in decode_callback_field()
789 if (!read_raw_value(stream, wire_type, buffer, &size)) in decode_callback_field()
797 static bool checkreturn decode_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iter_… in decode_field() argument
804 if (!pb_release_union_field(stream, field)) in decode_field()
812 return decode_static_field(stream, wire_type, field); in decode_field()
815 return decode_pointer_field(stream, wire_type, field); in decode_field()
818 return decode_callback_field(stream, wire_type, field); in decode_field()
821 PB_RETURN_ERROR(stream, "invalid field type"); in decode_field()
828 static bool checkreturn default_extension_decoder(pb_istream_t *stream, in default_extension_decoder() argument
834 PB_RETURN_ERROR(stream, "invalid extension"); in default_extension_decoder()
840 return decode_field(stream, wire_type, &iter); in default_extension_decoder()
845 static bool checkreturn decode_extension(pb_istream_t *stream, in decode_extension() argument
848 size_t pos = stream->bytes_left; in decode_extension()
850 while (extension != NULL && pos == stream->bytes_left) in decode_extension()
854 status = extension->type->decode(stream, extension, tag, wire_type); in decode_extension()
856 status = default_extension_decoder(stream, extension, tag, wire_type); in decode_extension()
989 static bool checkreturn pb_decode_inner(pb_istream_t *stream, const pb_msgdesc_t *fields, void *des… in pb_decode_inner() argument
1011 PB_RETURN_ERROR(stream, "failed to set defaults"); in pb_decode_inner()
1015 while (stream->bytes_left) in pb_decode_inner()
1021 if (!pb_decode_tag(stream, &wire_type, &tag, &eof)) in pb_decode_inner()
1037 PB_RETURN_ERROR(stream, "zero tag"); in pb_decode_inner()
1060 size_t pos = stream->bytes_left; in pb_decode_inner()
1062 if (!decode_extension(stream, tag, wire_type, extensions)) in pb_decode_inner()
1065 if (pos != stream->bytes_left) in pb_decode_inner()
1073 if (!pb_skip_field(stream, wire_type)) in pb_decode_inner()
1091 PB_RETURN_ERROR(stream, "wrong size for fixed count field"); in pb_decode_inner()
1109 if (!decode_field(stream, wire_type, &iter)) in pb_decode_inner()
1117 PB_RETURN_ERROR(stream, "wrong size for fixed count field"); in pb_decode_inner()
1135 PB_RETURN_ERROR(stream, "missing required field"); in pb_decode_inner()
1144 PB_RETURN_ERROR(stream, "missing required field"); in pb_decode_inner()
1153 bool checkreturn pb_decode_ex(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct, … in pb_decode_ex() argument
1159 status = pb_decode_inner(stream, fields, dest_struct, flags); in pb_decode_ex()
1164 if (!pb_make_string_substream(stream, &substream)) in pb_decode_ex()
1169 if (!pb_close_string_substream(stream, &substream)) in pb_decode_ex()
1181 bool checkreturn pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct) in pb_decode() argument
1185 status = pb_decode_inner(stream, fields, dest_struct, 0); in pb_decode()
1198 static bool pb_release_union_field(pb_istream_t *stream, pb_field_iter_t *field) in pb_release_union_field() argument
1213 PB_RETURN_ERROR(stream, "invalid union tag"); in pb_release_union_field()
1345 bool pb_decode_bool(pb_istream_t *stream, bool *dest) in pb_decode_bool() argument
1348 if (!pb_decode_varint32(stream, &value)) in pb_decode_bool()
1355 bool pb_decode_svarint(pb_istream_t *stream, pb_int64_t *dest) in pb_decode_svarint() argument
1358 if (!pb_decode_varint(stream, &value)) in pb_decode_svarint()
1369 bool pb_decode_fixed32(pb_istream_t *stream, void *dest) in pb_decode_fixed32() argument
1376 if (!pb_read(stream, u.bytes, 4)) in pb_decode_fixed32()
1392 bool pb_decode_fixed64(pb_istream_t *stream, void *dest) in pb_decode_fixed64() argument
1399 if (!pb_read(stream, u.bytes, 8)) in pb_decode_fixed64()
1419 static bool checkreturn pb_dec_bool(pb_istream_t *stream, const pb_field_iter_t *field) in pb_dec_bool() argument
1421 return pb_decode_bool(stream, (bool*)field->pData); in pb_dec_bool()
1424 static bool checkreturn pb_dec_varint(pb_istream_t *stream, const pb_field_iter_t *field) in pb_dec_varint() argument
1429 if (!pb_decode_varint(stream, &value)) in pb_dec_varint()
1442 PB_RETURN_ERROR(stream, "invalid data_size"); in pb_dec_varint()
1445 PB_RETURN_ERROR(stream, "integer too large"); in pb_dec_varint()
1457 if (!pb_decode_svarint(stream, &svalue)) in pb_dec_varint()
1462 if (!pb_decode_varint(stream, &value)) in pb_dec_varint()
1487 PB_RETURN_ERROR(stream, "invalid data_size"); in pb_dec_varint()
1490 PB_RETURN_ERROR(stream, "integer too large"); in pb_dec_varint()
1496 static bool checkreturn pb_dec_bytes(pb_istream_t *stream, const pb_field_iter_t *field) in pb_dec_bytes() argument
1502 if (!pb_decode_varint32(stream, &size)) in pb_dec_bytes()
1506 PB_RETURN_ERROR(stream, "bytes overflow"); in pb_dec_bytes()
1510 PB_RETURN_ERROR(stream, "size too large"); in pb_dec_bytes()
1515 PB_RETURN_ERROR(stream, "no malloc support"); in pb_dec_bytes()
1517 if (stream->bytes_left < size) in pb_dec_bytes()
1518 PB_RETURN_ERROR(stream, "end-of-stream"); in pb_dec_bytes()
1520 if (!allocate_field(stream, field->pData, alloc_size, 1)) in pb_dec_bytes()
1528 PB_RETURN_ERROR(stream, "bytes overflow"); in pb_dec_bytes()
1533 return pb_read(stream, dest->bytes, (size_t)size); in pb_dec_bytes()
1536 static bool checkreturn pb_dec_string(pb_istream_t *stream, const pb_field_iter_t *field) in pb_dec_string() argument
1542 if (!pb_decode_varint32(stream, &size)) in pb_dec_string()
1546 PB_RETURN_ERROR(stream, "size too large"); in pb_dec_string()
1552 PB_RETURN_ERROR(stream, "size too large"); in pb_dec_string()
1557 PB_RETURN_ERROR(stream, "no malloc support"); in pb_dec_string()
1559 if (stream->bytes_left < size) in pb_dec_string()
1560 PB_RETURN_ERROR(stream, "end-of-stream"); in pb_dec_string()
1562 if (!allocate_field(stream, field->pData, alloc_size, 1)) in pb_dec_string()
1570 PB_RETURN_ERROR(stream, "string overflow"); in pb_dec_string()
1575 if (!pb_read(stream, dest, (size_t)size)) in pb_dec_string()
1580 PB_RETURN_ERROR(stream, "invalid utf8"); in pb_dec_string()
1586 static bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_iter_t *field) in pb_dec_submessage() argument
1592 if (!pb_make_string_substream(stream, &substream)) in pb_dec_submessage()
1596 PB_RETURN_ERROR(stream, "invalid field descriptor"); in pb_dec_submessage()
1632 if (!pb_close_string_substream(stream, &substream)) in pb_dec_submessage()
1638 static bool checkreturn pb_dec_fixed_length_bytes(pb_istream_t *stream, const pb_field_iter_t *fiel… in pb_dec_fixed_length_bytes() argument
1642 if (!pb_decode_varint32(stream, &size)) in pb_dec_fixed_length_bytes()
1646 PB_RETURN_ERROR(stream, "bytes overflow"); in pb_dec_fixed_length_bytes()
1656 PB_RETURN_ERROR(stream, "incorrect fixed length bytes size"); in pb_dec_fixed_length_bytes()
1658 return pb_read(stream, (pb_byte_t*)field->pData, (size_t)field->data_size); in pb_dec_fixed_length_bytes()
1662 bool pb_decode_double_as_float(pb_istream_t *stream, float *dest) in pb_decode_double_as_float() argument
1670 if (!pb_decode_fixed64(stream, &value)) in pb_decode_double_as_float()