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);
70 static bool checkreturn buf_read(pb_istream_t *stream, pb_byte_t *buf, size_t count) in buf_read() argument
73 const pb_byte_t *source = (const pb_byte_t*)stream->state; in buf_read()
74 stream->state = (pb_byte_t*)stream->state + count; in buf_read()
85 bool checkreturn pb_read(pb_istream_t *stream, pb_byte_t *buf, size_t count) in pb_read() argument
91 if (buf == NULL && stream->callback != buf_read) in pb_read()
97 if (!pb_read(stream, tmp, 16)) in pb_read()
103 return pb_read(stream, tmp, count); in pb_read()
107 if (stream->bytes_left < count) in pb_read()
108 PB_RETURN_ERROR(stream, "end-of-stream"); in pb_read()
111 if (!stream->callback(stream, buf, count)) in pb_read()
112 PB_RETURN_ERROR(stream, "io error"); in pb_read()
114 if (!buf_read(stream, buf, count)) in pb_read()
118 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()
226 PB_RETURN_ERROR(stream, "varint overflow"); in pb_decode_varint32_eof()
234 bool checkreturn pb_decode_varint32(pb_istream_t *stream, uint32_t *dest) in pb_decode_varint32() argument
236 return pb_decode_varint32_eof(stream, dest, NULL); in pb_decode_varint32()
240 bool checkreturn pb_decode_varint(pb_istream_t *stream, uint64_t *dest) in pb_decode_varint() argument
249 PB_RETURN_ERROR(stream, "varint overflow"); in pb_decode_varint()
251 if (!pb_readbyte(stream, &byte)) in pb_decode_varint()
263 bool checkreturn pb_skip_varint(pb_istream_t *stream) in pb_skip_varint() argument
268 if (!pb_read(stream, &byte, 1)) in pb_skip_varint()
274 bool checkreturn pb_skip_string(pb_istream_t *stream) in pb_skip_string() argument
277 if (!pb_decode_varint32(stream, &length)) in pb_skip_string()
282 PB_RETURN_ERROR(stream, "size too large"); in pb_skip_string()
285 return pb_read(stream, NULL, (size_t)length); in pb_skip_string()
288 bool checkreturn pb_decode_tag(pb_istream_t *stream, pb_wire_type_t *wire_type, uint32_t *tag, bool… in pb_decode_tag() argument
295 if (!pb_decode_varint32_eof(stream, &temp, eof)) in pb_decode_tag()
305 bool checkreturn pb_skip_field(pb_istream_t *stream, pb_wire_type_t wire_type) in pb_skip_field() argument
309 case PB_WT_VARINT: return pb_skip_varint(stream); in pb_skip_field()
310 case PB_WT_64BIT: return pb_read(stream, NULL, 8); in pb_skip_field()
311 case PB_WT_STRING: return pb_skip_string(stream); in pb_skip_field()
312 case PB_WT_32BIT: return pb_read(stream, NULL, 4); in pb_skip_field()
313 default: PB_RETURN_ERROR(stream, "invalid wire_type"); in pb_skip_field()
320 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
331 PB_RETURN_ERROR(stream, "varint overflow"); in read_raw_value()
333 if (!pb_read(stream, buf, 1)) in read_raw_value()
340 return pb_read(stream, buf, 8); in read_raw_value()
344 return pb_read(stream, buf, 4); in read_raw_value()
352 default: PB_RETURN_ERROR(stream, "invalid wire_type"); in read_raw_value()
359 bool checkreturn pb_make_string_substream(pb_istream_t *stream, pb_istream_t *substream) in pb_make_string_substream() argument
362 if (!pb_decode_varint32(stream, &size)) in pb_make_string_substream()
365 *substream = *stream; in pb_make_string_substream()
367 PB_RETURN_ERROR(stream, "parent stream too short"); in pb_make_string_substream()
370 stream->bytes_left -= (size_t)size; in pb_make_string_substream()
374 bool checkreturn pb_close_string_substream(pb_istream_t *stream, pb_istream_t *substream) in pb_close_string_substream() argument
381 stream->state = substream->state; in pb_close_string_substream()
384 stream->errmsg = substream->errmsg; in pb_close_string_substream()
393 static bool checkreturn decode_basic_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field… in decode_basic_field() argument
399 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
401 return pb_dec_bool(stream, field); in decode_basic_field()
407 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
409 return pb_dec_varint(stream, field); in decode_basic_field()
413 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
415 return pb_decode_fixed32(stream, field->pData); in decode_basic_field()
419 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
424 return pb_decode_double_as_float(stream, (float*)field->pData); in decode_basic_field()
429 PB_RETURN_ERROR(stream, "invalid data_size"); in decode_basic_field()
431 return pb_decode_fixed64(stream, field->pData); in decode_basic_field()
436 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
438 return pb_dec_bytes(stream, field); in decode_basic_field()
442 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
444 return pb_dec_string(stream, field); in decode_basic_field()
449 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
451 return pb_dec_submessage(stream, field); in decode_basic_field()
455 PB_RETURN_ERROR(stream, "wrong wire type"); in decode_basic_field()
457 return pb_dec_fixed_length_bytes(stream, field); in decode_basic_field()
460 PB_RETURN_ERROR(stream, "invalid field type"); in decode_basic_field()
464 static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fiel… in decode_static_field() argument
469 return decode_basic_field(stream, wire_type, field); in decode_static_field()
474 return decode_basic_field(stream, wire_type, field); in decode_static_field()
486 if (!pb_make_string_substream(stream, &substream)) in decode_static_field()
501 PB_RETURN_ERROR(stream, "array overflow"); in decode_static_field()
502 if (!pb_close_string_substream(stream, &substream)) in decode_static_field()
514 PB_RETURN_ERROR(stream, "array overflow"); in decode_static_field()
516 return decode_basic_field(stream, wire_type, field); in decode_static_field()
541 PB_RETURN_ERROR(stream, "failed to set defaults"); in decode_static_field()
547 return decode_basic_field(stream, wire_type, field); in decode_static_field()
550 PB_RETURN_ERROR(stream, "invalid field type"); in decode_static_field()
559 static bool checkreturn allocate_field(pb_istream_t *stream, void *pData, size_t data_size, size_t … in allocate_field() argument
564 PB_RETURN_ERROR(stream, "invalid size"); in allocate_field()
588 PB_RETURN_ERROR(stream, "size too large"); in allocate_field()
598 PB_RETURN_ERROR(stream, "realloc failed"); in allocate_field()
621 static bool checkreturn decode_pointer_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fie… in decode_pointer_field() argument
626 PB_RETURN_ERROR(stream, "no malloc support"); in decode_pointer_field()
650 return decode_basic_field(stream, wire_type, field); in decode_pointer_field()
654 if (!allocate_field(stream, field->pField, field->data_size, 1)) in decode_pointer_field()
659 return decode_basic_field(stream, wire_type, field); in decode_pointer_field()
672 if (!pb_make_string_substream(stream, &substream)) in decode_pointer_field()
680 stream->errmsg = "too many array entries"; in decode_pointer_field()
715 if (!pb_close_string_substream(stream, &substream)) in decode_pointer_field()
726 PB_RETURN_ERROR(stream, "too many array entries"); in decode_pointer_field()
728 if (!allocate_field(stream, field->pField, field->data_size, (size_t)(*size + 1))) in decode_pointer_field()
734 return decode_basic_field(stream, wire_type, field); in decode_pointer_field()
738 PB_RETURN_ERROR(stream, "invalid field type"); in decode_pointer_field()
743 static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_fi… in decode_callback_field() argument
746 return pb_skip_field(stream, wire_type); in decode_callback_field()
753 if (!pb_make_string_substream(stream, &substream)) in decode_callback_field()
760 PB_RETURN_ERROR(stream, "callback failed"); in decode_callback_field()
763 if (!pb_close_string_substream(stream, &substream)) in decode_callback_field()
778 if (!read_raw_value(stream, wire_type, buffer, &size)) in decode_callback_field()
786 static bool checkreturn decode_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iter_… in decode_field() argument
793 if (!pb_release_union_field(stream, field)) in decode_field()
801 return decode_static_field(stream, wire_type, field); in decode_field()
804 return decode_pointer_field(stream, wire_type, field); in decode_field()
807 return decode_callback_field(stream, wire_type, field); in decode_field()
810 PB_RETURN_ERROR(stream, "invalid field type"); in decode_field()
817 static bool checkreturn default_extension_decoder(pb_istream_t *stream, in default_extension_decoder() argument
823 PB_RETURN_ERROR(stream, "invalid extension"); in default_extension_decoder()
829 return decode_field(stream, wire_type, &iter); in default_extension_decoder()
834 static bool checkreturn decode_extension(pb_istream_t *stream, in decode_extension() argument
837 size_t pos = stream->bytes_left; in decode_extension()
839 while (extension != NULL && pos == stream->bytes_left) in decode_extension()
843 status = extension->type->decode(stream, extension, tag, wire_type); in decode_extension()
845 status = default_extension_decoder(stream, extension, tag, wire_type); in decode_extension()
978 static bool checkreturn pb_decode_inner(pb_istream_t *stream, const pb_msgdesc_t *fields, void *des… in pb_decode_inner() argument
1000 PB_RETURN_ERROR(stream, "failed to set defaults"); in pb_decode_inner()
1004 while (stream->bytes_left) in pb_decode_inner()
1010 if (!pb_decode_tag(stream, &wire_type, &tag, &eof)) in pb_decode_inner()
1026 PB_RETURN_ERROR(stream, "zero tag"); in pb_decode_inner()
1049 size_t pos = stream->bytes_left; in pb_decode_inner()
1051 if (!decode_extension(stream, tag, wire_type, extensions)) in pb_decode_inner()
1054 if (pos != stream->bytes_left) in pb_decode_inner()
1062 if (!pb_skip_field(stream, wire_type)) in pb_decode_inner()
1080 PB_RETURN_ERROR(stream, "wrong size for fixed count field"); in pb_decode_inner()
1098 if (!decode_field(stream, wire_type, &iter)) in pb_decode_inner()
1106 PB_RETURN_ERROR(stream, "wrong size for fixed count field"); in pb_decode_inner()
1124 PB_RETURN_ERROR(stream, "missing required field"); in pb_decode_inner()
1133 PB_RETURN_ERROR(stream, "missing required field"); in pb_decode_inner()
1142 bool checkreturn pb_decode_ex(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct, … in pb_decode_ex() argument
1148 status = pb_decode_inner(stream, fields, dest_struct, flags); in pb_decode_ex()
1153 if (!pb_make_string_substream(stream, &substream)) in pb_decode_ex()
1158 if (!pb_close_string_substream(stream, &substream)) in pb_decode_ex()
1170 bool checkreturn pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct) in pb_decode() argument
1174 status = pb_decode_inner(stream, fields, dest_struct, 0); in pb_decode()
1187 static bool pb_release_union_field(pb_istream_t *stream, pb_field_iter_t *field) in pb_release_union_field() argument
1202 PB_RETURN_ERROR(stream, "invalid union tag"); in pb_release_union_field()
1327 bool pb_decode_bool(pb_istream_t *stream, bool *dest) in pb_decode_bool() argument
1330 if (!pb_decode_varint32(stream, &value)) in pb_decode_bool()
1337 bool pb_decode_svarint(pb_istream_t *stream, pb_int64_t *dest) in pb_decode_svarint() argument
1340 if (!pb_decode_varint(stream, &value)) in pb_decode_svarint()
1351 bool pb_decode_fixed32(pb_istream_t *stream, void *dest) in pb_decode_fixed32() argument
1358 if (!pb_read(stream, u.bytes, 4)) in pb_decode_fixed32()
1374 bool pb_decode_fixed64(pb_istream_t *stream, void *dest) in pb_decode_fixed64() argument
1381 if (!pb_read(stream, u.bytes, 8)) in pb_decode_fixed64()
1401 static bool checkreturn pb_dec_bool(pb_istream_t *stream, const pb_field_iter_t *field) in pb_dec_bool() argument
1403 return pb_decode_bool(stream, (bool*)field->pData); in pb_dec_bool()
1406 static bool checkreturn pb_dec_varint(pb_istream_t *stream, const pb_field_iter_t *field) in pb_dec_varint() argument
1411 if (!pb_decode_varint(stream, &value)) in pb_dec_varint()
1424 PB_RETURN_ERROR(stream, "invalid data_size"); in pb_dec_varint()
1427 PB_RETURN_ERROR(stream, "integer too large"); in pb_dec_varint()
1439 if (!pb_decode_svarint(stream, &svalue)) in pb_dec_varint()
1444 if (!pb_decode_varint(stream, &value)) in pb_dec_varint()
1469 PB_RETURN_ERROR(stream, "invalid data_size"); in pb_dec_varint()
1472 PB_RETURN_ERROR(stream, "integer too large"); in pb_dec_varint()
1478 static bool checkreturn pb_dec_bytes(pb_istream_t *stream, const pb_field_iter_t *field) in pb_dec_bytes() argument
1484 if (!pb_decode_varint32(stream, &size)) in pb_dec_bytes()
1488 PB_RETURN_ERROR(stream, "bytes overflow"); in pb_dec_bytes()
1492 PB_RETURN_ERROR(stream, "size too large"); in pb_dec_bytes()
1497 PB_RETURN_ERROR(stream, "no malloc support"); in pb_dec_bytes()
1499 if (stream->bytes_left < size) in pb_dec_bytes()
1500 PB_RETURN_ERROR(stream, "end-of-stream"); in pb_dec_bytes()
1502 if (!allocate_field(stream, field->pData, alloc_size, 1)) in pb_dec_bytes()
1510 PB_RETURN_ERROR(stream, "bytes overflow"); in pb_dec_bytes()
1515 return pb_read(stream, dest->bytes, (size_t)size); in pb_dec_bytes()
1518 static bool checkreturn pb_dec_string(pb_istream_t *stream, const pb_field_iter_t *field) in pb_dec_string() argument
1524 if (!pb_decode_varint32(stream, &size)) in pb_dec_string()
1528 PB_RETURN_ERROR(stream, "size too large"); in pb_dec_string()
1534 PB_RETURN_ERROR(stream, "size too large"); in pb_dec_string()
1539 PB_RETURN_ERROR(stream, "no malloc support"); in pb_dec_string()
1541 if (stream->bytes_left < size) in pb_dec_string()
1542 PB_RETURN_ERROR(stream, "end-of-stream"); in pb_dec_string()
1544 if (!allocate_field(stream, field->pData, alloc_size, 1)) in pb_dec_string()
1552 PB_RETURN_ERROR(stream, "string overflow"); in pb_dec_string()
1557 if (!pb_read(stream, dest, (size_t)size)) in pb_dec_string()
1562 PB_RETURN_ERROR(stream, "invalid utf8"); in pb_dec_string()
1568 static bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_iter_t *field) in pb_dec_submessage() argument
1574 if (!pb_make_string_substream(stream, &substream)) in pb_dec_submessage()
1578 PB_RETURN_ERROR(stream, "invalid field descriptor"); in pb_dec_submessage()
1614 if (!pb_close_string_substream(stream, &substream)) in pb_dec_submessage()
1620 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
1624 if (!pb_decode_varint32(stream, &size)) in pb_dec_fixed_length_bytes()
1628 PB_RETURN_ERROR(stream, "bytes overflow"); in pb_dec_fixed_length_bytes()
1638 PB_RETURN_ERROR(stream, "incorrect fixed length bytes size"); in pb_dec_fixed_length_bytes()
1640 return pb_read(stream, (pb_byte_t*)field->pData, (size_t)field->data_size); in pb_dec_fixed_length_bytes()
1644 bool pb_decode_double_as_float(pb_istream_t *stream, float *dest) in pb_decode_double_as_float() argument
1652 if (!pb_decode_fixed64(stream, &value)) in pb_decode_double_as_float()