codec

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 6 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewForwardCodec

func NewForwardCodec[V any]() trcache.Codec[V]

func NewFuncCodec

func NewFuncCodec[V any](marshal func(ctx context.Context, data V) (any, error),
	unmarshal func(ctx context.Context, data any) (V, error)) trcache.Codec[V]

func NewGOBCodec

func NewGOBCodec[V any](options ...GOBCodecOption) trcache.Codec[V]

func NewJSONCodec

func NewJSONCodec[V any](options ...JSONCodecOption) trcache.Codec[V]

Types

type ForwardCodec

type ForwardCodec[V any] struct {
}

ForwardCodec is a Codec that returns the same object passed.

func (ForwardCodec[V]) Decode

func (c ForwardCodec[V]) Decode(ctx context.Context, data any) (V, error)

func (ForwardCodec[V]) Encode

func (c ForwardCodec[V]) Encode(ctx context.Context, data V) (any, error)

type FuncCodec

type FuncCodec[V any] struct {
	// contains filtered or unexported fields
}

FuncCodec is a Codec that uses the passed functions as its methods.

func (FuncCodec[V]) Decode

func (c FuncCodec[V]) Decode(ctx context.Context, data any) (V, error)

func (FuncCodec[V]) Encode

func (c FuncCodec[V]) Encode(ctx context.Context, data V) (any, error)

type GOBCodec

type GOBCodec[V any] struct {
	// contains filtered or unexported fields
}

GOBCodec is a Codec that marshals from/to encoding/gob.

func (GOBCodec[V]) Decode

func (c GOBCodec[V]) Decode(ctx context.Context, data any) (V, error)

func (GOBCodec[V]) Encode

func (c GOBCodec[V]) Encode(ctx context.Context, data V) (any, error)

type GOBCodecOption

type GOBCodecOption func(*gobCodecOptions)

func WithGOBCodecReturnString

func WithGOBCodecReturnString(returnString bool) GOBCodecOption

type JSONCodec

type JSONCodec[V any] struct {
	// contains filtered or unexported fields
}

JSONCodec is a Codec that marshals from/to JSON.

func (JSONCodec[V]) Decode

func (c JSONCodec[V]) Decode(ctx context.Context, data any) (V, error)

func (JSONCodec[V]) Encode

func (c JSONCodec[V]) Encode(ctx context.Context, data V) (any, error)

type JSONCodecOption

type JSONCodecOption func(*jsonCodecOptions)

func WithJSONCodecReturnBytes

func WithJSONCodecReturnBytes(returnBytes bool) JSONCodecOption

type StringKeyCodec

type StringKeyCodec[K comparable] struct {
}

StringKeyCodec is a key codec that converts all values to string.

func NewStringKeyCodec

func NewStringKeyCodec[K comparable]() *StringKeyCodec[K]

func (*StringKeyCodec[K]) Convert

func (s *StringKeyCodec[K]) Convert(ctx context.Context, key K) (any, error)

Jump to

Keyboard shortcuts

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