pub struct ObjectCodec { /* private fields */ }Expand description
Codec for encoding/decoding LinoValue to/from Links Notation.
This codec handles the conversion between LinoValue and Links Notation
format strings. It supports circular references and shared object identity
through object ID references.
Implementations§
Source§impl ObjectCodec
impl ObjectCodec
Sourcepub fn encode(&mut self, value: &LinoValue) -> String
pub fn encode(&mut self, value: &LinoValue) -> String
Encode a LinoValue to the readable, indented Links Notation format.
This is the default representation: keys and values are written as plain
text, one per line, so the result can be read and reviewed directly.
See readable for the exact shape.
§Arguments
value- The value to encode
§Returns
A string in readable Links Notation format
Sourcepub fn encode_with_indent(&mut self, value: &LinoValue, indent: &str) -> String
pub fn encode_with_indent(&mut self, value: &LinoValue, indent: &str) -> String
Encode a LinoValue to the readable format using a custom indentation string.
§Arguments
value- The value to encodeindent- The indentation string used per nesting level (for example" ")
Sourcepub fn encode_line(&mut self, value: &LinoValue) -> String
pub fn encode_line(&mut self, value: &LinoValue) -> String
Encode a LinoValue to the readable, single-line Links Notation format.
The document is written as plain text on one line, so one value is one
line of an append-only log: appending is a single write, grep, tail -f
and wc -l keep working, and a compactor can cut at any newline without
splitting a record. See readable for the exact shape.
§Arguments
value- The value to encode
§Returns
A string in readable Links Notation format, containing no newline
Sourcepub fn encode_compact(&mut self, value: &LinoValue) -> String
pub fn encode_compact(&mut self, value: &LinoValue) -> String
Encode a LinoValue to the compact, single-line Links Notation format.
Every value is tagged with its type and every string is base64-encoded, so the whole document fits on one line and carries no readable text. This was the default before the readable format; callers now opt into it explicitly.
§Arguments
value- The value to encode
§Returns
A string in compact Links Notation format
Sourcepub fn encode_obfuscated(&mut self, value: &LinoValue) -> String
pub fn encode_obfuscated(&mut self, value: &LinoValue) -> String
Encode a LinoValue to the compact, base64 form.
Alias of ObjectCodec::encode_compact, named after what the form does to
its content: nothing in the output can be read without decoding it.
Sourcepub fn decode_line(&mut self, notation: &str) -> Result<LinoValue, CodecError>
pub fn decode_line(&mut self, notation: &str) -> Result<LinoValue, CodecError>
Decode the readable, single-line Links Notation format.
This is the exact inverse of ObjectCodec::encode_line. A document
spanning more than one line is rejected, so a reader that hands over one
record at a time cannot silently merge two records into one value.
§Arguments
notation- One line in readable Links Notation format
§Returns
The reconstructed value, or an error