json

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: Apache-2.0 Imports: 11 Imported by: 110

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidJSONCadence = errors.New("invalid JSON Cadence structure")

Functions

func Decode

func Decode(b []byte) (cadence.Value, error)

Decode returns a Cadence value decoded from its JSON-encoded representation.

This function returns an error if the bytes represent JSON that is malformed or does not conform to the JSON Cadence specification.

func Encode

func Encode(value cadence.Value) ([]byte, error)

Encode returns the JSON-encoded representation of the given value.

This function returns an error if the Cadence value cannot be represented as JSON.

func MustEncode added in v0.2.0

func MustEncode(value cadence.Value) []byte

MustEncode returns the JSON-encoded representation of the given value, or panics if the value cannot be represented as JSON.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder decodes JSON-encoded representations of Cadence values.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder initializes a Decoder that will decode JSON-encoded bytes from the given io.Reader.

func (*Decoder) Decode

func (d *Decoder) Decode() (value cadence.Value, err error)

Decode reads JSON-encoded bytes from the io.Reader and decodes them to a Cadence value.

This function returns an error if the bytes represent JSON that is malformed or does not conform to the JSON Cadence specification.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

An Encoder converts Cadence values into JSON-encoded bytes.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder initializes an Encoder that will write JSON-encoded bytes to the given io.Writer.

func (*Encoder) Encode

func (e *Encoder) Encode(value cadence.Value) (err error)

Encode writes the JSON-encoded representation of the given value to this encoder's io.Writer.

This function returns an error if the given value's type is not supported by this encoder.

Jump to

Keyboard shortcuts

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