pub struct Decoder<'a> { /* private fields */ }Expand description
A decoder for a twine blob.
Implementations§
Source§impl<'a> Decoder<'a>
impl<'a> Decoder<'a>
Sourcepub fn deref(&self, off: Offset) -> Result<Offset>
pub fn deref(&self, off: Offset) -> Result<Offset>
Dereference the offset.
If the value at this offset is a pointer, follow the pointer; repeat until it’s not. This is done implicitly by most other functions in this module, but it can be useful to do it by hand in case there is caching done on decoding (eg. to memoize the value decoded at a particular offset, it’s better to dereference the offset first).
Sourcepub fn get_shallow_value(&self, off: Offset) -> Result<ShallowValue<'a>>
pub fn get_shallow_value(&self, off: Offset) -> Result<ShallowValue<'a>>
Read one value at the given offset.
This does not recurse into subvalues, so it is fairly fast. The main way of
deserializing from twine is through this function.
If the value at off is a pointer, it is implicitly followed.
As a consequence, this never returns a Immediate::Pointer value.
pub fn get_bool(&self, off: Offset) -> Result<bool>
pub fn get_null(&self, off: Offset) -> Result<()>
pub fn get_float(&self, off: Offset) -> Result<f64>
pub fn get_str(&self, off: Offset) -> Result<&'a str>
pub fn get_bytes(&self, off: Offset) -> Result<&'a [u8]>
Sourcepub fn get_array(&self, off: Offset, res: &mut Vec<Offset>) -> Result<()>
pub fn get_array(&self, off: Offset, res: &mut Vec<Offset>) -> Result<()>
Read an array of offsets into res
Sourcepub fn get_dict(
&self,
off: Offset,
res: &mut Vec<(Offset, Offset)>,
) -> Result<()>
pub fn get_dict( &self, off: Offset, res: &mut Vec<(Offset, Offset)>, ) -> Result<()>
Read a dictionary of offsets into res.
res is cleared before reading.
Sourcepub fn get_tag(&self, off: Offset) -> Result<(Tag, Offset)>
pub fn get_tag(&self, off: Offset) -> Result<(Tag, Offset)>
Read a tagged value.
The value itself is not read, only an offset to it is returned.
Sourcepub fn get_variant(
&self,
off: Offset,
args: &mut Vec<Offset>,
) -> Result<VariantIdx>
pub fn get_variant( &self, off: Offset, args: &mut Vec<Offset>, ) -> Result<VariantIdx>
Read a variant value. The variant index is returned,
and (the offsets of the) arguments are pushed into args.
args is cleared first.
Sourcepub fn entrypoint(&self) -> Result<Offset>
pub fn entrypoint(&self) -> Result<Offset>
Find the entrypoint.
A twine blob is terminated with a postfix (in essence, a pointer to the actual toplevel value). This reads the postfix and returns the offset of the toplevel value.