[][src]Trait binjs::io::TokenReader

pub trait TokenReader: FileStructurePrinter {
    fn string_at(
        &mut self,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<Option<SharedString>, TokenReaderError>;
fn float_at(
        &mut self,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<Option<f64>, TokenReaderError>;
fn unsigned_long_at(
        &mut self,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<u32, TokenReaderError>;
fn bool_at(
        &mut self,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<Option<bool>, TokenReaderError>;
fn offset_at(
        &mut self,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<u32, TokenReaderError>;
fn enter_list_at(
        &mut self,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<u32, TokenReaderError>;
fn enter_tagged_tuple_at(
        &mut self,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(InterfaceName, Option<Rc<Box<[FieldName]>>>), TokenReaderError>; fn poison(&mut self) { ... }
fn string_enum_at(
        &mut self,
        path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<SharedString, TokenReaderError> { ... }
fn identifier_name_at(
        &mut self,
        path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<Option<IdentifierName>, TokenReaderError> { ... }
fn property_key_at(
        &mut self,
        path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<Option<PropertyKey>, TokenReaderError> { ... }
fn exit_list_at(
        &mut self,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenReaderError> { ... }
fn exit_tagged_tuple_at(
        &mut self,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenReaderError> { ... }
fn enter_scoped_dictionary_at(
        &mut self,
        _name: &SharedString,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenReaderError> { ... }
fn exit_scoped_dictionary_at(
        &mut self,
        _name: &SharedString,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenReaderError> { ... } }

An API for reading tokens.

Note that a TokenReader by itself cannot determine the nature of the following token. Rather, the driver of the TokenReader must be able to deduce the nature of the following token from what it has previously read.

All the reading methods offer a version suffixed with _at(path: &Path), which lets the reader determine what item we're reading in the AST. This may be used both for debugging purposes and for encodings that depend on the current position in the AST (e.g. entropy coding).

Required methods

fn string_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<Option<SharedString>, TokenReaderError>

Read a single UTF-8 string.

The returned string MUST be valid UTF-8.

fn float_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<Option<f64>, TokenReaderError>

Read a single f64. Note that all user-level numbers are f64.

fn unsigned_long_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<u32, TokenReaderError>

Read a single u32.

fn bool_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<Option<bool>, TokenReaderError>

Read a single bool.

fn offset_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<u32, TokenReaderError>

Read a single number of bytes.

fn enter_list_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<u32, TokenReaderError>

Start reading a list.

fn enter_tagged_tuple_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<(InterfaceName, Option<Rc<Box<[FieldName]>>>), TokenReaderError>

Start reading a tagged tuple. If the stream was encoded properly, the tag is attached to an ordered tuple of fields that may be extracted in order.

Loading content...

Provided methods

fn poison(&mut self)

Poison the reader, ensuring that it will never be used for reading again.

fn string_enum_at(
    &mut self,
    path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<SharedString, TokenReaderError>

Read a single UTF-8 value from a string enumeration.

The default implementation uses `self.string``, but some encodings may use the extra information e.g. to represent the enumeration by an index in the list of possible values, or to encode string enums as interfaces.

The returned string MUST be valid UTF-8.

fn identifier_name_at(
    &mut self,
    path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<Option<IdentifierName>, TokenReaderError>

Read a single identifier name.

The default implementation uses self.string_at, but some encodings may use the extra information e.g. to represent the identifier as a DeBruijn index.

fn property_key_at(
    &mut self,
    path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<Option<PropertyKey>, TokenReaderError>

Read a single property name.

The default implementation uses self.string_at, but some encodings may use the extra information e.g. to initialize dictionaries.

fn exit_list_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<(), TokenReaderError>

Finish reading a list.

fn exit_tagged_tuple_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<(), TokenReaderError>

Finish reading a tagged tuple.

fn enter_scoped_dictionary_at(
    &mut self,
    _name: &SharedString,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<(), TokenReaderError>

Signal that, from this point, reading is expected to use a specialized dictionary. Use of the specialized dictionary will stop at exit_scoped_dictionary_at.

This method is called during when visiting a node labelled ScopedDictionary, once the dictionary name has been decoded.

May be ignored by implementations of TokenReader that do not support dictionary switching.

fn exit_scoped_dictionary_at(
    &mut self,
    _name: &SharedString,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<(), TokenReaderError>

Signal that, from this point, reading is expected to return to the previous specialized dictionary.

This method is called during when leaving a node labelled ScopedDictionary.

May be ignored by implementations of TokenReader that do not support dictionary switching.

Loading content...

Implementors

impl TokenReader for binjs::io::entropy::read::Decoder[src]

impl TokenReader for binjs::io::multipart::TreeTokenReader[src]

fn float_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<Option<f64>, TokenReaderError>
[src]

Read a single f64. Note that all numbers are f64.

fn unsigned_long_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<u32, TokenReaderError>
[src]

Read a single u32.

fn bool_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<Option<bool>, TokenReaderError>
[src]

Read a single bool.

fn offset_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<u32, TokenReaderError>
[src]

Read a single u32.

fn enter_list_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<u32, TokenReaderError>
[src]

Start reading a list.

Returns an extractor for that list and the number of elements in the list. Before dropping the sub-extractor, callers MUST either reach the end of the list or call skip().

fn enter_tagged_tuple_at(
    &mut self,
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<(InterfaceName, Option<Rc<Box<[FieldName]>>>), TokenReaderError>
[src]

Start reading a tagged tuple.

Returns the tag name, None for fields and a sub-extractor dedicated to that tuple. The sub-extractor MUST be consumed entirely.

impl<R> TokenReader for binjs::io::binjs_json::read::Decoder<R> where
    R: Read
[src]

impl<R> TokenReader for binjs::io::simple::TreeTokenReader<R> where
    R: Read + Seek
[src]

Loading content...