[][src]Trait binjs::io::TokenWriter

pub trait TokenWriter {
    type Data: AsRef<[u8]>;
    fn done(self) -> Result<Self::Data, TokenWriterError>;
fn enter_tagged_tuple_at(
        &mut self,
        _node: &(dyn Node + 'static),
        _tag: &InterfaceName,
        _children: &[&FieldName],
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError>;
fn enter_list_at(
        &mut self,
        _len: usize,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError>;
fn string_at(
        &mut self,
        value: Option<&SharedString>,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError>;
fn string_enum_at(
        &mut self,
        value: &SharedString,
        path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError>;
fn float_at(
        &mut self,
        value: Option<f64>,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError>;
fn unsigned_long_at(
        &mut self,
        value: u32,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError>;
fn bool_at(
        &mut self,
        value: Option<bool>,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError>;
fn offset_at(
        &mut self,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError>; fn exit_tagged_tuple_at(
        &mut self,
        _node: &(dyn Node + 'static),
        _tag: &InterfaceName,
        _children: &[&FieldName],
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError> { ... }
fn exit_list_at(
        &mut self,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError> { ... }
fn property_key_at(
        &mut self,
        value: Option<&PropertyKey>,
        path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError> { ... }
fn identifier_name_at(
        &mut self,
        value: Option<&IdentifierName>,
        path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError> { ... }
fn enter_scoped_dictionary_at(
        &mut self,
        _name: &SharedString,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError> { ... }
fn exit_scoped_dictionary_at(
        &mut self,
        _name: &SharedString,
        _path: &Path<InterfaceName, (usize, FieldName)>
    ) -> Result<(), TokenWriterError> { ... } }

Build an in-memory representation of a BinTree.

Implementations may for instance introduce atoms, maximal sharing, etc.

All the reading methods offer a version suffixed with _at(..., path: &Path), which lets the writer 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).

Associated Types

type Data: AsRef<[u8]>

The type of data generated by this writer. Typically some variant of Vec<u8>.

Loading content...

Required methods

fn done(self) -> Result<Self::Data, TokenWriterError>

Finish writing, produce data.

fn enter_tagged_tuple_at(
    &mut self,
    _node: &(dyn Node + 'static),
    _tag: &InterfaceName,
    _children: &[&FieldName],
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<(), TokenWriterError>

Write a tagged tuple.

The number of items is specified by the grammar, so it MAY not be recorded by the TokenWriter.

By convention, a null tagged tuple is the special tagged tuple "null", with no children.

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

Write a list.

By opposition to a tuple, the number of items is variable and MUST be somehow recorded by the TokenWriter.

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

Write a single UTF-8 string.

If specified, the string MUST be UTF-8.

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

Write 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.

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

Write a single number.

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

Write a single u32.

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

Write single bool.

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

Write the number of bytes left in this tuple.

Loading content...

Provided methods

fn exit_tagged_tuple_at(
    &mut self,
    _node: &(dyn Node + 'static),
    _tag: &InterfaceName,
    _children: &[&FieldName],
    _path: &Path<InterfaceName, (usize, FieldName)>
) -> Result<(), TokenWriterError>

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

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

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

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

Signal that, from this point, writing 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 TokenWriter that do not support dictionary switching.

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

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

This method is called upon exiting a node labelled ScopedDictionary.

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

Loading content...

Implementors

impl TokenWriter for TreeTokenWriter[src]

type Data = Box<[u8]>

impl TokenWriter for DictionaryBuilder[src]

type Data = [u8; 0]

impl TokenWriter for Encoder[src]

type Data = Box<[u8]>

impl<'a> TokenWriter for &'a mut DictionaryBuilder[src]

type Data = [u8; 0]

impl<T> TokenWriter for TokenWriterTreeAdapter<T> where
    T: TokenWriterWithTree
[src]

type Data = <T as TokenWriterWithTree>::Data

Loading content...