Documentation ΒΆ
Index ΒΆ
- Variables
- func Marshal(data any, options ...Options) ([]byte, error)
- func Unmarshal(b []byte, data any, options ...Options) error
- type AfterUnpack
- type BeforePack
- type ErrCantUseInInterfaceMode
- type ErrDataTooLarge
- type ErrInvalidType
- type ErrInvalidTypeKey
- type ErrNotDefined
- type Objects
- type Options
- type Packer
- type Socket
- type Unpacker
Constants ΒΆ
This section is empty.
Variables ΒΆ
View Source
var ( ErrInvalidPackedUint = errors.New("invalid packed uint") ErrInvalidReceiver = errors.New("invalid argument given to Decode, not a pointer type") ErrNil = errors.New("attempted to encode nil outside of pointer or interface context") ErrNilObject = errors.New("may not encode nil in object mode") ErrMustBePointerToInterface = errors.New("in Objects mode, value given to Decode must be of type *interface{}") )
Functions ΒΆ
Types ΒΆ
type AfterUnpack ΒΆ
type AfterUnpack interface { // If a struct implements this interface, this function will be called // right after it was unpacked, by returning an error it will cause the // unpacker to early return said error and stop further unpacking. AfterUnpack() error }
type BeforePack ΒΆ
type BeforePack interface { // If a struct implements this interface, this function will be called // right before it is about to be packed, by returning an error it will // cause the packer to early return said error and stop further packing. BeforePack() error }
type ErrCantUseInInterfaceMode ΒΆ
type ErrCantUseInInterfaceMode struct {
// contains filtered or unexported fields
}
func (*ErrCantUseInInterfaceMode) Error ΒΆ
func (e *ErrCantUseInInterfaceMode) Error() string
type ErrDataTooLarge ΒΆ
type ErrDataTooLarge struct {
// contains filtered or unexported fields
}
func (*ErrDataTooLarge) Error ΒΆ
func (e *ErrDataTooLarge) Error() string
type ErrInvalidType ΒΆ
type ErrInvalidType struct {
// contains filtered or unexported fields
}
func (*ErrInvalidType) Error ΒΆ
func (e *ErrInvalidType) Error() string
type ErrInvalidTypeKey ΒΆ
type ErrInvalidTypeKey struct {
// contains filtered or unexported fields
}
func (*ErrInvalidTypeKey) Error ΒΆ
func (e *ErrInvalidTypeKey) Error() string
type ErrNotDefined ΒΆ
type ErrNotDefined struct {
// contains filtered or unexported fields
}
func (*ErrNotDefined) Error ΒΆ
func (e *ErrNotDefined) Error() string
type Objects ΒΆ
type Objects interface { // Get ID of given Object GetID(item any) (uint, bool) // Get type of Object for given ID GetType(id uint) (reflect.Type, bool) // Insert new Objects Push(items ...any) Objects }
func NewObjects ΒΆ
type Options ΒΆ
type Options struct { // Set the Packer/Unpacker to work in Object Mode, in which it will only // be able to pack/unpack pre-defined types stored in given `Objects`, // by tagging them with object IDs that are defined in `Objects`. // // In this mode each top-level object packed will come with it's ID prepended // to it, so you may unpack it from a stream without needing to know what object // is being decoded beforehand. WithObjects Objects // Allows you to defined a list of allowed types to exist within a struct field // with type: any, []any, [...]any or map[...]any; // by tagging it with `pack:"objects:mapkey"` WithSubObjects map[string]Objects // Limit the amount of bytes a packer is able to write for a top-level object // and the amount of bytes an unpacker is able to read. // Once the limit is about to be passed, an error of type ErrDataTooLarge will // be returned. SizeLimit uint64 }
type Packer ΒΆ
type Packer interface { // Encode object into stream // // Note: If a pointer is given to the encoder (*obj), then the decoder needs to receive a pointer to a pointer (**obj) // (unless object mode is enabled in the options) Encode(data any) error // Total bytes written to the underlying stream BytesWritten() uint64 // Reset bytes written to 0 ResetCounter() // Set objects SetObjects(objects Objects) // Set sub-objects SetSubObjects(subObjects map[string]Objects) // Set size limit SetSizeLimit(sizeLimit uint64) }
type Socket ΒΆ
type Socket interface { // Read object from socket Read() (any, error) // Write object to socket Write(any) error // Read object from socket with a timeout ReadTimeout(timeout time.Duration) (any, error) // Write object to socket with a timeout WriteTimeout(data any, timeout time.Duration) error // Close socket Close() error // Get total bytes read BytesRead() uint64 // Get total bytes written BytesWritten() uint64 // Reset total bytes read ResetRead() // Reset total bytes written ResetWritten() // Deallocate write buffer to free memory ZeroBuffer() }
type Unpacker ΒΆ
type Unpacker interface { // Decode object on stream into a pointer Decode(data any) error // Total bytes read from the underlying stream BytesRead() uint64 // Reset bytes read to 0 ResetCounter() // Set objects SetObjects(objects Objects) // Set sub-objects SetSubObjects(subObjects map[string]Objects) // Set size limit SetSizeLimit(sizeLimit uint64) }
Click to show internal directories.
Click to hide internal directories.