Trait ion_rs::data_source::IonDataSource[][src]

pub trait IonDataSource: BufRead {
    fn skip_bytes(&mut self, number_of_bytes: usize) -> IonResult<()>;
fn next_byte(&mut self) -> IonResult<Option<u8>>;
fn read_next_byte_while<F>(
        &mut self,
        byte_processor: &mut F
    ) -> IonResult<usize>
    where
        F: FnMut(u8) -> bool
;
fn read_slice<T, F>(
        &mut self,
        length: usize,
        fallback_buffer: &mut Vec<u8>,
        slice_processor: F
    ) -> IonResult<T>
    where
        F: FnOnce(&[u8]) -> IonResult<T>
; }

Optimized read operations for parsing Ion.

The binary Ion spec calls for a number of reading patterns, including:

  • Type descriptor octets (value headers) require that a single byte be read from input.
  • Variable length integers (both signed and unsigned) require that a single byte at a time be read from the data source until some condition is met.
  • Fixed length values require that n bytes be read from the data source and interpreted as a single value.
  • Skipping over values, partial or whole, requires that the next n bytes of the data source be ignored altogether.

The IonDataSource trait extends functionality offered by the BufRead trait by providing methods that are tailored to these use cases. They have been optimized to prefer operating on data that’s already in the input buffer in-place rather than copying it out to another byte array.

Required methods

fn skip_bytes(&mut self, number_of_bytes: usize) -> IonResult<()>[src]

Ignore the next number_of_bytes bytes in the data source.

fn next_byte(&mut self) -> IonResult<Option<u8>>[src]

Returns the next byte in the data source if available.

fn read_next_byte_while<F>(
    &mut self,
    byte_processor: &mut F
) -> IonResult<usize> where
    F: FnMut(u8) -> bool
[src]

Calls byte_processor on each byte in the data source until it returns false. Returns the number of bytes that were read and processed.

fn read_slice<T, F>(
    &mut self,
    length: usize,
    fallback_buffer: &mut Vec<u8>,
    slice_processor: F
) -> IonResult<T> where
    F: FnOnce(&[u8]) -> IonResult<T>, 
[src]

Calls slice_processor on a slice containing the next length bytes from the data source. If the required bytes are already in the input buffer, a reference to that slice of the input buffer will be used. If they are not, the required bytes will be read into fallback_buffer and that will be used instead. If fallback_buffer does not have enough capacity to store the requested data, it will be resized. It will never be shrunk, however–it is the caller’s responsibility to manage this memory.

Loading content...

Implementors

impl<T: BufRead> IonDataSource for T[src]

fn skip_bytes(&mut self, number_of_bytes: usize) -> IonResult<()>[src]

fn next_byte(&mut self) -> IonResult<Option<u8>>[src]

fn read_next_byte_while<F>(
    &mut self,
    byte_processor: &mut F
) -> IonResult<usize> where
    F: FnMut(u8) -> bool
[src]

fn read_slice<V, F>(
    &mut self,
    number_of_bytes: usize,
    fallback_buffer: &mut Vec<u8>,
    slice_processor: F
) -> IonResult<V> where
    F: FnOnce(&[u8]) -> IonResult<V>, 
[src]

Loading content...