dagjson

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 12 Imported by: 108

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode added in v0.9.0

func Decode(na datamodel.NodeAssembler, r io.Reader) error

Decode deserializes data from the given io.Reader and feeds it into the given datamodel.NodeAssembler. Decode fits the codec.Decoder function interface.

A similar function is available on DecodeOptions type if you would like to customize any of the decoding details. This function uses the defaults for the dag-json codec (meaning: links are decoded, and bytes are decoded).

This is the function that will be registered in the default multicodec registry during package init time.

func Encode added in v0.9.0

func Encode(n datamodel.Node, w io.Writer) error

Encode walks the given datamodel.Node and serializes it to the given io.Writer. Encode fits the codec.Encoder function interface.

A similar function is available on EncodeOptions type if you would like to customize any of the encoding details. This function uses the defaults for the dag-json codec (meaning: links are encoded, bytes are encoded, and map keys are sorted during encode).

This is the function that will be registered in the default multicodec registry during package init time.

func Marshal

func Marshal(n datamodel.Node, sink shared.TokenSink, options EncodeOptions) error

Marshal is a deprecated function. Please consider switching to EncodeOptions.Encode instead.

func Unmarshal

func Unmarshal(na datamodel.NodeAssembler, tokSrc shared.TokenSource, options DecodeOptions) error

Unmarshal is a deprecated function. Please consider switching to DecodeOptions.Decode instead.

Types

type DecodeOptions added in v0.11.0

type DecodeOptions struct {
	// If true, parse DAG-JSON `{"/":"cid string"}` as a Link kind node rather
	// than a plain map
	ParseLinks bool

	// If true, parse DAG-JSON `{"/":{"bytes":"base64 bytes..."}}` as a Bytes kind
	// node rather than nested plain maps
	ParseBytes bool

	// If true, the decoder stops reading from the stream at the end of the JSON structure.
	// i.e. it does not slurp remaining whitespaces and EOF.
	// As per standard IPLD behavior, the parser considers the entire block to be
	// part of the JSON structure and will error if there is extraneous
	// non-whitespace data.
	DontParseBeyondEnd bool
}

DecodeOptions can be used to customize the behavior of a decoding function. The Decode method on this struct fits the codec.Decoder function interface.

func (DecodeOptions) Decode added in v0.11.0

func (cfg DecodeOptions) Decode(na datamodel.NodeAssembler, r io.Reader) error

Decode deserializes data from the given io.Reader and feeds it into the given datamodel.NodeAssembler. Decode fits the codec.Decoder function interface.

The behavior of the decoder can be customized by setting fields in the DecodeOptions struct before calling this method.

type EncodeOptions added in v0.11.0

type EncodeOptions struct {
	// If true, will encode nodes with a Link kind using the DAG-JSON
	// `{"/":"cid string"}` form.
	EncodeLinks bool

	// If true, will encode nodes with a Bytes kind using the DAG-JSON
	// `{"/":{"bytes":"base64 bytes..."}}` form.
	EncodeBytes bool

	// Control the sorting of map keys, using one of the `codec.MapSortMode_*` constants.
	MapSortMode codec.MapSortMode
}

EncodeOptions can be used to customize the behavior of an encoding function. The Encode method on this struct fits the codec.Encoder function interface.

func (EncodeOptions) Encode added in v0.11.0

func (cfg EncodeOptions) Encode(n datamodel.Node, w io.Writer) error

Encode walks the given datamodel.Node and serializes it to the given io.Writer. Encode fits the codec.Encoder function interface.

The behavior of the encoder can be customized by setting fields in the EncodeOptions struct before calling this method.

Jump to

Keyboard shortcuts

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