Documentation
¶
Index ¶
- Constants
- func NewLookupDecoder(ctx *Context, typ reflect2.Type, decoder jsoniter.ValDecoder) jsoniter.ValDecoder
- func NewLookupEncoder(ctx *Context, typ reflect2.Type, encoder jsoniter.ValEncoder) jsoniter.ValEncoder
- func NewLookupToken(prefix, encoderID string) string
- type Context
- type Decoder
- type Encoder
- type Key
Constants ¶
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 a 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 ¶
NewLookupToken returns the field name for sparse encoded data as the encoder id with the format "[prefix]-[encoder id]".
Types ¶
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.
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.
type Key ¶
type Key string
Key is an encoded lookup data key.
func NewLookupKey ¶
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 ¶
IsTokenKey returns true if the key was derived from the lookup token.