codec

package
v0.0.0-...-133031b Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arbor

type Arbor struct{}

Arbor serializes forest types using the safe arbor serialization that validates the data.

func (Arbor) Decode

func (ac Arbor) Decode(by []byte, v interface{}) error

func (Arbor) Encode

func (ac Arbor) Encode(v interface{}) ([]byte, error)

type Codec

type Codec interface {
	Encode(v interface{}) ([]byte, error)
	Decode(b []byte, v interface{}) error
}

Codec can encode and decode forest types.

type Default

type Default struct {
	Inner Codec
	sync.Once
}

Default initializes to the safe Arbor codec, unless overriden by internal code such as test code.

func (*Default) Decode

func (d *Default) Decode(b []byte, v interface{}) error

func (*Default) Encode

func (d *Default) Encode(v interface{}) ([]byte, error)

type Unsafe

type Unsafe struct{}

Unsafe serializes forest types without validating them for the purposes of fast testing.

This avoids branches within the orchard code that could lead to nodes not being validated.

NOTE(jfm) msgpack is used because stdlib encodings have coincidental issues:

- Gob calls into encoding.BinaryMarshaler method set, which calls the node validation code paths.

- JSON encodes types like fields.Version into an escaped hexidecimal string, but refuses to decode back into fields.Version without some help.

In an attempt to avoid touching the fields types, I've opted to go with a encoding that works "out of the box".

func (Unsafe) Decode

func (Unsafe) Decode(b []byte, v interface{}) error

func (Unsafe) Encode

func (Unsafe) Encode(v interface{}) ([]byte, error)

Jump to

Keyboard shortcuts

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