[−][src]Trait binjs_io::io::TokenReader
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
) -> Result<Option<SharedString>, TokenReaderError>
&mut self,
_path: &Path
) -> 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) -> Result<Option<f64>, TokenReaderError>
Read a single f64
. Note that all user-level numbers are f64
.
fn unsigned_long_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
Read a single u32
.
fn bool_at(&mut self, _path: &Path) -> Result<Option<bool>, TokenReaderError>
Read a single bool
.
fn offset_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
Read a single number of bytes.
fn enter_list_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
Start reading a list.
fn enter_tagged_tuple_at(
&mut self,
_path: &Path
) -> Result<(InterfaceName, Option<Rc<Box<[FieldName]>>>), TokenReaderError>
&mut self,
_path: &Path
) -> 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.
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
) -> Result<SharedString, TokenReaderError>
&mut self,
path: &Path
) -> 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
) -> Result<Option<IdentifierName>, TokenReaderError>
&mut self,
path: &Path
) -> 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
) -> Result<Option<PropertyKey>, TokenReaderError>
&mut self,
path: &Path
) -> 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) -> Result<(), TokenReaderError>
Finish reading a list.
fn exit_tagged_tuple_at(&mut self, _path: &Path) -> Result<(), TokenReaderError>
Finish reading a tagged tuple.
fn enter_scoped_dictionary_at(
&mut self,
_name: &SharedString,
_path: &Path
) -> Result<(), TokenReaderError>
&mut self,
_name: &SharedString,
_path: &Path
) -> 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
) -> Result<(), TokenReaderError>
&mut self,
_name: &SharedString,
_path: &Path
) -> 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.
Implementors
impl TokenReader for binjs_io::entropy::read::Decoder
[src]
fn bool_at(&mut self, path: &Path) -> Result<Option<bool>, TokenReaderError>
[src]
fn string_enum_at(
&mut self,
path: &Path
) -> Result<SharedString, TokenReaderError>
[src]
&mut self,
path: &Path
) -> Result<SharedString, TokenReaderError>
fn enter_tagged_tuple_at(
&mut self,
path: &Path
) -> Result<(InterfaceName, Option<Rc<Box<[FieldName]>>>), TokenReaderError>
[src]
&mut self,
path: &Path
) -> Result<(InterfaceName, Option<Rc<Box<[FieldName]>>>), TokenReaderError>
fn float_at(&mut self, _path: &Path) -> Result<Option<f64>, TokenReaderError>
[src]
fn string_at(
&mut self,
_path: &Path
) -> Result<Option<SharedString>, TokenReaderError>
[src]
&mut self,
_path: &Path
) -> Result<Option<SharedString>, TokenReaderError>
fn identifier_name_at(
&mut self,
_path: &Path
) -> Result<Option<IdentifierName>, TokenReaderError>
[src]
&mut self,
_path: &Path
) -> Result<Option<IdentifierName>, TokenReaderError>
fn property_key_at(
&mut self,
_path: &Path
) -> Result<Option<PropertyKey>, TokenReaderError>
[src]
&mut self,
_path: &Path
) -> Result<Option<PropertyKey>, TokenReaderError>
fn unsigned_long_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
[src]
fn enter_list_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
[src]
fn enter_scoped_dictionary_at(
&mut self,
name: &SharedString,
_path: &Path
) -> Result<(), TokenReaderError>
[src]
&mut self,
name: &SharedString,
_path: &Path
) -> Result<(), TokenReaderError>
fn exit_scoped_dictionary_at(
&mut self,
name: &SharedString,
_path: &Path
) -> Result<(), TokenReaderError>
[src]
&mut self,
name: &SharedString,
_path: &Path
) -> Result<(), TokenReaderError>
fn offset_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
[src]
impl TokenReader for binjs_io::multipart::TreeTokenReader
[src]
fn poison(&mut self)
[src]
fn string_at(
&mut self,
_path: &Path
) -> Result<Option<SharedString>, TokenReaderError>
[src]
&mut self,
_path: &Path
) -> Result<Option<SharedString>, TokenReaderError>
fn float_at(&mut self, _path: &Path) -> Result<Option<f64>, TokenReaderError>
[src]
Read a single f64
. Note that all numbers are f64
.
fn unsigned_long_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
[src]
Read a single u32
.
fn bool_at(&mut self, _path: &Path) -> Result<Option<bool>, TokenReaderError>
[src]
Read a single bool
.
fn offset_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
[src]
Read a single u32
.
fn enter_list_at(&mut self, _path: &Path) -> 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
) -> Result<(InterfaceName, Option<Rc<Box<[FieldName]>>>), TokenReaderError>
[src]
&mut self,
_path: &Path
) -> Result<(InterfaceName, Option<Rc<Box<[FieldName]>>>), TokenReaderError>
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::simple::TreeTokenReader<R> where
R: Read + Seek,
[src]
R: Read + Seek,
fn poison(&mut self)
[src]
fn bool_at(&mut self, _path: &Path) -> Result<Option<bool>, TokenReaderError>
[src]
fn offset_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
[src]
fn float_at(&mut self, _path: &Path) -> Result<Option<f64>, TokenReaderError>
[src]
fn unsigned_long_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
[src]
fn string_at(
&mut self,
_path: &Path
) -> Result<Option<SharedString>, TokenReaderError>
[src]
&mut self,
_path: &Path
) -> Result<Option<SharedString>, TokenReaderError>
fn enter_list_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
[src]
fn exit_list_at(&mut self, _path: &Path) -> Result<(), TokenReaderError>
[src]
fn enter_tagged_tuple_at(
&mut self,
_path: &Path
) -> Result<(InterfaceName, Option<Rc<Box<[FieldName]>>>), TokenReaderError>
[src]
&mut self,
_path: &Path
) -> Result<(InterfaceName, Option<Rc<Box<[FieldName]>>>), TokenReaderError>
fn exit_tagged_tuple_at(&mut self, _path: &Path) -> Result<(), TokenReaderError>
[src]
impl<R: Read> TokenReader for binjs_io::binjs_json::read::Decoder<R>
[src]
fn string_at(
&mut self,
_path: &Path
) -> Result<Option<SharedString>, TokenReaderError>
[src]
&mut self,
_path: &Path
) -> Result<Option<SharedString>, TokenReaderError>
fn string_enum_at(
&mut self,
_path: &Path
) -> Result<SharedString, TokenReaderError>
[src]
&mut self,
_path: &Path
) -> Result<SharedString, TokenReaderError>
fn identifier_name_at(
&mut self,
_path: &Path
) -> Result<Option<IdentifierName>, TokenReaderError>
[src]
&mut self,
_path: &Path
) -> Result<Option<IdentifierName>, TokenReaderError>
fn property_key_at(
&mut self,
_path: &Path
) -> Result<Option<PropertyKey>, TokenReaderError>
[src]
&mut self,
_path: &Path
) -> Result<Option<PropertyKey>, TokenReaderError>
fn float_at(&mut self, _path: &Path) -> Result<Option<f64>, TokenReaderError>
[src]
fn unsigned_long_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
[src]
fn bool_at(&mut self, _path: &Path) -> Result<Option<bool>, TokenReaderError>
[src]
fn offset_at(&mut self, __path: &Path) -> Result<u32, TokenReaderError>
[src]
fn enter_list_at(&mut self, _path: &Path) -> Result<u32, TokenReaderError>
[src]
fn exit_list_at(&mut self, _path: &Path) -> Result<(), TokenReaderError>
[src]
fn enter_tagged_tuple_at(
&mut self,
_path: &Path
) -> Result<(InterfaceName, Option<Rc<Box<[FieldName]>>>), TokenReaderError>
[src]
&mut self,
_path: &Path
) -> Result<(InterfaceName, Option<Rc<Box<[FieldName]>>>), TokenReaderError>