pub struct CodedInputStream<'a> { /* private fields */ }
Expand description
Buffered read with handy utilities.
Implementations§
Source§impl<'a> CodedInputStream<'a>
impl<'a> CodedInputStream<'a>
Sourcepub fn new(read: &'a mut dyn Read) -> CodedInputStream<'a> ⓘ
pub fn new(read: &'a mut dyn Read) -> CodedInputStream<'a> ⓘ
Wrap a Read
.
Note resulting CodedInputStream
is buffered.
If Read
is buffered, the resulting stream will be double buffered,
consider using from_buf_read
instead.
Sourcepub fn from_buf_read(buf_read: &'a mut dyn BufRead) -> CodedInputStream<'a> ⓘ
pub fn from_buf_read(buf_read: &'a mut dyn BufRead) -> CodedInputStream<'a> ⓘ
Create from BufRead
.
CodedInputStream
will utilize BufRead
buffer.
Sourcepub fn from_bytes(bytes: &'a [u8]) -> CodedInputStream<'a> ⓘ
pub fn from_bytes(bytes: &'a [u8]) -> CodedInputStream<'a> ⓘ
Read from byte slice
Sourcepub fn set_recursion_limit(&mut self, limit: u32)
pub fn set_recursion_limit(&mut self, limit: u32)
Set the recursion limit.
Sourcepub fn bytes_until_limit(&self) -> u64
pub fn bytes_until_limit(&self) -> u64
How many bytes until current limit
Sourcepub fn read_exact(&mut self, buf: &mut [MaybeUninit<u8>]) -> Result<(), Error>
pub fn read_exact(&mut self, buf: &mut [MaybeUninit<u8>]) -> Result<(), Error>
Read bytes into given buf
.
Sourcepub fn read_raw_byte(&mut self) -> Result<u8, Error>
pub fn read_raw_byte(&mut self) -> Result<u8, Error>
Read one byte
Sourcepub fn push_limit(&mut self, limit: u64) -> Result<u64, Error>
pub fn push_limit(&mut self, limit: u64) -> Result<u64, Error>
Push new limit, return previous limit.
Sourcepub fn check_eof(&mut self) -> Result<(), Error>
pub fn check_eof(&mut self) -> Result<(), Error>
Check we are at EOF.
Return error if we are not at EOF.
Sourcepub fn read_raw_varint64(&mut self) -> Result<u64, Error>
pub fn read_raw_varint64(&mut self) -> Result<u64, Error>
Read varint
Sourcepub fn read_raw_varint32(&mut self) -> Result<u32, Error>
pub fn read_raw_varint32(&mut self) -> Result<u32, Error>
Read varint
Sourcepub fn read_raw_little_endian32(&mut self) -> Result<u32, Error>
pub fn read_raw_little_endian32(&mut self) -> Result<u32, Error>
Read little-endian 32-bit integer
Sourcepub fn read_raw_little_endian64(&mut self) -> Result<u64, Error>
pub fn read_raw_little_endian64(&mut self) -> Result<u64, Error>
Read little-endian 64-bit integer
Sourcepub fn read_raw_tag_or_eof(&mut self) -> Result<Option<u32>, Error>
pub fn read_raw_tag_or_eof(&mut self) -> Result<Option<u32>, Error>
Read tag number as u32
or None if EOF is reached.
Sourcepub fn read_double(&mut self) -> Result<f64, Error>
pub fn read_double(&mut self) -> Result<f64, Error>
Read double
Sourcepub fn read_float(&mut self) -> Result<f32, Error>
pub fn read_float(&mut self) -> Result<f32, Error>
Read float
Sourcepub fn read_int64(&mut self) -> Result<i64, Error>
pub fn read_int64(&mut self) -> Result<i64, Error>
Read int64
Sourcepub fn read_int32(&mut self) -> Result<i32, Error>
pub fn read_int32(&mut self) -> Result<i32, Error>
Read int32
Sourcepub fn read_uint64(&mut self) -> Result<u64, Error>
pub fn read_uint64(&mut self) -> Result<u64, Error>
Read uint64
Sourcepub fn read_uint32(&mut self) -> Result<u32, Error>
pub fn read_uint32(&mut self) -> Result<u32, Error>
Read uint32
Sourcepub fn read_sint64(&mut self) -> Result<i64, Error>
pub fn read_sint64(&mut self) -> Result<i64, Error>
Read sint64
Sourcepub fn read_sint32(&mut self) -> Result<i32, Error>
pub fn read_sint32(&mut self) -> Result<i32, Error>
Read sint32
Sourcepub fn read_fixed64(&mut self) -> Result<u64, Error>
pub fn read_fixed64(&mut self) -> Result<u64, Error>
Read fixed64
Sourcepub fn read_fixed32(&mut self) -> Result<u32, Error>
pub fn read_fixed32(&mut self) -> Result<u32, Error>
Read fixed32
Sourcepub fn read_sfixed64(&mut self) -> Result<i64, Error>
pub fn read_sfixed64(&mut self) -> Result<i64, Error>
Read sfixed64
Sourcepub fn read_sfixed32(&mut self) -> Result<i32, Error>
pub fn read_sfixed32(&mut self) -> Result<i32, Error>
Read sfixed32
Sourcepub fn read_enum_or_unknown<E>(&mut self) -> Result<EnumOrUnknown<E>, Error>where
E: Enum,
pub fn read_enum_or_unknown<E>(&mut self) -> Result<EnumOrUnknown<E>, Error>where
E: Enum,
Read enum
as ProtobufEnumOrUnknown
Sourcepub fn read_repeated_packed_double_into(
&mut self,
target: &mut Vec<f64>,
) -> Result<(), Error>
pub fn read_repeated_packed_double_into( &mut self, target: &mut Vec<f64>, ) -> Result<(), Error>
Read repeated packed double
Sourcepub fn read_repeated_packed_float_into(
&mut self,
target: &mut Vec<f32>,
) -> Result<(), Error>
pub fn read_repeated_packed_float_into( &mut self, target: &mut Vec<f32>, ) -> Result<(), Error>
Read repeated packed float
Sourcepub fn read_repeated_packed_int64_into(
&mut self,
target: &mut Vec<i64>,
) -> Result<(), Error>
pub fn read_repeated_packed_int64_into( &mut self, target: &mut Vec<i64>, ) -> Result<(), Error>
Read repeated packed int64
Sourcepub fn read_repeated_packed_int32_into(
&mut self,
target: &mut Vec<i32>,
) -> Result<(), Error>
pub fn read_repeated_packed_int32_into( &mut self, target: &mut Vec<i32>, ) -> Result<(), Error>
Read repeated packed int32
Sourcepub fn read_repeated_packed_uint64_into(
&mut self,
target: &mut Vec<u64>,
) -> Result<(), Error>
pub fn read_repeated_packed_uint64_into( &mut self, target: &mut Vec<u64>, ) -> Result<(), Error>
Read repeated packed uint64
Sourcepub fn read_repeated_packed_uint32_into(
&mut self,
target: &mut Vec<u32>,
) -> Result<(), Error>
pub fn read_repeated_packed_uint32_into( &mut self, target: &mut Vec<u32>, ) -> Result<(), Error>
Read repeated packed uint32
Sourcepub fn read_repeated_packed_sint64_into(
&mut self,
target: &mut Vec<i64>,
) -> Result<(), Error>
pub fn read_repeated_packed_sint64_into( &mut self, target: &mut Vec<i64>, ) -> Result<(), Error>
Read repeated packed sint64
Sourcepub fn read_repeated_packed_sint32_into(
&mut self,
target: &mut Vec<i32>,
) -> Result<(), Error>
pub fn read_repeated_packed_sint32_into( &mut self, target: &mut Vec<i32>, ) -> Result<(), Error>
Read repeated packed sint32
Sourcepub fn read_repeated_packed_fixed64_into(
&mut self,
target: &mut Vec<u64>,
) -> Result<(), Error>
pub fn read_repeated_packed_fixed64_into( &mut self, target: &mut Vec<u64>, ) -> Result<(), Error>
Read repeated packed fixed64
Sourcepub fn read_repeated_packed_fixed32_into(
&mut self,
target: &mut Vec<u32>,
) -> Result<(), Error>
pub fn read_repeated_packed_fixed32_into( &mut self, target: &mut Vec<u32>, ) -> Result<(), Error>
Read repeated packed fixed32
Sourcepub fn read_repeated_packed_sfixed64_into(
&mut self,
target: &mut Vec<i64>,
) -> Result<(), Error>
pub fn read_repeated_packed_sfixed64_into( &mut self, target: &mut Vec<i64>, ) -> Result<(), Error>
Read repeated packed sfixed64
Sourcepub fn read_repeated_packed_sfixed32_into(
&mut self,
target: &mut Vec<i32>,
) -> Result<(), Error>
pub fn read_repeated_packed_sfixed32_into( &mut self, target: &mut Vec<i32>, ) -> Result<(), Error>
Read repeated packed sfixed32
Sourcepub fn read_repeated_packed_bool_into(
&mut self,
target: &mut Vec<bool>,
) -> Result<(), Error>
pub fn read_repeated_packed_bool_into( &mut self, target: &mut Vec<bool>, ) -> Result<(), Error>
Read repeated packed bool
Sourcepub fn read_unknown(
&mut self,
wire_type: WireType,
) -> Result<UnknownValue, Error>
pub fn read_unknown( &mut self, wire_type: WireType, ) -> Result<UnknownValue, Error>
Read UnknownValue
Sourcepub fn read_raw_bytes_into(
&mut self,
count: u32,
target: &mut Vec<u8>,
) -> Result<(), Error>
pub fn read_raw_bytes_into( &mut self, count: u32, target: &mut Vec<u8>, ) -> Result<(), Error>
Read raw bytes into the supplied vector. The vector will be resized as needed and overwritten.
Sourcepub fn read_raw_bytes(&mut self, count: u32) -> Result<Vec<u8>, Error>
pub fn read_raw_bytes(&mut self, count: u32) -> Result<Vec<u8>, Error>
Read exact number of bytes
Sourcepub fn read_bytes_into(&mut self, target: &mut Vec<u8>) -> Result<(), Error>
pub fn read_bytes_into(&mut self, target: &mut Vec<u8>) -> Result<(), Error>
Read bytes
field, length delimited
Sourcepub fn read_string(&mut self) -> Result<String, Error>
pub fn read_string(&mut self) -> Result<String, Error>
Read string
field, length delimited
Sourcepub fn read_string_into(&mut self, target: &mut String) -> Result<(), Error>
pub fn read_string_into(&mut self, target: &mut String) -> Result<(), Error>
Read string
field, length delimited
Sourcepub fn merge_message<M>(&mut self, message: &mut M) -> Result<(), Error>where
M: Message,
pub fn merge_message<M>(&mut self, message: &mut M) -> Result<(), Error>where
M: Message,
Read message, do not check if message is initialized
Sourcepub fn merge_message_dyn(
&mut self,
message: &mut (dyn MessageDyn + 'static),
) -> Result<(), Error>
pub fn merge_message_dyn( &mut self, message: &mut (dyn MessageDyn + 'static), ) -> Result<(), Error>
Like merge_message
, but for dynamic messages.
Sourcepub fn read_message<M>(&mut self) -> Result<M, Error>where
M: Message,
pub fn read_message<M>(&mut self) -> Result<M, Error>where
M: Message,
Read message
Sourcepub fn read_message_dyn(
&mut self,
descriptor: &MessageDescriptor,
) -> Result<Box<dyn MessageDyn>, Error>
pub fn read_message_dyn( &mut self, descriptor: &MessageDescriptor, ) -> Result<Box<dyn MessageDyn>, Error>
Read message.
Trait Implementations§
Source§impl<'a> BufRead for CodedInputStream<'a>
impl<'a> BufRead for CodedInputStream<'a>
Source§fn fill_buf(&mut self) -> Result<&[u8], Error>
fn fill_buf(&mut self) -> Result<&[u8], Error>
Read
methods, if empty. Read moreSource§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
amount
of additional bytes from the internal buffer as having been read.
Subsequent calls to read
only return bytes that have not been marked as read. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left
)read
. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
byte
or EOF is reached. Read more1.0.0 · Source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
0xA
byte) is reached, and append
them to the provided String
buffer. Read moreSource§impl<'a> Debug for CodedInputStream<'a>
impl<'a> Debug for CodedInputStream<'a>
Source§impl<'a> Read for CodedInputStream<'a>
impl<'a> Read for CodedInputStream<'a>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Error>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreAuto Trait Implementations§
impl<'a> Freeze for CodedInputStream<'a>
impl<'a> !RefUnwindSafe for CodedInputStream<'a>
impl<'a> !Send for CodedInputStream<'a>
impl<'a> !Sync for CodedInputStream<'a>
impl<'a> Unpin for CodedInputStream<'a>
impl<'a> !UnwindSafe for CodedInputStream<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more