json

package
v0.0.0-...-fe78ce7 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ProtoMarshalOptions = protojson.MarshalOptions{
		Multiline:       false,
		UseProtoNames:   true,
		UseEnumNumbers:  true,
		EmitUnpopulated: true,
	}

	ProtoUnmarshalOptions = protojson.UnmarshalOptions{
		DiscardUnknown: true,
	}
)

Functions

func ProtoMarshal

func ProtoMarshal(m proto.Message) ([]byte, error)

ProtoMarshal encodes a protobuf Message to JSON using the default ProtoMarshalOptions.

func ProtoUnmarshal

func ProtoUnmarshal(b []byte, m proto.Message) error

ProtoUnmarshal decodes JSON data into a protobuf Message using the default ProtoUnmarshalOptions.

Types

type ErrUnexpectedType

type ErrUnexpectedType struct {
	Expected jsoniter.ValueType
	Actual   jsoniter.ValueType
}

func (*ErrUnexpectedType) Error

func (err *ErrUnexpectedType) Error() string

type StringUint

type StringUint uint64

StringUint is an integer type used for JSON encoding.

It's used to decode JSON numeric values or numeric strings (base 10 or float) into uint64 and serialize uint64 into string (base 10).

func (StringUint) MarshalJSON

func (si StringUint) MarshalJSON() ([]byte, error)

MarshalJSON serializes the uint64 value to JSON numeric string (base 10).

func (StringUint) Uint32

func (si StringUint) Uint32() uint32

Uint32 returns the value converted to uint32.

func (StringUint) Uint64

func (si StringUint) Uint64() uint64

Uint64 returns the value converted to uint64.

func (*StringUint) UnmarshalJSON

func (si *StringUint) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes JSON numeric value or numeric string into uint64 value.

type Transform

type Transform struct {
	*jsoniter.Iterator
	// contains filtered or unexported fields
}

func NewTransform

func NewTransform(data []byte) (*Transform, error)

func (*Transform) Array

func (t *Transform) Array(cb func() ([]byte, error)) ([]byte, error)

func (*Transform) Object

func (t *Transform) Object(cb func(string) ([]byte, error)) ([]byte, error)

func (*Transform) ValidateNext

func (t *Transform) ValidateNext(expectedType jsoniter.ValueType) error

type UnixTime

type UnixTime struct {
	time.Time
}

UnixTime is a time.Time wrapper type used for JSON encoding.

Used to deserialize unix timestamps encoded as integer into time.Time and serialize time.Time to integer.

func (UnixTime) MarshalJSON

func (ut UnixTime) MarshalJSON() ([]byte, error)

MarshalJSON serializes the Time value to JSON integer.

func (*UnixTime) UnmarshalJSON

func (ut *UnixTime) UnmarshalJSON(data []byte) error

UnmarshalJSON deserializes JSON integer into Time value.

Jump to

Keyboard shortcuts

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