Lines Matching refs:stream

23 static bool checkreturn buf_write(pb_ostream_t *stream, const pb_byte_t *buf, size_t count);
24 static bool checkreturn encode_array(pb_ostream_t *stream, pb_field_iter_t *field);
26 static bool checkreturn encode_basic_field(pb_ostream_t *stream, const pb_field_iter_t *field);
27 static bool checkreturn encode_callback_field(pb_ostream_t *stream, const pb_field_iter_t *field);
28 static bool checkreturn encode_field(pb_ostream_t *stream, pb_field_iter_t *field);
29 static bool checkreturn encode_extension_field(pb_ostream_t *stream, const pb_field_iter_t *field);
30 static bool checkreturn default_extension_encoder(pb_ostream_t *stream, const pb_extension_t *exten…
31 static bool checkreturn pb_encode_varint_32(pb_ostream_t *stream, uint32_t low, uint32_t high);
32 static bool checkreturn pb_enc_bool(pb_ostream_t *stream, const pb_field_iter_t *field);
33 static bool checkreturn pb_enc_varint(pb_ostream_t *stream, const pb_field_iter_t *field);
34 static bool checkreturn pb_enc_fixed(pb_ostream_t *stream, const pb_field_iter_t *field);
35 static bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_iter_t *field);
36 static bool checkreturn pb_enc_string(pb_ostream_t *stream, const pb_field_iter_t *field);
37 static bool checkreturn pb_enc_submessage(pb_ostream_t *stream, const pb_field_iter_t *field);
38 static bool checkreturn pb_enc_fixed_length_bytes(pb_ostream_t *stream, const pb_field_iter_t *fiel…
52 static bool checkreturn buf_write(pb_ostream_t *stream, const pb_byte_t *buf, size_t count) in buf_write() argument
54 pb_byte_t *dest = (pb_byte_t*)stream->state; in buf_write()
55 stream->state = dest + count; in buf_write()
64 pb_ostream_t stream; in pb_ostream_from_buffer() local
70 stream.callback = ▮ in pb_ostream_from_buffer()
72 stream.callback = &buf_write; in pb_ostream_from_buffer()
74 stream.state = buf; in pb_ostream_from_buffer()
75 stream.max_size = bufsize; in pb_ostream_from_buffer()
76 stream.bytes_written = 0; in pb_ostream_from_buffer()
78 stream.errmsg = NULL; in pb_ostream_from_buffer()
80 return stream; in pb_ostream_from_buffer()
83 bool checkreturn pb_write(pb_ostream_t *stream, const pb_byte_t *buf, size_t count) in pb_write() argument
85 if (count > 0 && stream->callback != NULL) in pb_write()
87 if (stream->bytes_written + count < stream->bytes_written || in pb_write()
88 stream->bytes_written + count > stream->max_size) in pb_write()
90 PB_RETURN_ERROR(stream, "stream full"); in pb_write()
94 if (!buf_write(stream, buf, count)) in pb_write()
95 PB_RETURN_ERROR(stream, "io error"); in pb_write()
97 if (!stream->callback(stream, buf, count)) in pb_write()
98 PB_RETURN_ERROR(stream, "io error"); in pb_write()
102 stream->bytes_written += count; in pb_write()
127 static bool checkreturn encode_array(pb_ostream_t *stream, pb_field_iter_t *field) in encode_array() argument
141 PB_RETURN_ERROR(stream, "array max size exceeded"); in encode_array()
147 if (!pb_encode_tag(stream, PB_WT_STRING, field->tag)) in encode_array()
166 PB_RETURN_ERROR(stream, PB_GET_ERROR(&sizestream)); in encode_array()
173 if (!pb_encode_varint(stream, (pb_uint64_t)size)) in encode_array()
176 if (stream->callback == NULL) in encode_array()
177 return pb_write(stream, NULL, size); /* Just sizing.. */ in encode_array()
184 if (!pb_enc_fixed(stream, field)) in encode_array()
189 if (!pb_enc_varint(stream, field)) in encode_array()
216 status = pb_encode_tag_for_field(stream, field) && in encode_array()
217 pb_encode_varint(stream, 0); in encode_array()
221 status = encode_basic_field(stream, field); in encode_array()
231 if (!encode_basic_field(stream, field)) in encode_array()
361 static bool checkreturn encode_basic_field(pb_ostream_t *stream, const pb_field_iter_t *field) in encode_basic_field() argument
369 if (!pb_encode_tag_for_field(stream, field)) in encode_basic_field()
375 return pb_enc_bool(stream, field); in encode_basic_field()
380 return pb_enc_varint(stream, field); in encode_basic_field()
384 return pb_enc_fixed(stream, field); in encode_basic_field()
387 return pb_enc_bytes(stream, field); in encode_basic_field()
390 return pb_enc_string(stream, field); in encode_basic_field()
394 return pb_enc_submessage(stream, field); in encode_basic_field()
397 return pb_enc_fixed_length_bytes(stream, field); in encode_basic_field()
400 PB_RETURN_ERROR(stream, "invalid field type"); in encode_basic_field()
406 static bool checkreturn encode_callback_field(pb_ostream_t *stream, const pb_field_iter_t *field) in encode_callback_field() argument
410 if (!field->descriptor->field_callback(NULL, stream, field)) in encode_callback_field()
411 PB_RETURN_ERROR(stream, "callback error"); in encode_callback_field()
417 static bool checkreturn encode_field(pb_ostream_t *stream, pb_field_iter_t *field) in encode_field() argument
449 PB_RETURN_ERROR(stream, "missing required field"); in encode_field()
458 return encode_callback_field(stream, field); in encode_field()
462 return encode_array(stream, field); in encode_field()
466 return encode_basic_field(stream, field); in encode_field()
473 static bool checkreturn default_extension_encoder(pb_ostream_t *stream, const pb_extension_t *exten… in default_extension_encoder() argument
478 PB_RETURN_ERROR(stream, "invalid extension"); in default_extension_encoder()
480 return encode_field(stream, &iter); in default_extension_encoder()
486 static bool checkreturn encode_extension_field(pb_ostream_t *stream, const pb_field_iter_t *field) in encode_extension_field() argument
494 status = extension->type->encode(stream, extension); in encode_extension_field()
496 status = default_extension_encoder(stream, extension); in encode_extension_field()
511 bool checkreturn pb_encode(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_struct) in pb_encode() argument
521 if (!encode_extension_field(stream, &iter)) in pb_encode()
527 if (!encode_field(stream, &iter)) in pb_encode()
535 bool checkreturn pb_encode_ex(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void *src_str… in pb_encode_ex() argument
539 return pb_encode_submessage(stream, fields, src_struct); in pb_encode_ex()
545 if (!pb_encode(stream, fields, src_struct)) in pb_encode_ex()
548 return pb_write(stream, &zero, 1); in pb_encode_ex()
552 return pb_encode(stream, fields, src_struct); in pb_encode_ex()
558 pb_ostream_t stream = PB_OSTREAM_SIZING; in pb_get_encoded_size() local
560 if (!pb_encode(&stream, fields, src_struct)) in pb_get_encoded_size()
563 *size = stream.bytes_written; in pb_get_encoded_size()
572 static bool checkreturn pb_encode_varint_32(pb_ostream_t *stream, uint32_t low, uint32_t high) in pb_encode_varint_32() argument
603 return pb_write(stream, buffer, i); in pb_encode_varint_32()
606 bool checkreturn pb_encode_varint(pb_ostream_t *stream, pb_uint64_t value) in pb_encode_varint() argument
612 return pb_write(stream, &byte, 1); in pb_encode_varint()
617 return pb_encode_varint_32(stream, value, 0); in pb_encode_varint()
619 return pb_encode_varint_32(stream, (uint32_t)value, (uint32_t)(value >> 32)); in pb_encode_varint()
624 bool checkreturn pb_encode_svarint(pb_ostream_t *stream, pb_int64_t value) in pb_encode_svarint() argument
633 return pb_encode_varint(stream, zigzagged); in pb_encode_svarint()
636 bool checkreturn pb_encode_fixed32(pb_ostream_t *stream, const void *value) in pb_encode_fixed32() argument
640 return pb_write(stream, (const pb_byte_t*)value, 4); in pb_encode_fixed32()
648 return pb_write(stream, bytes, 4); in pb_encode_fixed32()
653 bool checkreturn pb_encode_fixed64(pb_ostream_t *stream, const void *value) in pb_encode_fixed64() argument
657 return pb_write(stream, (const pb_byte_t*)value, 8); in pb_encode_fixed64()
669 return pb_write(stream, bytes, 8); in pb_encode_fixed64()
674 bool checkreturn pb_encode_tag(pb_ostream_t *stream, pb_wire_type_t wiretype, uint32_t field_number) in pb_encode_tag() argument
677 return pb_encode_varint(stream, tag); in pb_encode_tag()
680 bool pb_encode_tag_for_field ( pb_ostream_t* stream, const pb_field_iter_t* field ) in pb_encode_tag_for_field() argument
709 PB_RETURN_ERROR(stream, "invalid field type"); in pb_encode_tag_for_field()
712 return pb_encode_tag(stream, wiretype, field->tag); in pb_encode_tag_for_field()
715 bool checkreturn pb_encode_string(pb_ostream_t *stream, const pb_byte_t *buffer, size_t size) in pb_encode_string() argument
717 if (!pb_encode_varint(stream, (pb_uint64_t)size)) in pb_encode_string()
720 return pb_write(stream, buffer, size); in pb_encode_string()
723 bool checkreturn pb_encode_submessage(pb_ostream_t *stream, const pb_msgdesc_t *fields, const void … in pb_encode_submessage() argument
733 stream->errmsg = substream.errmsg; in pb_encode_submessage()
740 if (!pb_encode_varint(stream, (pb_uint64_t)size)) in pb_encode_submessage()
743 if (stream->callback == NULL) in pb_encode_submessage()
744 return pb_write(stream, NULL, size); /* Just sizing */ in pb_encode_submessage()
746 if (stream->bytes_written + size > stream->max_size) in pb_encode_submessage()
747 PB_RETURN_ERROR(stream, "stream full"); in pb_encode_submessage()
751 substream.callback = stream->callback; in pb_encode_submessage()
752 substream.state = stream->state; in pb_encode_submessage()
761 stream->bytes_written += substream.bytes_written; in pb_encode_submessage()
762 stream->state = substream.state; in pb_encode_submessage()
764 stream->errmsg = substream.errmsg; in pb_encode_submessage()
768 PB_RETURN_ERROR(stream, "submsg size changed"); in pb_encode_submessage()
775 static bool checkreturn pb_enc_bool(pb_ostream_t *stream, const pb_field_iter_t *field) in pb_enc_bool() argument
779 return pb_encode_varint(stream, value); in pb_enc_bool()
782 static bool checkreturn pb_enc_varint(pb_ostream_t *stream, const pb_field_iter_t *field) in pb_enc_varint() argument
798 PB_RETURN_ERROR(stream, "invalid data_size"); in pb_enc_varint()
800 return pb_encode_varint(stream, value); in pb_enc_varint()
816 PB_RETURN_ERROR(stream, "invalid data_size"); in pb_enc_varint()
819 return pb_encode_svarint(stream, value); in pb_enc_varint()
822 return pb_encode_varint_32(stream, (uint32_t)value, (uint32_t)-1); in pb_enc_varint()
825 return pb_encode_varint(stream, (pb_uint64_t)value); in pb_enc_varint()
830 static bool checkreturn pb_enc_fixed(pb_ostream_t *stream, const pb_field_iter_t *field) in pb_enc_fixed() argument
835 return pb_encode_float_as_double(stream, *(float*)field->pData); in pb_enc_fixed()
841 return pb_encode_fixed32(stream, field->pData); in pb_enc_fixed()
846 return pb_encode_fixed64(stream, field->pData); in pb_enc_fixed()
851 PB_RETURN_ERROR(stream, "invalid data_size"); in pb_enc_fixed()
855 static bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_iter_t *field) in pb_enc_bytes() argument
864 return pb_encode_string(stream, NULL, 0); in pb_enc_bytes()
870 PB_RETURN_ERROR(stream, "bytes size exceeded"); in pb_enc_bytes()
873 return pb_encode_string(stream, bytes->bytes, (size_t)bytes->size); in pb_enc_bytes()
876 static bool checkreturn pb_enc_string(pb_ostream_t *stream, const pb_field_iter_t *field) in pb_enc_string() argument
894 PB_RETURN_ERROR(stream, "zero-length string"); in pb_enc_string()
917 PB_RETURN_ERROR(stream, "unterminated string"); in pb_enc_string()
923 PB_RETURN_ERROR(stream, "invalid utf8"); in pb_enc_string()
926 return pb_encode_string(stream, (const pb_byte_t*)str, size); in pb_enc_string()
929 static bool checkreturn pb_enc_submessage(pb_ostream_t *stream, const pb_field_iter_t *field) in pb_enc_submessage() argument
932 PB_RETURN_ERROR(stream, "invalid field descriptor"); in pb_enc_submessage()
940 if (!callback->funcs.encode(stream, field, &callback->arg)) in pb_enc_submessage()
945 return pb_encode_submessage(stream, field->submsg_desc, field->pData); in pb_enc_submessage()
948 static bool checkreturn pb_enc_fixed_length_bytes(pb_ostream_t *stream, const pb_field_iter_t *fiel… in pb_enc_fixed_length_bytes() argument
950 return pb_encode_string(stream, (const pb_byte_t*)field->pData, (size_t)field->data_size); in pb_enc_fixed_length_bytes()
954 bool pb_encode_float_as_double(pb_ostream_t *stream, float value) in pb_encode_float_as_double() argument
998 return pb_encode_fixed64(stream, &mantissa); in pb_encode_float_as_double()