Skip to main content

Crate lino_objects_codec

Crate lino_objects_codec 

Source
Expand description

Object encoder/decoder for Links Notation format.

This library provides encoding and decoding of JSON-like objects to/from Links Notation format. It supports all common JSON types plus special float values (NaN, Infinity, -Infinity).

§Features

  • Readable by Default: encode() writes plain, indented text that can be read and reviewed
  • Universal Serialization: Encode objects to Links Notation format
  • Type Support: Handle all common types: null, boolean, integer, float, string, array, object
  • Special Float Values: Support for NaN, Infinity, -Infinity (which are not valid JSON)
  • Circular References: Detect and preserve circular references (via object IDs)
  • Object Identity: Maintain object identity for shared references
  • UTF-8 Support: Full Unicode string support, always written as text – a string is never base64-encoded, so every word of it stays greppable. A character the chosen form cannot hold (a carriage return in either form, a newline on a single line) is percent-escaped, and only that one value is marked, as (escaped "line one%0Aline two")
  • Simple API: Easy-to-use encode() and decode() functions

§Example

use lino_objects_codec::{encode, decode, LinoValue};

// Encode a simple object
let data = LinoValue::object([
    ("name", LinoValue::String("Alice".to_string())),
    ("age", LinoValue::Int(30)),
    ("active", LinoValue::Bool(true)),
]);
let encoded = encode(&data);
assert_eq!(encoded, "(\n  name \"Alice\"\n  age 30\n  active true\n)");
let decoded = decode(&encoded).unwrap();
assert_eq!(decoded, data);

§Output formats

FunctionOutput
encodereadable, indented plain text (default)
encode_with_indentthe same, with a custom indentation string
encode_linereadable plain text on a single line, one record per line
encode_compact / encode_obfuscatedthe previous single-line, base64 form

decode accepts all of them, so files written by earlier versions keep working and migrate to the readable form on the next write. decode_line is the exact inverse of encode_line and reads one record at a time.

Re-exports§

pub use readable::BASE64_MARKER;
pub use readable::DEFAULT_INDENT;
pub use readable::ESCAPED_MARKER;
pub use readable::OBJECT_MARKER;

Modules§

debug
Opt-in tracing for the codec.
format
Formatting utilities for indented Links Notation format. Formatting utilities for indented Links Notation and individual values.
readable
Readable, indented Links Notation representation.

Structs§

ObjectCodec
Codec for encoding/decoding LinoValue to/from Links Notation.

Enums§

CodecError
Error types for codec operations
LinoValue
A value that can be encoded/decoded using the Links Notation codec.

Functions§

decode
Decode Links Notation format to a value.
decode_line
Decode one line of readable Links Notation back into a value.
encode
Encode a value to the readable, indented Links Notation format.
encode_compact
Encode a value to the compact, single-line Links Notation format.
encode_line
Encode a value to the readable, single-line Links Notation format.
encode_obfuscated
Encode a value to the compact, base64 form.
encode_with_indent
Encode a value to the readable format using a custom indentation string.