pub struct CodedOutputStream<'a> { /* private fields */ }
Expand description
Buffered write with handy utilities
Implementations§
Source§impl<'a> CodedOutputStream<'a>
impl<'a> CodedOutputStream<'a>
Sourcepub fn new(writer: &'a mut dyn Write) -> CodedOutputStream<'a> ⓘ
pub fn new(writer: &'a mut dyn Write) -> CodedOutputStream<'a> ⓘ
Construct from given Write
.
CodedOutputStream
is buffered even if Write
is not
Sourcepub fn bytes(bytes: &'a mut [u8]) -> CodedOutputStream<'a> ⓘ
pub fn bytes(bytes: &'a mut [u8]) -> CodedOutputStream<'a> ⓘ
CodedOutputStream
which writes directly to bytes.
Attempt to write more than bytes capacity results in error.
Sourcepub fn vec(vec: &'a mut Vec<u8>) -> CodedOutputStream<'a> ⓘ
pub fn vec(vec: &'a mut Vec<u8>) -> CodedOutputStream<'a> ⓘ
CodedOutputStream
which writes directly to Vec<u8>
.
Sourcepub fn total_bytes_written(&self) -> u64
pub fn total_bytes_written(&self) -> u64
Total number of bytes written to this stream.
This number may be larger than the actual number of bytes written to the underlying stream, if the buffer was not flushed.
The number may be inaccurate if there was an error during the write.
Sourcepub fn flush(&mut self) -> Result<()>
pub fn flush(&mut self) -> Result<()>
Flush to buffer to the underlying buffer.
Note that CodedOutputStream
does flush
in the destructor,
however, if flush
in destructor fails, then destructor panics
and program terminates. So it’s advisable to explicitly call flush
before destructor.
Sourcepub fn write_raw_byte(&mut self, byte: u8) -> Result<()>
pub fn write_raw_byte(&mut self, byte: u8) -> Result<()>
Write a byte
Sourcepub fn write_raw_bytes(&mut self, bytes: &[u8]) -> Result<()>
pub fn write_raw_bytes(&mut self, bytes: &[u8]) -> Result<()>
Write bytes
Sourcepub fn write_tag(
&mut self,
field_number: u32,
wire_type: WireType,
) -> Result<()>
pub fn write_tag( &mut self, field_number: u32, wire_type: WireType, ) -> Result<()>
Write a tag
Sourcepub fn write_raw_varint32(&mut self, value: u32) -> Result<()>
pub fn write_raw_varint32(&mut self, value: u32) -> Result<()>
Write varint
Sourcepub fn write_raw_varint64(&mut self, value: u64) -> Result<()>
pub fn write_raw_varint64(&mut self, value: u64) -> Result<()>
Write varint
Sourcepub fn write_raw_little_endian32(&mut self, value: u32) -> Result<()>
pub fn write_raw_little_endian32(&mut self, value: u32) -> Result<()>
Write 32-bit integer little endian
Sourcepub fn write_raw_little_endian64(&mut self, value: u64) -> Result<()>
pub fn write_raw_little_endian64(&mut self, value: u64) -> Result<()>
Write 64-bit integer little endian
Sourcepub fn write_float_no_tag(&mut self, value: f32) -> Result<()>
pub fn write_float_no_tag(&mut self, value: f32) -> Result<()>
Write float
Sourcepub fn write_double_no_tag(&mut self, value: f64) -> Result<()>
pub fn write_double_no_tag(&mut self, value: f64) -> Result<()>
Write double
Sourcepub fn write_uint64_no_tag(&mut self, value: u64) -> Result<()>
pub fn write_uint64_no_tag(&mut self, value: u64) -> Result<()>
Write varint
Sourcepub fn write_uint32_no_tag(&mut self, value: u32) -> Result<()>
pub fn write_uint32_no_tag(&mut self, value: u32) -> Result<()>
Write varint
Sourcepub fn write_int64_no_tag(&mut self, value: i64) -> Result<()>
pub fn write_int64_no_tag(&mut self, value: i64) -> Result<()>
Write varint
Sourcepub fn write_int32_no_tag(&mut self, value: i32) -> Result<()>
pub fn write_int32_no_tag(&mut self, value: i32) -> Result<()>
Write varint
Sourcepub fn write_sint64_no_tag(&mut self, value: i64) -> Result<()>
pub fn write_sint64_no_tag(&mut self, value: i64) -> Result<()>
Write zigzag varint
Sourcepub fn write_sint32_no_tag(&mut self, value: i32) -> Result<()>
pub fn write_sint32_no_tag(&mut self, value: i32) -> Result<()>
Write zigzag varint
Sourcepub fn write_fixed64_no_tag(&mut self, value: u64) -> Result<()>
pub fn write_fixed64_no_tag(&mut self, value: u64) -> Result<()>
Write fixed64
Sourcepub fn write_fixed32_no_tag(&mut self, value: u32) -> Result<()>
pub fn write_fixed32_no_tag(&mut self, value: u32) -> Result<()>
Write fixed32
Sourcepub fn write_sfixed64_no_tag(&mut self, value: i64) -> Result<()>
pub fn write_sfixed64_no_tag(&mut self, value: i64) -> Result<()>
Write sfixed64
Sourcepub fn write_sfixed32_no_tag(&mut self, value: i32) -> Result<()>
pub fn write_sfixed32_no_tag(&mut self, value: i32) -> Result<()>
Write sfixed32
Sourcepub fn write_bool_no_tag(&mut self, value: bool) -> Result<()>
pub fn write_bool_no_tag(&mut self, value: bool) -> Result<()>
Write bool
Sourcepub fn write_enum_no_tag(&mut self, value: i32) -> Result<()>
pub fn write_enum_no_tag(&mut self, value: i32) -> Result<()>
Write enum
Sourcepub fn write_enum_obj_no_tag<E>(&mut self, value: E) -> Result<()>where
E: Enum,
pub fn write_enum_obj_no_tag<E>(&mut self, value: E) -> Result<()>where
E: Enum,
Write enum
Sourcepub fn write_enum_or_unknown_no_tag<E>(
&mut self,
value: EnumOrUnknown<E>,
) -> Result<()>where
E: Enum,
pub fn write_enum_or_unknown_no_tag<E>(
&mut self,
value: EnumOrUnknown<E>,
) -> Result<()>where
E: Enum,
Write enum
Sourcepub fn write_unknown_no_tag(
&mut self,
unknown: UnknownValueRef<'_>,
) -> Result<()>
pub fn write_unknown_no_tag( &mut self, unknown: UnknownValueRef<'_>, ) -> Result<()>
Write unknown value
Sourcepub fn write_fixed64(&mut self, field_number: u32, value: u64) -> Result<()>
pub fn write_fixed64(&mut self, field_number: u32, value: u64) -> Result<()>
Write fixed64
field
Sourcepub fn write_fixed32(&mut self, field_number: u32, value: u32) -> Result<()>
pub fn write_fixed32(&mut self, field_number: u32, value: u32) -> Result<()>
Write fixed32
field
Sourcepub fn write_sfixed64(&mut self, field_number: u32, value: i64) -> Result<()>
pub fn write_sfixed64(&mut self, field_number: u32, value: i64) -> Result<()>
Write sfixed64
field
Sourcepub fn write_sfixed32(&mut self, field_number: u32, value: i32) -> Result<()>
pub fn write_sfixed32(&mut self, field_number: u32, value: i32) -> Result<()>
Write sfixed32
field
Sourcepub fn write_enum_obj<E>(&mut self, field_number: u32, value: E) -> Result<()>where
E: Enum,
pub fn write_enum_obj<E>(&mut self, field_number: u32, value: E) -> Result<()>where
E: Enum,
Write enum
field
Sourcepub fn write_enum_or_unknown<E>(
&mut self,
field_number: u32,
value: EnumOrUnknown<E>,
) -> Result<()>where
E: Enum,
pub fn write_enum_or_unknown<E>(
&mut self,
field_number: u32,
value: EnumOrUnknown<E>,
) -> Result<()>where
E: Enum,
Write enum
field
Sourcepub fn write_unknown(
&mut self,
field_number: u32,
value: UnknownValueRef<'_>,
) -> Result<()>
pub fn write_unknown( &mut self, field_number: u32, value: UnknownValueRef<'_>, ) -> Result<()>
Write unknown field
Sourcepub fn write_unknown_fields(&mut self, fields: &UnknownFields) -> Result<()>
pub fn write_unknown_fields(&mut self, fields: &UnknownFields) -> Result<()>
Write unknown fields
Sourcepub fn write_bytes_no_tag(&mut self, bytes: &[u8]) -> Result<()>
pub fn write_bytes_no_tag(&mut self, bytes: &[u8]) -> Result<()>
Write bytes
Sourcepub fn write_string_no_tag(&mut self, s: &str) -> Result<()>
pub fn write_string_no_tag(&mut self, s: &str) -> Result<()>
Write string
Sourcepub fn write_message_no_tag_dyn(&mut self, msg: &dyn MessageDyn) -> Result<()>
pub fn write_message_no_tag_dyn(&mut self, msg: &dyn MessageDyn) -> Result<()>
Write dynamic message
Sourcepub fn write_repeated_packed_float_no_tag(
&mut self,
values: &[f32],
) -> Result<()>
pub fn write_repeated_packed_float_no_tag( &mut self, values: &[f32], ) -> Result<()>
Write repeated packed float values.
Sourcepub fn write_repeated_packed_float(
&mut self,
field_number: u32,
values: &[f32],
) -> Result<()>
pub fn write_repeated_packed_float( &mut self, field_number: u32, values: &[f32], ) -> Result<()>
Write field header and data for repeated packed float.
Sourcepub fn write_repeated_packed_double_no_tag(
&mut self,
values: &[f64],
) -> Result<()>
pub fn write_repeated_packed_double_no_tag( &mut self, values: &[f64], ) -> Result<()>
Write repeated packed double values.
Sourcepub fn write_repeated_packed_double(
&mut self,
field_number: u32,
values: &[f64],
) -> Result<()>
pub fn write_repeated_packed_double( &mut self, field_number: u32, values: &[f64], ) -> Result<()>
Write field header and data for repeated packed double.
Sourcepub fn write_repeated_packed_fixed32_no_tag(
&mut self,
values: &[u32],
) -> Result<()>
pub fn write_repeated_packed_fixed32_no_tag( &mut self, values: &[u32], ) -> Result<()>
Write repeated packed fixed32 values.
Sourcepub fn write_repeated_packed_fixed32(
&mut self,
field_number: u32,
values: &[u32],
) -> Result<()>
pub fn write_repeated_packed_fixed32( &mut self, field_number: u32, values: &[u32], ) -> Result<()>
Write field header and data for repeated packed fixed32.
Sourcepub fn write_repeated_packed_fixed64_no_tag(
&mut self,
values: &[u64],
) -> Result<()>
pub fn write_repeated_packed_fixed64_no_tag( &mut self, values: &[u64], ) -> Result<()>
Write repeated packed fixed64 values.
Sourcepub fn write_repeated_packed_fixed64(
&mut self,
field_number: u32,
values: &[u64],
) -> Result<()>
pub fn write_repeated_packed_fixed64( &mut self, field_number: u32, values: &[u64], ) -> Result<()>
Write field header and data for repeated packed fixed64.
Sourcepub fn write_repeated_packed_sfixed32_no_tag(
&mut self,
values: &[i32],
) -> Result<()>
pub fn write_repeated_packed_sfixed32_no_tag( &mut self, values: &[i32], ) -> Result<()>
Write repeated packed sfixed32 values.
Sourcepub fn write_repeated_packed_sfixed32(
&mut self,
field_number: u32,
values: &[i32],
) -> Result<()>
pub fn write_repeated_packed_sfixed32( &mut self, field_number: u32, values: &[i32], ) -> Result<()>
Write field header and data for repeated packed sfixed32.
Sourcepub fn write_repeated_packed_sfixed64_no_tag(
&mut self,
values: &[i64],
) -> Result<()>
pub fn write_repeated_packed_sfixed64_no_tag( &mut self, values: &[i64], ) -> Result<()>
Write repeated packed sfixed64 values.
Sourcepub fn write_repeated_packed_sfixed64(
&mut self,
field_number: u32,
values: &[i64],
) -> Result<()>
pub fn write_repeated_packed_sfixed64( &mut self, field_number: u32, values: &[i64], ) -> Result<()>
Write field header and data for repeated packed sfixed64.
Sourcepub fn write_repeated_packed_int32_no_tag(
&mut self,
values: &[i32],
) -> Result<()>
pub fn write_repeated_packed_int32_no_tag( &mut self, values: &[i32], ) -> Result<()>
Write repeated packed int32 values.
Sourcepub fn write_repeated_packed_int32(
&mut self,
field_number: u32,
values: &[i32],
) -> Result<()>
pub fn write_repeated_packed_int32( &mut self, field_number: u32, values: &[i32], ) -> Result<()>
Write field header and data for repeated packed int32.
Sourcepub fn write_repeated_packed_int64_no_tag(
&mut self,
values: &[i64],
) -> Result<()>
pub fn write_repeated_packed_int64_no_tag( &mut self, values: &[i64], ) -> Result<()>
Write repeated packed int64 values.
Sourcepub fn write_repeated_packed_int64(
&mut self,
field_number: u32,
values: &[i64],
) -> Result<()>
pub fn write_repeated_packed_int64( &mut self, field_number: u32, values: &[i64], ) -> Result<()>
Write field header and data for repeated packed int64.
Sourcepub fn write_repeated_packed_uint32_no_tag(
&mut self,
values: &[u32],
) -> Result<()>
pub fn write_repeated_packed_uint32_no_tag( &mut self, values: &[u32], ) -> Result<()>
Write repeated packed uint32 values.
Sourcepub fn write_repeated_packed_uint32(
&mut self,
field_number: u32,
values: &[u32],
) -> Result<()>
pub fn write_repeated_packed_uint32( &mut self, field_number: u32, values: &[u32], ) -> Result<()>
Write field header and data for repeated packed uint32.
Sourcepub fn write_repeated_packed_uint64_no_tag(
&mut self,
values: &[u64],
) -> Result<()>
pub fn write_repeated_packed_uint64_no_tag( &mut self, values: &[u64], ) -> Result<()>
Write repeated packed uint64 values.
Sourcepub fn write_repeated_packed_uint64(
&mut self,
field_number: u32,
values: &[u64],
) -> Result<()>
pub fn write_repeated_packed_uint64( &mut self, field_number: u32, values: &[u64], ) -> Result<()>
Write field header and data for repeated packed uint64.
Sourcepub fn write_repeated_packed_sint32_no_tag(
&mut self,
values: &[i32],
) -> Result<()>
pub fn write_repeated_packed_sint32_no_tag( &mut self, values: &[i32], ) -> Result<()>
Write repeated packed sint32 values.
Sourcepub fn write_repeated_packed_sint32(
&mut self,
field_number: u32,
values: &[i32],
) -> Result<()>
pub fn write_repeated_packed_sint32( &mut self, field_number: u32, values: &[i32], ) -> Result<()>
Write field header and data for repeated packed sint32.
Sourcepub fn write_repeated_packed_sint64_no_tag(
&mut self,
values: &[i64],
) -> Result<()>
pub fn write_repeated_packed_sint64_no_tag( &mut self, values: &[i64], ) -> Result<()>
Write repeated packed sint64 values.
Sourcepub fn write_repeated_packed_sint64(
&mut self,
field_number: u32,
values: &[i64],
) -> Result<()>
pub fn write_repeated_packed_sint64( &mut self, field_number: u32, values: &[i64], ) -> Result<()>
Write field header and data for repeated packed sint64.
Sourcepub fn write_repeated_packed_bool_no_tag(
&mut self,
values: &[bool],
) -> Result<()>
pub fn write_repeated_packed_bool_no_tag( &mut self, values: &[bool], ) -> Result<()>
Write repeated packed bool values.
Sourcepub fn write_repeated_packed_bool(
&mut self,
field_number: u32,
values: &[bool],
) -> Result<()>
pub fn write_repeated_packed_bool( &mut self, field_number: u32, values: &[bool], ) -> Result<()>
Write field header and data for repeated packed bool.
Sourcepub fn write_repeated_packed_enum_or_unknown_no_tag<E: Enum>(
&mut self,
values: &[EnumOrUnknown<E>],
) -> Result<()>
pub fn write_repeated_packed_enum_or_unknown_no_tag<E: Enum>( &mut self, values: &[EnumOrUnknown<E>], ) -> Result<()>
Write repeated packed enum values.
Sourcepub fn write_repeated_packed_enum_or_unknown<E: Enum>(
&mut self,
field_number: u32,
values: &[EnumOrUnknown<E>],
) -> Result<()>
pub fn write_repeated_packed_enum_or_unknown<E: Enum>( &mut self, field_number: u32, values: &[EnumOrUnknown<E>], ) -> Result<()>
Write field header and data for repeated packed enum.
Sourcepub fn write_message<M: MessageFull>(
&mut self,
field_number: u32,
msg: &M,
) -> Result<()>
pub fn write_message<M: MessageFull>( &mut self, field_number: u32, msg: &M, ) -> Result<()>
Write message
field
Sourcepub fn write_message_dyn(
&mut self,
field_number: u32,
msg: &dyn MessageDyn,
) -> Result<()>
pub fn write_message_dyn( &mut self, field_number: u32, msg: &dyn MessageDyn, ) -> Result<()>
Write dynamic message
field
Trait Implementations§
Source§impl<'a> Debug for CodedOutputStream<'a>
impl<'a> Debug for CodedOutputStream<'a>
Source§impl<'a> Drop for CodedOutputStream<'a>
impl<'a> Drop for CodedOutputStream<'a>
Source§impl<'a> Write for CodedOutputStream<'a>
impl<'a> Write for CodedOutputStream<'a>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)