codec

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: Apache-2.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

View Source
const (
	TypeNil uint8 = iota
	TypeDict
	TypeList
	TypeBytes
	TypeString
	TypeBool
	TypeCustom = 10
)
View Source
const MaxSizeForBytes = 1e6

MaxSizeForBytes is size limit for bytes buffer. msgpack decoder already has limit to 1 MB

Variables

View Source
var (
	ErrNilValue      = errors.New("NilValueError")
	ErrInvalidFormat = errors.New("InvalidFormatError")
	ErrIllegalType   = errors.New("IllegalTypeError")
	ErrPanicInCustom = errors.New("PanicInCustomError")
)
View Source
var (
	TrueBytes  = []byte{0x01}
	FalseBytes = []byte{0x00}
)
View Source
var (
	BC = RLP
)
View Source
var MP = bytesWrapperFrom(&mpCodecObject)
View Source
var Nil = &TypedObj{
	typedObjBase{
		TypeNil, nil,
	},
}
View Source
var RLP = bytesWrapperFrom(&rlpCodecObject)

Functions

func DecodeAny

func DecodeAny(tc TypeCodec, to *TypedObj) (interface{}, error)

func LimitReader added in v1.3.2

func LimitReader(r io.Reader, n int64) io.Reader

func Marshal

func Marshal(w io.Writer, v interface{}) error

func MarshalAny

func MarshalAny(c Codec, tc TypeCodec, o interface{}) ([]byte, error)

func MarshalToBytes

func MarshalToBytes(v interface{}) ([]byte, error)

func MustMarshalToBytes

func MustMarshalToBytes(v interface{}) []byte

func MustUnmarshalFromBytes

func MustUnmarshalFromBytes(b []byte, v interface{}) []byte

func Unmarshal

func Unmarshal(r io.Reader, v interface{}) error

func UnmarshalAny

func UnmarshalAny(c Codec, tc TypeCodec, bs []byte) (interface{}, error)

func UnmarshalFromBytes

func UnmarshalFromBytes(b []byte, v interface{}) ([]byte, error)

Types

type Codec

type Codec interface {
	Marshal(w io.Writer, v interface{}) error
	Unmarshal(r io.Reader, v interface{}) error
	MarshalToBytes(v interface{}) ([]byte, error)
	UnmarshalFromBytes(b []byte, v interface{}) ([]byte, error)
	MustMarshalToBytes(v interface{}) []byte
	MustUnmarshalFromBytes(b []byte, v interface{}) []byte
	NewEncoderBytes(b *[]byte) EncodeAndCloser
	// contains filtered or unexported methods
}

type DecodeAndCloser added in v0.9.6

type DecodeAndCloser interface {
	Decoder
	Close() error
}

func NewDecoder

func NewDecoder(r Reader) DecodeAndCloser

func NewSimpleDecoder

func NewSimpleDecoder(r io.Reader) DecodeAndCloser

type DecodeSelfer

type DecodeSelfer interface {
	RLPDecodeSelf(d Decoder) error
}

type Decoder

type Decoder interface {
	Skip(cnt int) error
	Decode(o interface{}) error
	DecodeMulti(objs ...interface{}) (int, error)
	DecodeAll(objs ...interface{}) error
	DecodeBytes() ([]byte, error)
	DecodeList() (Decoder, error)
	DecodeListOf(objs ...interface{}) error
	SetMaxBytes(sz int) bool
}

type EncodeAndCloser added in v0.9.6

type EncodeAndCloser interface {
	Encoder
	Close() error
}

func NewEncoder

func NewEncoder(w Writer) EncodeAndCloser

func NewEncoderBytes

func NewEncoderBytes(b *[]byte) EncodeAndCloser

func NewSimpleEncoder

func NewSimpleEncoder(w io.Writer) EncodeAndCloser

type EncodeSelfer

type EncodeSelfer interface {
	RLPEncodeSelf(e Encoder) error
}

type Encoder

type Encoder interface {
	Encode(o interface{}) error
	EncodeMulti(objs ...interface{}) error
	EncodeList() (Encoder, error)
	EncodeListOf(objs ...interface{}) error
}

type Marshaler

type Marshaler interface {
	MarshalRLP() ([]byte, error)
}

type ReadSelfer added in v0.9.6

type ReadSelfer interface {
	RLPReadSelf(w Reader) error
}

type Reader

type Reader interface {
	Skip(cnt int) error
	ReadList() (Reader, error)
	ReadMap() (Reader, error)
	ReadBytes() ([]byte, error)
	ReadRaw() ([]byte, error)
	ReadValue(v reflect.Value) error
	Close() error
}

type Selfer

type Selfer interface {
	EncodeSelfer
	DecodeSelfer
}

type TypeCodec

type TypeCodec interface {
	Decode(tag uint8, data []byte) (interface{}, error)
	Encode(o interface{}) (uint8, []byte, error)
}

type TypedDict added in v0.9.6

type TypedDict struct {
	Keys []string
	Map  map[string]*TypedObj
}

func (*TypedDict) RLPReadSelf added in v0.9.6

func (m *TypedDict) RLPReadSelf(r Reader) error

func (*TypedDict) RLPWriteSelf added in v0.9.6

func (m *TypedDict) RLPWriteSelf(w Writer) error

type TypedObj

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

func EncodeAny

func EncodeAny(tc TypeCodec, o interface{}) (*TypedObj, error)

func (*TypedObj) RLPDecodeSelf

func (o *TypedObj) RLPDecodeSelf(d Decoder) error

func (*TypedObj) RLPEncodeSelf

func (o *TypedObj) RLPEncodeSelf(e Encoder) error

type Unmarshaler

type Unmarshaler interface {
	UnmarshalRLP([]byte) error
}

type WriteSelfer added in v0.9.6

type WriteSelfer interface {
	RLPWriteSelf(w Writer) error
}

type Writer

type Writer interface {
	WriteList() (Writer, error)
	WriteMap() (Writer, error)
	WriteBytes(b []byte) error
	WriteRaw(b []byte) error
	WriteValue(v reflect.Value) error
	WriteNull() error
	Close() error
}

Jump to

Keyboard shortcuts

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