codec

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 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
)

Variables

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

Functions

func DecodeAny

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

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) SimpleEncoder
	// contains filtered or unexported methods
}

type DecodeSelfer

type DecodeSelfer interface {
	RLPDecodeSelf(d Decoder) error
}

type Decoder

type Decoder interface {
	Decode(o interface{}) error
	DecodeMulti(objs ...interface{}) (int, error)
	DecodeBytes() ([]byte, error)
	DecodeList() (Decoder, error)
	DecodeListOf(objs ...interface{}) error
}

func NewDecoder

func NewDecoder(r Reader) Decoder

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
}

func NewEncoder

func NewEncoder(w Writer) Encoder

type Marshaler

type Marshaler interface {
	MarshalRLP() ([]byte, 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 SimpleDecoder

type SimpleDecoder interface {
	Decode(v interface{}) error
}

func NewSimpleDecoder

func NewSimpleDecoder(r io.Reader) SimpleDecoder

type SimpleEncoder

type SimpleEncoder interface {
	Encode(v interface{}) error
}

func NewEncoderBytes

func NewEncoderBytes(b *[]byte) SimpleEncoder

func NewSimpleEncoder

func NewSimpleEncoder(w io.Writer) SimpleEncoder

type TypeCodec

type TypeCodec interface {
	Decode(tag uint8, data []byte) (interface{}, error)
	Encode(o interface{}) (uint8, []byte, 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 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