lookup

package
v0.0.0-...-015e77e Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const InvalidToken = ""

InvalidToken is an invalid lookup token.

Variables

This section is empty.

Functions

func NewLookupDecoder

func NewLookupDecoder(ctx *Context, typ reflect2.Type, decoder jsoniter.ValDecoder) jsoniter.ValDecoder

NewLookupDecoder returns an decoder that reads a lookup table. It will check the iterated string values to see if they match our lookup token. If there is a match, it will replace it with a decoded value from the lookup table or an empty value.

func NewLookupEncoder

func NewLookupEncoder(ctx *Context, typ reflect2.Type, encoder jsoniter.ValEncoder) jsoniter.ValEncoder

NewLookupEncoder returns an encoder that builds a lookup table. It will strip out tagged struct fields and collect the encoded values in the provided stream as a map. As it strips out values, it replaces them with a token key for the lookup table. Later we can use this key as a lookup to reconstruct the encoded struct as it is decoded. The hash encoder must be run before this encoder, so the struct fields are hashed before they are stripped.

func NewLookupToken

func NewLookupToken(prefix, encoderID string) string

NewLookupToken returns the field name for sparse encoded data as the encoder id with the format "[prefix]-[encoder id]".

Types

type Context

type Context struct {
	Token  string
	Stream *jsoniter.Stream
}

Context holds the context for the lookup coders.

type Decoder

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

Decoder is a ValDecoder that reads lookup table key strings from the iterator. When a key is found in the lookup table it decodes the lookup table data in place of the key.

func (*Decoder) Decode

func (d *Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator)

Decode sets ptr to the next value of iterator.

func (*Decoder) SetLogger

func (d *Decoder) SetLogger(l log.Logger)

SetLogger changes the logger for the decoder.

type Encoder

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

Encoder is a ValEncoder that encodes the data to lookup table and encodes a entry key for the data into the stream that can be read later by the decoder.

func (*Encoder) Encode

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

Encode writes the value of ptr to stream.

func (*Encoder) IsEmpty

func (e *Encoder) IsEmpty(ptr unsafe.Pointer) bool

IsEmpty returns true is ptr is empty, otherwise false.

func (*Encoder) SetLogger

func (e *Encoder) SetLogger(l log.Logger)

SetLogger changes the logger for the encoder.

type Key

type Key string

Key is an encoded lookup data key.

func NewLookupKey

func NewLookupKey(token string, index int, typ reflect2.Type) Key

NewLookupKey creates a new lookup table key with the encoding field index and type. The field index is *not* the index relative to a StructField, but relative to the JSON encoding itself.

func (Key) IsTokenKey

func (k Key) IsTokenKey(token string) bool

IsTokenKey returns true if the key was derived from the lookup token.

func (Key) Kind

func (k Key) Kind() reflect.Kind

Kind returns the encoded reflect.Kind for the key.

func (Key) String

func (k Key) String() string

Jump to

Keyboard shortcuts

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