serde

package
v0.0.0-...-fd0b456 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnpairedKey = errors.New("unpaired key")
)

Functions

func FakeOmitempty

func FakeOmitempty(t reflect.StructTag) reflect.StructTag

func FlattenStructTag

func FlattenStructTag(tags []Tag) reflect.StructTag

func Marshal

func Marshal(v any) ([]byte, error)

Marshal encodes v into JSON. It skips fields if those are undefined Undefinedable[T].

v can be any type.

func NewDecoder

func NewDecoder(r io.Reader) *jsoniter.Decoder

func NewEncoder

func NewEncoder(w io.Writer) *jsoniter.Encoder

func Unmarshal

func Unmarshal(data []byte, v any) error

Unmarshal decodes data into v. v must be pointer type, return error otherwise.

Currently this is almost same as json.Unmarshal. Future releases may change behavior of this function. It is safe to unmarshal data through this if v has at least an Undefinedable[T] field.

Types

type FakedOmitemptyField

type FakedOmitemptyField struct {
	reflect2.StructField
	// contains filtered or unexported fields
}

FakedOmitemptyField implements reflect2.StructField interface, faking the struct tag to pretend it is always tagged with ,omitempty option.

The Zero value is not ready for use. Make it with NewFakedOmitemptyField.

func NewFakedOmitemptyField

func NewFakedOmitemptyField(f reflect2.StructField) FakedOmitemptyField

func (FakedOmitemptyField) Tag

type IsUndefineder

type IsUndefineder interface {
	IsUndefined() bool
}

type Tag

type Tag struct {
	Key   string
	Value string
}

func ParseStructTag

func ParseStructTag(tag reflect.StructTag) ([]Tag, error)

func (Tag) Flatten

func (t Tag) Flatten() string

type UndefinedSkipperExtension

type UndefinedSkipperExtension struct {
}

UndefinedSkipperExtension is the extension for jsoniter.API. When marshaling, this extension forces jsoniter.API to skip undefined struct fields. A field is considered undefined if its type implements interface{ IsUndefined() bool } and if it returns true.

func (*UndefinedSkipperExtension) CreateDecoder

func (extension *UndefinedSkipperExtension) CreateDecoder(typ reflect2.Type) jsoniter.ValDecoder

func (*UndefinedSkipperExtension) CreateEncoder

func (extension *UndefinedSkipperExtension) CreateEncoder(typ reflect2.Type) jsoniter.ValEncoder

func (*UndefinedSkipperExtension) CreateMapKeyDecoder

func (extension *UndefinedSkipperExtension) CreateMapKeyDecoder(typ reflect2.Type) jsoniter.ValDecoder

func (*UndefinedSkipperExtension) CreateMapKeyEncoder

func (extension *UndefinedSkipperExtension) CreateMapKeyEncoder(typ reflect2.Type) jsoniter.ValEncoder

func (*UndefinedSkipperExtension) DecorateDecoder

func (extension *UndefinedSkipperExtension) DecorateDecoder(typ reflect2.Type, decoder jsoniter.ValDecoder) jsoniter.ValDecoder

func (*UndefinedSkipperExtension) DecorateEncoder

func (extension *UndefinedSkipperExtension) DecorateEncoder(typ reflect2.Type, encoder jsoniter.ValEncoder) jsoniter.ValEncoder

func (*UndefinedSkipperExtension) UpdateStructDescriptor

func (extension *UndefinedSkipperExtension) UpdateStructDescriptor(structDescriptor *jsoniter.StructDescriptor)

type UndefinedableEncoder

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

UndefinedableEncoder fakes the Encoder so that undefined Undefinedable[T] fields are skipped.

func (UndefinedableEncoder) Encode

func (e UndefinedableEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream)

func (UndefinedableEncoder) IsEmpty

func (e UndefinedableEncoder) IsEmpty(ptr unsafe.Pointer) bool

Jump to

Keyboard shortcuts

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