[][src]Trait binjs_io::io::TokenWriterWithTree

pub trait TokenWriterWithTree {
    type Tree;
    type Data: AsRef<[u8]>;
    fn done(self) -> Result<Self::Data, TokenWriterError>;
fn tagged_tuple(
        &mut self,
        _tag: &InterfaceName,
        _children: &[(&FieldName, Self::Tree)]
    ) -> Result<Self::Tree, TokenWriterError>;
fn list(
        &mut self,
        _: Vec<Self::Tree>
    ) -> Result<Self::Tree, TokenWriterError>; fn string(
        &mut self,
        _: Option<&SharedString>
    ) -> Result<Self::Tree, TokenWriterError> { ... }
fn string_enum(
        &mut self,
        str: &SharedString
    ) -> Result<Self::Tree, TokenWriterError> { ... }
fn float(&mut self, _: Option<f64>) -> Result<Self::Tree, TokenWriterError> { ... }
fn unsigned_long(&mut self, _: u32) -> Result<Self::Tree, TokenWriterError> { ... }
fn bool(&mut self, _: Option<bool>) -> Result<Self::Tree, TokenWriterError> { ... }
fn offset(&mut self) -> Result<Self::Tree, TokenWriterError> { ... }
fn property_key(
        &mut self,
        value: Option<&PropertyKey>
    ) -> Result<Self::Tree, TokenWriterError> { ... }
fn identifier_name(
        &mut self,
        value: Option<&IdentifierName>
    ) -> Result<Self::Tree, TokenWriterError> { ... } }

Associated Types

type Tree

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 tagged_tuple(
    &mut self,
    _tag: &InterfaceName,
    _children: &[(&FieldName, Self::Tree)]
) -> Result<Self::Tree, 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 list(&mut self, _: Vec<Self::Tree>) -> Result<Self::Tree, TokenWriterError>

Write a list.

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

Loading content...

Provided methods

fn string(
    &mut self,
    _: Option<&SharedString>
) -> Result<Self::Tree, TokenWriterError>

Write a single UTF-8 string.

If specified, the string MUST be UTF-8.

fn string_enum(
    &mut self,
    str: &SharedString
) -> Result<Self::Tree, 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(&mut self, _: Option<f64>) -> Result<Self::Tree, TokenWriterError>

Write a single number.

fn unsigned_long(&mut self, _: u32) -> Result<Self::Tree, TokenWriterError>

Write a single u32.

fn bool(&mut self, _: Option<bool>) -> Result<Self::Tree, TokenWriterError>

Write single bool.

fn offset(&mut self) -> Result<Self::Tree, TokenWriterError>

Write the number of bytes left in this tuple.

fn property_key(
    &mut self,
    value: Option<&PropertyKey>
) -> Result<Self::Tree, TokenWriterError>

fn identifier_name(
    &mut self,
    value: Option<&IdentifierName>
) -> Result<Self::Tree, TokenWriterError>

Loading content...

Implementors

impl TokenWriterWithTree for binjs_io::multipart::TreeTokenWriter[src]

type Tree = Tree

type Data = Box<[u8]>

impl TokenWriterWithTree for binjs_io::simple::TreeTokenWriter[src]

type Tree = AbstractTree

type Data = Box<[u8]>

fn list(
    &mut self,
    items: Vec<Self::Tree>
) -> Result<Self::Tree, TokenWriterError>
[src]

Lists are represented as:

  • ""
  • number of items (u32);
  • items
  • ""

The number of bytes is the total size of

  • number of items;
  • items.

fn tagged_tuple(
    &mut self,
    tag: &InterfaceName,
    children: &[(&FieldName, Self::Tree)]
) -> Result<Self::Tree, TokenWriterError>
[src]

For this example, we use a very, very, very suboptimal encoding.

  • - kind (string, \0 terminated) - number of items (varnum) - field names (string, \0 terminated)
  • contents

impl TokenWriterWithTree for Encoder[src]

type Tree = Rc<SubTree>

type Data = Box<[u8]>

Loading content...