json

package
v0.0.0-...-3cc3ff2 Latest Latest
Warning

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

Go to latest
Published: May 17, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownType = errors.New("unknown type")

ErrUnknownType is thrown when the given type is unknown

Functions

func AddType

func AddType(encoder *gojay.Encoder, typed types.Type, value interface{})

AddType encodes the given value into the given encoder

func AddTypeKey

func AddTypeKey(encoder *gojay.Encoder, key string, typed types.Type, value interface{})

AddTypeKey encodes the given value into the given encoder

func BoolEmpty

func BoolEmpty(val interface{}) bool

BoolEmpty returns the given value as a bool or a empty bool if the value is nil

func BytesBase64Empty

func BytesBase64Empty(val interface{}) string

BytesBase64Empty returns the given bytes buffer as a base64 string or a empty string if the value is nil

func DecodeType

func DecodeType(decoder *gojay.Decoder, prop types.Type) (interface{}, error)

DecodeType decodes the given property from the given decoder

func Float32Empty

func Float32Empty(val interface{}) float32

Float32Empty returns the given value as a float32 or a empty float32 if the value is nil

func Float64Empty

func Float64Empty(val interface{}) float64

Float64Empty returns the given value as a float64 or a empty float64 if the value is nil

func Int32Empty

func Int32Empty(val interface{}) int32

Int32Empty returns the given value as a int32 or a empty int32 if the value is nil

func Int64Empty

func Int64Empty(val interface{}) int64

Int64Empty returns the given value as a int64 or a empty int64 if the value is nil

func StringEmpty

func StringEmpty(val interface{}) string

StringEmpty returns the given value as a string or a empty string if the value is nil

func Uint32Empty

func Uint32Empty(val interface{}) uint32

Uint32Empty returns the given value as a uint32 or a empty uint32 if the value is nil

func Uint64Empty

func Uint64Empty(val interface{}) uint64

Uint64Empty returns the given value as a uint64 or a empty uint64 if the value is nil

Types

type Array

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

Array represents a JSON array.

func NewArray

func NewArray(path string, template specs.Template, store references.Store, tracker references.Tracker) *Array

NewArray creates a new array to be JSON encoded/decoded.

func (*Array) IsNil

func (array *Array) IsNil() bool

IsNil returns whether the given array is null or not.

func (*Array) MarshalJSONArray

func (array *Array) MarshalJSONArray(encoder *gojay.Encoder)

MarshalJSONArray encodes the array into the given gojay encoder.

func (*Array) UnmarshalJSONArray

func (array *Array) UnmarshalJSONArray(decoder *gojay.Decoder) error

UnmarshalJSONArray unmarshals the given specs into the configured reference store.

type Constructor

type Constructor struct{}

Constructor is capable of constructing new codec managers for the given resource and specs.

func NewConstructor

func NewConstructor() *Constructor

NewConstructor constructs a new JSON constructor.

func (*Constructor) Name

func (constructor *Constructor) Name() string

Name returns the name of the JSON codec constructor.

func (*Constructor) New

func (constructor *Constructor) New(resource string, specs *specs.ParameterMap) (codec.Manager, error)

New constructs a new JSON codec manager

type Enum

type Enum specs.Template

Enum represents a enum type template. This type is used to encode or decode values inside gojay. These values are used to construct messages to a service or a user.

func (Enum) Marshal

func (template Enum) Marshal(encoder *gojay.Encoder, store references.Store, tracker references.Tracker)

Marshal marshals the enum template as a JSON value. If no enum has been defined inside the given reference store is the type ignored.

func (Enum) MarshalKey

func (template Enum) MarshalKey(encoder *gojay.Encoder, key string, store references.Store, tracker references.Tracker)

MarshalKey marshals the enum template as an object field using the given key. The key is not set if the enum value is `null`.

func (Enum) Unmarshal

func (template Enum) Unmarshal(decoder *gojay.Decoder, path string, store references.Store, tracker references.Tracker) error

Unmarshal attempts to unmarshal the value from the decoder as a enum and stores it inside the reference store.

type ErrUndefinedSpecs

type ErrUndefinedSpecs struct{}

ErrUndefinedSpecs occurs when spacs are nil

func (ErrUndefinedSpecs) Error

func (e ErrUndefinedSpecs) Error() string

Error returns a description of the given error as a string

func (ErrUndefinedSpecs) Prettify

func (e ErrUndefinedSpecs) Prettify() prettyerr.Error

Prettify returns the prettified version of the given error

type Manager

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

Manager manages a specs object and allows to encode/decode messages.

func (*Manager) Marshal

func (manager *Manager) Marshal(store references.Store) (io.Reader, error)

Marshal marshals the given reference store into a JSON message. This method is called during runtime to encode a new message with the values stored inside the given reference store

func (*Manager) Name

func (manager *Manager) Name() string

Name returns the proto codec name

func (*Manager) Property

func (manager *Manager) Property() *specs.Property

Property returns the manager property which is used to marshal and unmarshal data

func (*Manager) Unmarshal

func (manager *Manager) Unmarshal(reader io.Reader, store references.Store) error

Unmarshal unmarshals the given JSON io reader into the given reference store. This method is called during runtime to decode a new message and store it inside the given reference store

type Object

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

Object represents a JSON object

func NewObject

func NewObject(path string, template specs.Template, store references.Store, tracker references.Tracker) *Object

NewObject constructs a new object encoder/decoder for the given specs

func (*Object) IsNil

func (object *Object) IsNil() bool

IsNil returns whether the given object is null or not

func (*Object) MarshalJSONObject

func (object *Object) MarshalJSONObject(encoder *gojay.Encoder)

MarshalJSONObject encodes the given specs object into the given gojay encoder

func (*Object) NKeys

func (object *Object) NKeys() int

NKeys returns the amount of available keys inside the given object

func (*Object) UnmarshalJSONObject

func (object *Object) UnmarshalJSONObject(decoder *gojay.Decoder, key string) error

UnmarshalJSONObject unmarshals the given specs into the configured reference store

type Scalar

type Scalar specs.Template

Scalar represents a scalar type such as a string, int or float. The scalar type is used to encode or decode values inside gojay. These values are used to construct messages to a service or user.

func (Scalar) Marshal

func (template Scalar) Marshal(encoder *gojay.Encoder, store references.Store, tracker references.Tracker)

Marshal marshals the scalar template as a JSON value.

func (Scalar) MarshalKey

func (template Scalar) MarshalKey(encoder *gojay.Encoder, key string, store references.Store, tracker references.Tracker) bool

MarshalKey marshals the scalar template as an object field using the given key. The key is not set if the value is `null`.

func (Scalar) Unmarshal

func (template Scalar) Unmarshal(decoder *gojay.Decoder, path string, store references.Store, tracker references.Tracker) error

Unmarshal attempts to unmarshal the value from the decoder as a scalar and stores it inside the reference store.

Jump to

Keyboard shortcuts

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