codec

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2021 License: MIT Imports: 5 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(n ipld.Node, sink shared.TokenSink) error

Marshal provides a very general node-to-tokens marshalling feature. It can handle either cbor or json by being combined with a refmt TokenSink.

It is valid for all the data model types except links, which are only supported if the nodes are typed and provide additional information to clarify how links should be encoded through their type info. (The dag-cbor and dag-json formats can be used if links are of CID implementation and need to be encoded in a schemafree way.)

func Unmarshal

func Unmarshal(na ipld.NodeAssembler, tokSrc shared.TokenSource) error

Unmarshal provides a very general tokens-to-node unmarshalling feature. It can handle either cbor or json by being combined with a refmt TokenSink.

The unmarshalled data is fed to the given NodeAssembler, which accumulates it; at the end, any error is returned from the Unmarshal method, and the user can pick up the finished Node from wherever their assembler has it. Typical usage might look like the following:

nb := basicnode.Prototype__Any{}.NewBuilder()
err := codec.Unmarshal(nb, json.Decoder(reader))
n := nb.Build()

It is valid for all the data model types except links, which are only supported if the nodes are typed and provide additional information to clarify how links should be decoded through their type info. (The dag-cbor and dag-json formats can be used if links are of CID implementation and need to be decoded in a schemafree way.)

Types

type Decoder added in v0.6.0

type Decoder = ipld.Decoder

Decoder is defined in the root ipld package; this alias is just for documentation and discoverability.

Most of the documentation for Encoder also applies wholesale to the Decoder interface.

type Encoder added in v0.6.0

type Encoder = ipld.Encoder

Encoder is defined in the root ipld package; this alias is just for documentation and discoverability.

Encoder functions can be composed into an ipld.LinkSystem to provide a "one stop shop" API for handling content addressable storage. Encoder functions can also be used directly if you want to handle serial data streams.

Most codec packages will have a ReusableEncoder type (which contains any working memory needed by the encoder implementation, as well as any configuration options), and that type will have an Encode function matching this interface.

By convention, codec packages that have a multicodec contract will also have a package-scope exported function called Encode which also matches this interface, and is the equivalent of creating a zero-value ReusableEncoder (aka, default config) and using its Encode method. This package-scope function will typically also internally use a sync.Pool to keep some ReusableEncoder values on hand to avoid unnecesary allocations.

Note that a ReusableEncoder type that supports configuration options does not functionally expose those options when invoked by the multicodec system -- multicodec indicators do not provide room for extended configuration info. Codecs that expose configuration options are doing so for library users to enjoy; it does not mean those non-default configurations will necessarly be available in all scenarios that use codecs indirectly. There is also no standard interface for such configurations: by nature, if they exist at all, they vary per codec.

type ErrBudgetExhausted added in v0.6.0

type ErrBudgetExhausted struct{}

func (ErrBudgetExhausted) Error added in v0.6.0

func (e ErrBudgetExhausted) Error() string

Directories

Path Synopsis
The dagcbor package provides a DAG-CBOR codec implementation.
The dagcbor package provides a DAG-CBOR codec implementation.
Several groups of exported symbols are available at different levels of abstraction: - You might just want the multicodec registration! Then never deal with this package directly again.
Several groups of exported symbols are available at different levels of abstraction: - You might just want the multicodec registration! Then never deal with this package directly again.
jst
"jst" -- JSON Table -- is a format that's parsable as JSON, while sprucing up the display to humans using the non-significant whitespace cleverly.
"jst" -- JSON Table -- is a format that's parsable as JSON, while sprucing up the display to humans using the non-significant whitespace cleverly.
Package raw implements IPLD's raw codec, which simply writes and reads a Node which can be represented as bytes.
Package raw implements IPLD's raw codec, which simply writes and reads a Node which can be represented as bytes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL