Struct ion_rs::binary::non_blocking::raw_binary_reader::RawBinaryReader
source · pub struct RawBinaryReader<A: AsRef<[u8]> + Expandable> { /* private fields */ }
Expand description
A raw binary reader that pulls input bytes from a fixed buffer.
If any read operation fails due to the buffer containing incomplete data, that method will
return IonError::Incomplete
.
If the buffer (generic type A
) is a Vec<u8>
, then data can be appended to it between read
operations. This can be useful when reading from a data source that is growing over time, such
as when tailing a growing file, reading over the network, or waiting for user input.
Applications can read from the buffer until they encounter an Incomplete
. Then, when more
data is available, they can use read_from or
append_bytes to add that data to the buffer.
Finally, they can retry the read operation that had previously failed.
Note that if the buffer runs out of data between top level values, this will be interpreted as the end of the stream. Applications can still add more data to the buffer and resume reading.
Implementations§
source§impl<A: AsRef<[u8]> + Expandable> RawBinaryReader<A>
impl<A: AsRef<[u8]> + Expandable> RawBinaryReader<A>
sourcepub fn new(source: A) -> RawBinaryReader<A>
pub fn new(source: A) -> RawBinaryReader<A>
Constructs a RawBinaryReader from a value that can be viewed as a byte slice.
sourcepub fn annotations_iter(
&self
) -> impl Iterator<Item = IonResult<RawSymbolToken>> + '_
pub fn annotations_iter( &self ) -> impl Iterator<Item = IonResult<RawSymbolToken>> + '_
Creates an iterator that lazily reads the VarUInt symbol IDs in this value’s annotations wrapper. If the reader is not on a value or the current value does not have annotations, the iterator will be empty.
sourcepub fn read_symbol_id(&mut self) -> IonResult<SymbolId>
pub fn read_symbol_id(&mut self) -> IonResult<SymbolId>
If the reader is currently positioned on a symbol value, parses that value into a SymbolId
.
sourcepub fn read_str_bytes(&mut self) -> IonResult<&[u8]>
pub fn read_str_bytes(&mut self) -> IonResult<&[u8]>
If the reader is currently positioned on a string, returns the slice of bytes that represents that string’s UNVALIDATED utf-8 bytes. This method is available for performance optimization in scenarios where utf-8 validation may be unnecessary and/or a bottleneck. It is strongly recommended that you use read_str unless absolutely necessary.
sourcepub fn read_blob_bytes(&mut self) -> IonResult<&[u8]>
pub fn read_blob_bytes(&mut self) -> IonResult<&[u8]>
If the reader is currently positioned on a blob, returns a slice containing its bytes.
sourcepub fn read_clob_bytes(&mut self) -> IonResult<&[u8]>
pub fn read_clob_bytes(&mut self) -> IonResult<&[u8]>
If the reader is currently positioned on a clob, returns a slice containing its bytes.
pub fn header_length(&self) -> usize
sourcepub fn raw_bytes(&self) -> Option<&[u8]>
pub fn raw_bytes(&self) -> Option<&[u8]>
Returns a slice containing the current value’s bytes. In the case of a container the raw bytes will consist of its field ID (if present), its annotations (if present), and its header. In the case of a non-container value, the bytes for the value itself is also included.
pub fn raw_field_id_bytes(&self) -> Option<&[u8]>
pub fn raw_header_bytes(&self) -> Option<&[u8]>
pub fn raw_value_bytes(&self) -> Option<&[u8]>
pub fn raw_annotations_bytes(&self) -> Option<&[u8]>
pub fn field_id_length(&self) -> Option<usize>
pub fn field_id_offset(&self) -> Option<usize>
pub fn field_id_range(&self) -> Option<Range<usize>>
pub fn annotations_length(&self) -> Option<usize>
pub fn annotations_offset(&self) -> Option<usize>
pub fn annotations_range(&self) -> Option<Range<usize>>
pub fn header_offset(&self) -> usize
pub fn header_range(&self) -> Range<usize>
pub fn value_length(&self) -> usize
pub fn value_offset(&self) -> usize
pub fn value_range(&self) -> Range<usize>
Trait Implementations§
source§impl BufferedRawReader for RawBinaryReader<Vec<u8>>
impl BufferedRawReader for RawBinaryReader<Vec<u8>>
source§fn append_bytes(&mut self, bytes: &[u8]) -> IonResult<()>
fn append_bytes(&mut self, bytes: &[u8]) -> IonResult<()>
Copies the provided bytes to end of the reader’s input buffer.
source§fn read_from<R: Read>(&mut self, source: R, length: usize) -> IonResult<usize>
fn read_from<R: Read>(&mut self, source: R, length: usize) -> IonResult<usize>
Tries to read length
bytes from source
. Unlike append_bytes,
this method does not do any copying. A slice of the reader’s buffer is handed to source
so it can be populated directly.
fn stream_complete(&mut self)
fn is_stream_complete(&self) -> bool
source§impl<A: Debug + AsRef<[u8]> + Expandable> Debug for RawBinaryReader<A>
impl<A: Debug + AsRef<[u8]> + Expandable> Debug for RawBinaryReader<A>
source§impl<A: AsRef<[u8]> + Expandable> IonReader for RawBinaryReader<A>
impl<A: AsRef<[u8]> + Expandable> IonReader for RawBinaryReader<A>
source§fn read_str(&mut self) -> IonResult<&str>
fn read_str(&mut self) -> IonResult<&str>
If the reader is currently positioned on a string, returns a &str containing its text.
§type Item = RawStreamItem
type Item = RawStreamItem
§type Symbol = RawSymbolToken
type Symbol = RawSymbolToken
source§fn ion_version(&self) -> (u8, u8)
fn ion_version(&self) -> (u8, u8)
source§fn next(&mut self) -> IonResult<Self::Item>
fn next(&mut self) -> IonResult<Self::Item>
source§fn current(&self) -> Self::Item
fn current(&self) -> Self::Item
source§fn ion_type(&self) -> Option<IonType>
fn ion_type(&self) -> Option<IonType>
source§fn annotations<'a>(
&'a self
) -> Box<dyn Iterator<Item = IonResult<Self::Symbol>> + 'a>
fn annotations<'a>( &'a self ) -> Box<dyn Iterator<Item = IonResult<Self::Symbol>> + 'a>
source§fn has_annotations(&self) -> bool
fn has_annotations(&self) -> bool
true
.
Otherwise, returns false
.source§fn field_name(&self) -> IonResult<Self::Symbol>
fn field_name(&self) -> IonResult<Self::Symbol>
Ok(_)
with a Self::Symbol
representing the field’s name; otherwise, returns an crate::IonError::IllegalOperation. Read moresource§fn is_null(&self) -> bool
fn is_null(&self) -> bool
true
if the reader is currently positioned over an Ion null of any type.source§fn read_null(&mut self) -> IonResult<IonType>
fn read_null(&mut self) -> IonResult<IonType>
source§fn read_bool(&mut self) -> IonResult<bool>
fn read_bool(&mut self) -> IonResult<bool>
source§fn read_i64(&mut self) -> IonResult<i64>
fn read_i64(&mut self) -> IonResult<i64>
i64
, or an IO
error is encountered while reading, returns crate::IonError.source§fn read_int(&mut self) -> IonResult<Int>
fn read_int(&mut self) -> IonResult<Int>
Int
. If the
current item is not an integer or an IO error is encountered while reading, returns
crate::IonError.source§fn read_f32(&mut self) -> IonResult<f32>
fn read_f32(&mut self) -> IonResult<f32>
source§fn read_f64(&mut self) -> IonResult<f64>
fn read_f64(&mut self) -> IonResult<f64>
source§fn read_decimal(&mut self) -> IonResult<Decimal>
fn read_decimal(&mut self) -> IonResult<Decimal>
source§fn read_string(&mut self) -> IonResult<Str>
fn read_string(&mut self) -> IonResult<Str>
source§fn read_symbol(&mut self) -> IonResult<Self::Symbol>
fn read_symbol(&mut self) -> IonResult<Self::Symbol>
source§fn read_blob(&mut self) -> IonResult<Blob>
fn read_blob(&mut self) -> IonResult<Blob>
Vec<u8>
. If the
current item is not a blob or an IO error is encountered while reading, returns crate::IonError.source§fn read_clob(&mut self) -> IonResult<Clob>
fn read_clob(&mut self) -> IonResult<Clob>
Vec<u8>
. If the
current item is not a clob or an IO error is encountered while reading, returns crate::IonError.source§fn read_timestamp(&mut self) -> IonResult<Timestamp>
fn read_timestamp(&mut self) -> IonResult<Timestamp>
source§fn step_in(&mut self) -> IonResult<()>
fn step_in(&mut self) -> IonResult<()>
source§fn step_out(&mut self) -> IonResult<()>
fn step_out(&mut self) -> IonResult<()>
source§fn parent_type(&self) -> Option<IonType>
fn parent_type(&self) -> Option<IonType>
None
. Otherwise, returns
Some(_)
with the parent container’s crate::IonType.source§fn depth(&self) -> usize
fn depth(&self) -> usize
0
.