Expand description
Dependency-free multi-format codec engine.
NextJson serializes and deserializes values through the format-neutral
crate::ser::FormatEncoder and crate::de::FormatDecoder
contracts. The same NsonSerialize / NsonDeserialize implementation can
be used with each codec whose documented wire model can represent the
value. Most encoders emit events directly; document-oriented codecs may
collect a Value before producing bytes.
§Registry
- Text, self-describing:
json,json5,hjson,yaml,toml,ron,sexpr,csv,urlform. - Binary, self-describing:
cbor,msgpack,bson,bencode,pickle. - Binary, schema-light:
postcard. - Environment:
envy(deserialization from process environment).
The Format trait carries the name, MIME type, file extensions and the
generic encode / decode entry points, so formats are first-class
values that can be passed around, stored in the all registry, or
selected by detect.
§Unified typed API
use nextjson::formats;
let value = ("NextJson", vec![1_u64, 2, 3], true);
let json = formats::encode_with(&value, formats::Json)?;
let msgpack = formats::encode_with(&value, formats::MsgPack)?;
let yaml = formats::encode_with(&value, formats::Yaml)?;
let back: (String, Vec<u64>, bool) = formats::decode_with(&json, formats::Json)?;
let back_mp: (String, Vec<u64>, bool) =
formats::decode_with(&msgpack, formats::MsgPack)?;
let back_yaml: (String, Vec<u64>, bool) =
formats::decode_with(&yaml, formats::Yaml)?;
assert_eq!(back, back_mp);
assert_eq!(back, back_yaml);§Format-to-format transcoding
transcode converts between compatible formats without a typed value:
use nextjson::formats;
let json = br#"{"name":"NextJson","values":[1,2,3]}"#;
let msgpack = formats::transcode(json, formats::Json, formats::MsgPack)?;
let json2 = formats::transcode(&msgpack, formats::MsgPack, formats::Json)?;
assert_eq!(json2, json);Modules§
- bin
- Shared primitives for the binary codecs.
Structs§
- Bencode
- Bencode format marker.
- Bencode
Decoder - Streaming bencode decoder.
- Bencode
Encoder - Streaming bencode encoder.
- Bson
- BSON format marker.
- Bson
Decoder - Streaming BSON decoder.
- Bson
Encoder - Streaming BSON encoder.
- Cbor
- CBOR format marker.
- Csv
- CSV format marker.
- CsvDecoder
- Streaming CSV decoder over pre-parsed rows.
- CsvEncoder
- Streaming CSV encoder.
- Envy
- Envy format marker (deserialization from
std::env). - Format
Info - Metadata for one registered format.
- Hjson
- Hjson format marker.
- Hjson
Decoder - Streaming Hjson decoder.
- Json
- JSON format marker.
- Json5
- JSON5 format marker.
- Json5
Decoder - Streaming JSON5 decoder.
- MsgPack
- MessagePack format marker.
- MsgPack
Decoder - Streaming MessagePack decoder.
- MsgPack
Encoder - Streaming MessagePack encoder.
- Pickle
- Pickle format marker.
- Pickle
Encoder - Streaming pickle (protocol 2) encoder.
- Postcard
- Postcard format marker.
- Postcard
Decoder - Streaming Postcard decoder.
- Postcard
Encoder - Streaming Postcard encoder.
- Ron
- RON format marker.
- RonDecoder
- Streaming RON decoder.
- RonEncoder
- Streaming RON encoder.
- Sexpr
- S-expression format marker.
- Sexpr
Decoder - Streaming S-expression decoder.
- Sexpr
Encoder - Streaming S-expression encoder.
- Toml
- TOML format marker.
- Toml
Encoder - TOML encoder that collects one event stream and emits it on
finish. - Tree
Decoder - A
FormatDecoderthat replays an owned token stream produced from aValuetree. - UrlForm
- URL form-encoding format marker.
- UrlForm
Decoder - Streaming URL-form decoder.
- UrlForm
Encoder - Streaming URL-form encoder (flat key/value map only).
- Yaml
- YAML format marker.
- Yaml
Encoder - YAML encoder that collects one event stream and emits it on
finish.
Enums§
- Format
Kind - Discriminant for every format registered in
all.
Traits§
- Format
- A registered data format with generic typed entry points.
Functions§
- all
- All registered formats.
- by_
extension - Look up a format by file extension (with or without a leading dot).
- by_name
- Look up a format by canonical name (case-insensitive).
- decode_
with - Deserialize a value with an explicit format.
- detect
- Sniff the most likely format from a byte prefix.
- encode_
with - Serialize a value with an explicit format.
- to_
value - Decode one format’s bytes into a
Value. - transcode
- Convert between any two formats without a typed value.
Type Aliases§
- Cbor
Decoder - CBOR decoder serving the unified interface over a JSON relay.
- Cbor
Encoder - The CBOR encoder writes through the JSON relay.
- Envy
Decoder - Envy decoder serving the unified interface from a parsed
Value. - Hjson
Encoder - The Hjson encoder is the standard JSON encoder (Hjson is a superset).
- Json5
Encoder - The JSON5 encoder is the standard JSON encoder (JSON5 is a superset).
- Json
Decoder - JSON decoder serving the unified interface (the native
Decoder, which already implementscrate::de::FormatDecoder). - Json
Encoder - The JSON encoder is the native buffered encoder.
- Pickle
Decoder - Pickle decoder that serves the unified interface from a parsed
Value. - Toml
Decoder - TOML decoder serving the unified interface from a parsed
Value. - Yaml
Decoder - YAML decoder serving the unified interface from a parsed
Value.