json

package
v0.39.6 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 13 Imported by: 111

Documentation

Overview

Package json implements the JSON-Cadence specification: https://github.com/onflow/flow/blob/master/docs/json-cadence-spec.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(gauge common.MemoryGauge, b []byte, options ...Option) (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.

func Prepare added in v0.12.0

func Prepare(v cadence.Value) jsonValue

Prepare traverses the object graph of the provided value and constructs a struct representation that can be marshalled to 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(gauge common.MemoryGauge, 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.

type Option added in v0.24.4

type Option func(*Decoder)

func WithAllowUnstructuredStaticTypes added in v0.24.4

func WithAllowUnstructuredStaticTypes(allow bool) Option

WithAllowUnstructuredStaticTypes returns a new Decoder Option which enables or disables if the decoding of a static type as a type ID (cadence.TypeID) is allowed

Jump to

Keyboard shortcuts

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