Documentation
¶
Index ¶
- Constants
- Variables
- func StringLen(str string) int
- type Codec
- type Errs
- type GeneralCodec
- type Manager
- type Packer
- func (p *Packer) Errored() bool
- func (p *Packer) PackBool(val bool)
- func (p *Packer) PackByte(val byte)
- func (p *Packer) PackBytes(val []byte)
- func (p *Packer) PackFixedBytes(val []byte)
- func (p *Packer) PackID(id ids.ID)
- func (p *Packer) PackInt(val uint32)
- func (p *Packer) PackLong(val uint64)
- func (p *Packer) PackShort(val uint16)
- func (p *Packer) PackStr(val string)
- func (p *Packer) Remaining() int
- func (p *Packer) UnpackBool() bool
- func (p *Packer) UnpackByte() byte
- func (p *Packer) UnpackBytes() []byte
- func (p *Packer) UnpackFixedBytes(n int) []byte
- func (p *Packer) UnpackID() ids.ID
- func (p *Packer) UnpackInt() uint32
- func (p *Packer) UnpackLong() uint64
- func (p *Packer) UnpackShort() uint16
- func (p *Packer) UnpackStr() string
- type Registry
Constants ¶
const ( // ByteLen is the number of bytes per byte ByteLen = 1 // ShortLen is the number of bytes per short ShortLen = 2 // VersionSize is the number of bytes used for codec version VersionSize = ShortLen // IntLen is the number of bytes per int IntLen = 4 // LongLen is the number of bytes per long LongLen = 8 // BoolLen is the number of bytes per bool BoolLen = 1 // IPLen is the number of bytes per IP (16 bytes + 2 for port) IPLen = 16 + ShortLen )
Size constants for binary packing
const DefaultMaxSize = 1024 * 1024
DefaultMaxSize is the default maximum size for codec manager (1MB)
const MaxStringLen = math.MaxUint16
MaxStringLen is the maximum string length that can be packed
Variables ¶
var ( ErrUnsupportedType = errors.New("unsupported type") ErrMaxSliceLenExceeded = errors.New("max slice length exceeded") ErrDoesNotImplementInterface = errors.New("does not implement interface") ErrUnexportedField = errors.New("unexported field") ErrMarshalNil = errors.New("can't marshal nil pointer") ErrMarshalZeroLength = errors.New("can't marshal zero length value") ErrUnmarshalNil = errors.New("can't unmarshal into nil") ErrUnmarshalZeroLength = errors.New("can't unmarshal zero length value") ErrCantPackVersion = errors.New("couldn't pack codec version") ErrCantUnpackVersion = errors.New("couldn't unpack codec version") ErrUnknownVersion = errors.New("unknown codec version") ErrDuplicateType = errors.New("duplicate type registration") ErrExtraSpace = errors.New("trailing buffer space") )
Common codec errors
var ( ErrInsufficientLength = errors.New("packing: insufficient length") ErrNegativeLength = errors.New("packing: negative length") ErrBadLength = errors.New("packing: bad length") ErrOverflow = errors.New("packing: overflow") )
Common errors
Functions ¶
Types ¶
type Codec ¶
type Codec interface {
MarshalInto(interface{}, *wrappers.Packer) error
UnmarshalFrom(*wrappers.Packer, interface{}) error
Size(value interface{}) (int, error)
}
Codec marshals and unmarshals
type Errs ¶
type Errs struct {
Err error
}
Errs collects errors during a series of operations. It stores only the first error encountered.
type GeneralCodec ¶
GeneralCodec combines Codec and Registry interfaces
type Manager ¶
type Manager interface {
RegisterCodec(version uint16, codec Codec) error
Marshal(version uint16, source interface{}) ([]byte, error)
Unmarshal(bytes []byte, dest interface{}) (uint16, error)
Size(version uint16, value interface{}) (int, error)
}
Manager manages multiple codec versions
func NewDefaultManager ¶
func NewDefaultManager() Manager
NewDefaultManager returns a codec manager with default max size
type Packer ¶
Packer provides methods to pack data into bytes
func PackerFromBytes ¶
PackerFromBytes returns a Packer initialized with the given bytes
func (*Packer) PackFixedBytes ¶
PackFixedBytes packs a fixed-length byte slice
func (*Packer) UnpackBytes ¶
UnpackBytes unpacks a byte slice with length prefix
func (*Packer) UnpackFixedBytes ¶
UnpackFixedBytes unpacks a fixed-length byte slice
Directories
¶
| Path | Synopsis |
|---|---|
|
Package codecmock is a generated GoMock package.
|
Package codecmock is a generated GoMock package. |
|
Package wrappers provides common wrapper types and utilities.
|
Package wrappers provides common wrapper types and utilities. |
|
Package zapcodec is a drop-in replacement for linearcodec that emits the ZAP-native little-endian wire layout.
|
Package zapcodec is a drop-in replacement for linearcodec that emits the ZAP-native little-endian wire layout. |