pub struct CodedOutputStream<'a> { /* private fields */ }
Expand description

Buffered write with handy utilities

Implementations§

source§

impl<'a> CodedOutputStream<'a>

source

pub fn new(writer: &'a mut dyn Write) -> CodedOutputStream<'a>

Construct from given Write.

CodedOutputStream is buffered even if Write is not

source

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.

source

pub fn vec(vec: &'a mut Vec<u8>) -> CodedOutputStream<'a>

CodedOutputStream which writes directly to Vec<u8>.

source

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.

source

pub fn check_eof(&self)

Check if EOF is reached.

§Panics

If underlying write has no EOF

source

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.

source

pub fn write_raw_byte(&mut self, byte: u8) -> Result<()>

Write a byte

source

pub fn write_raw_bytes(&mut self, bytes: &[u8]) -> Result<()>

Write bytes

source

pub fn write_tag( &mut self, field_number: u32, wire_type: WireType ) -> Result<()>

Write a tag

source

pub fn write_raw_varint32(&mut self, value: u32) -> Result<()>

Write varint

source

pub fn write_raw_varint64(&mut self, value: u64) -> Result<()>

Write varint

source

pub fn write_raw_little_endian32(&mut self, value: u32) -> Result<()>

Write 32-bit integer little endian

source

pub fn write_raw_little_endian64(&mut self, value: u64) -> Result<()>

Write 64-bit integer little endian

source

pub fn write_float_no_tag(&mut self, value: f32) -> Result<()>

Write float

source

pub fn write_double_no_tag(&mut self, value: f64) -> Result<()>

Write double

source

pub fn write_float(&mut self, field_number: u32, value: f32) -> Result<()>

Write float field

source

pub fn write_double(&mut self, field_number: u32, value: f64) -> Result<()>

Write double field

source

pub fn write_uint64_no_tag(&mut self, value: u64) -> Result<()>

Write varint

source

pub fn write_uint32_no_tag(&mut self, value: u32) -> Result<()>

Write varint

source

pub fn write_int64_no_tag(&mut self, value: i64) -> Result<()>

Write varint

source

pub fn write_int32_no_tag(&mut self, value: i32) -> Result<()>

Write varint

source

pub fn write_sint64_no_tag(&mut self, value: i64) -> Result<()>

Write zigzag varint

source

pub fn write_sint32_no_tag(&mut self, value: i32) -> Result<()>

Write zigzag varint

source

pub fn write_fixed64_no_tag(&mut self, value: u64) -> Result<()>

Write fixed64

source

pub fn write_fixed32_no_tag(&mut self, value: u32) -> Result<()>

Write fixed32

source

pub fn write_sfixed64_no_tag(&mut self, value: i64) -> Result<()>

Write sfixed64

source

pub fn write_sfixed32_no_tag(&mut self, value: i32) -> Result<()>

Write sfixed32

source

pub fn write_bool_no_tag(&mut self, value: bool) -> Result<()>

Write bool

source

pub fn write_enum_no_tag(&mut self, value: i32) -> Result<()>

Write enum

source

pub fn write_enum_obj_no_tag<E>(&mut self, value: E) -> Result<()>
where E: Enum,

Write enum

source

pub fn write_enum_or_unknown_no_tag<E>( &mut self, value: EnumOrUnknown<E> ) -> Result<()>
where E: Enum,

Write enum

source

pub fn write_unknown_no_tag( &mut self, unknown: UnknownValueRef<'_> ) -> Result<()>

Write unknown value

source

pub fn write_uint64(&mut self, field_number: u32, value: u64) -> Result<()>

Write uint64 field

source

pub fn write_uint32(&mut self, field_number: u32, value: u32) -> Result<()>

Write uint32 field

source

pub fn write_int64(&mut self, field_number: u32, value: i64) -> Result<()>

Write int64 field

source

pub fn write_int32(&mut self, field_number: u32, value: i32) -> Result<()>

Write int32 field

source

pub fn write_sint64(&mut self, field_number: u32, value: i64) -> Result<()>

Write sint64 field

source

pub fn write_sint32(&mut self, field_number: u32, value: i32) -> Result<()>

Write sint32 field

source

pub fn write_fixed64(&mut self, field_number: u32, value: u64) -> Result<()>

Write fixed64 field

source

pub fn write_fixed32(&mut self, field_number: u32, value: u32) -> Result<()>

Write fixed32 field

source

pub fn write_sfixed64(&mut self, field_number: u32, value: i64) -> Result<()>

Write sfixed64 field

source

pub fn write_sfixed32(&mut self, field_number: u32, value: i32) -> Result<()>

Write sfixed32 field

source

pub fn write_bool(&mut self, field_number: u32, value: bool) -> Result<()>

Write bool field

source

pub fn write_enum(&mut self, field_number: u32, value: i32) -> Result<()>

Write enum field

source

pub fn write_enum_obj<E>(&mut self, field_number: u32, value: E) -> Result<()>
where E: Enum,

Write enum field

source

pub fn write_enum_or_unknown<E>( &mut self, field_number: u32, value: EnumOrUnknown<E> ) -> Result<()>
where E: Enum,

Write enum field

source

pub fn write_unknown( &mut self, field_number: u32, value: UnknownValueRef<'_> ) -> Result<()>

Write unknown field

source

pub fn write_unknown_fields(&mut self, fields: &UnknownFields) -> Result<()>

Write unknown fields

source

pub fn write_bytes_no_tag(&mut self, bytes: &[u8]) -> Result<()>

Write bytes

source

pub fn write_string_no_tag(&mut self, s: &str) -> Result<()>

Write string

source

pub fn write_message_no_tag<M: Message>(&mut self, msg: &M) -> Result<()>

Write message

source

pub fn write_message_no_tag_dyn(&mut self, msg: &dyn MessageDyn) -> Result<()>

Write dynamic message

source

pub fn write_bytes(&mut self, field_number: u32, bytes: &[u8]) -> Result<()>

Write bytes field

source

pub fn write_string(&mut self, field_number: u32, s: &str) -> Result<()>

Write string field

source

pub fn write_repeated_packed_float_no_tag( &mut self, values: &[f32] ) -> Result<()>

Write repeated packed float values.

source

pub fn write_repeated_packed_float( &mut self, field_number: u32, values: &[f32] ) -> Result<()>

Write field header and data for repeated packed float.

source

pub fn write_repeated_packed_double_no_tag( &mut self, values: &[f64] ) -> Result<()>

Write repeated packed double values.

source

pub fn write_repeated_packed_double( &mut self, field_number: u32, values: &[f64] ) -> Result<()>

Write field header and data for repeated packed double.

source

pub fn write_repeated_packed_fixed32_no_tag( &mut self, values: &[u32] ) -> Result<()>

Write repeated packed fixed32 values.

source

pub fn write_repeated_packed_fixed32( &mut self, field_number: u32, values: &[u32] ) -> Result<()>

Write field header and data for repeated packed fixed32.

source

pub fn write_repeated_packed_fixed64_no_tag( &mut self, values: &[u64] ) -> Result<()>

Write repeated packed fixed64 values.

source

pub fn write_repeated_packed_fixed64( &mut self, field_number: u32, values: &[u64] ) -> Result<()>

Write field header and data for repeated packed fixed64.

source

pub fn write_repeated_packed_sfixed32_no_tag( &mut self, values: &[i32] ) -> Result<()>

Write repeated packed sfixed32 values.

source

pub fn write_repeated_packed_sfixed32( &mut self, field_number: u32, values: &[i32] ) -> Result<()>

Write field header and data for repeated packed sfixed32.

source

pub fn write_repeated_packed_sfixed64_no_tag( &mut self, values: &[i64] ) -> Result<()>

Write repeated packed sfixed64 values.

source

pub fn write_repeated_packed_sfixed64( &mut self, field_number: u32, values: &[i64] ) -> Result<()>

Write field header and data for repeated packed sfixed64.

source

pub fn write_repeated_packed_int32_no_tag( &mut self, values: &[i32] ) -> Result<()>

Write repeated packed int32 values.

source

pub fn write_repeated_packed_int32( &mut self, field_number: u32, values: &[i32] ) -> Result<()>

Write field header and data for repeated packed int32.

source

pub fn write_repeated_packed_int64_no_tag( &mut self, values: &[i64] ) -> Result<()>

Write repeated packed int64 values.

source

pub fn write_repeated_packed_int64( &mut self, field_number: u32, values: &[i64] ) -> Result<()>

Write field header and data for repeated packed int64.

source

pub fn write_repeated_packed_uint32_no_tag( &mut self, values: &[u32] ) -> Result<()>

Write repeated packed uint32 values.

source

pub fn write_repeated_packed_uint32( &mut self, field_number: u32, values: &[u32] ) -> Result<()>

Write field header and data for repeated packed uint32.

source

pub fn write_repeated_packed_uint64_no_tag( &mut self, values: &[u64] ) -> Result<()>

Write repeated packed uint64 values.

source

pub fn write_repeated_packed_uint64( &mut self, field_number: u32, values: &[u64] ) -> Result<()>

Write field header and data for repeated packed uint64.

source

pub fn write_repeated_packed_sint32_no_tag( &mut self, values: &[i32] ) -> Result<()>

Write repeated packed sint32 values.

source

pub fn write_repeated_packed_sint32( &mut self, field_number: u32, values: &[i32] ) -> Result<()>

Write field header and data for repeated packed sint32.

source

pub fn write_repeated_packed_sint64_no_tag( &mut self, values: &[i64] ) -> Result<()>

Write repeated packed sint64 values.

source

pub fn write_repeated_packed_sint64( &mut self, field_number: u32, values: &[i64] ) -> Result<()>

Write field header and data for repeated packed sint64.

source

pub fn write_repeated_packed_bool_no_tag( &mut self, values: &[bool] ) -> Result<()>

Write repeated packed bool values.

source

pub fn write_repeated_packed_bool( &mut self, field_number: u32, values: &[bool] ) -> Result<()>

Write field header and data for repeated packed bool.

source

pub fn write_repeated_packed_enum_or_unknown_no_tag<E: Enum>( &mut self, values: &[EnumOrUnknown<E>] ) -> Result<()>

Write repeated packed enum values.

source

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.

source

pub fn write_message<M: MessageFull>( &mut self, field_number: u32, msg: &M ) -> Result<()>

Write message field

source

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>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Drop for CodedOutputStream<'a>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a> Write for CodedOutputStream<'a>

source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer into this writer, returning how many bytes were written. Read more
source§

fn flush(&mut self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for CodedOutputStream<'a>

§

impl<'a> !Send for CodedOutputStream<'a>

§

impl<'a> !Sync for CodedOutputStream<'a>

§

impl<'a> Unpin for CodedOutputStream<'a>

§

impl<'a> !UnwindSafe for CodedOutputStream<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.