encodbin

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrVarIntBufferSize = errors.New("varint: invalid buffer size")
View Source
var NoTypeIDDefaultID = TypeIDFromUint8(0)
View Source
var TypeSize = struct {
	Bool int
	Byte int

	Int8  int
	Int16 int

	Uint8   int
	Uint16  int
	Uint32  int
	Uint64  int
	Uint128 int

	Float32 int
	Float64 int

	PublicKey int
	Signature int

	Tstamp         int
	BlockTimestamp int

	CurrencyName int
}{
	Byte: 1,
	Bool: 1,

	Int8:  1,
	Int16: 2,

	Uint8:   1,
	Uint16:  2,
	Uint32:  4,
	Uint64:  8,
	Uint128: 16,

	Float32: 4,
	Float64: 8,
}

Functions

func DecodeCompactU16Length

func DecodeCompactU16Length(bytes []byte) int

DecodeCompactU16Length decodes a "Compact-u16" length from the provided byte slice.

func DecodeCompactU16LengthFromByteReader

func DecodeCompactU16LengthFromByteReader(reader io.ByteReader) (int, error)

DecodeCompactU16LengthFromByteReader decodes a "Compact-u16" length from the provided io.ByteReader.

func EncodeCompactU16Length

func EncodeCompactU16Length(bytes *[]byte, ln int)

func ReverseBytes

func ReverseBytes(s []byte)

func Uint32FromTypeID

func Uint32FromTypeID(vid TypeID, order binary.ByteOrder) (out uint32)

Uint32FromTypeID parses a TypeID bytes to a uint32.

func Uint8FromTypeID

func Uint8FromTypeID(vid TypeID) (out uint8)

Uint32FromTypeID parses a TypeID bytes to a uint8.

Types

type BaseVariant

type BaseVariant struct {
	TypeID TypeID
	Impl   interface{}
}

type BinaryMarshaler

type BinaryMarshaler interface {
	MarshalWithEncoder(encoder *Encoder) error
}

type BinaryUnmarshaler

type BinaryUnmarshaler interface {
	UnmarshalWithDecoder(decoder *Decoder) error
}

type Decoder

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

Decoder implements the EOS unpacking, similar to FC_BUFFER

func NewBinDecoder

func NewBinDecoder(data []byte) *Decoder

func NewDecoderWithEncoding

func NewDecoderWithEncoding(data []byte, enc Encoding) *Decoder

func (*Decoder) Decode

func (dec *Decoder) Decode(v interface{}) (err error)

func (*Decoder) Discard

func (dec *Decoder) Discard(n int) (err error)

func (*Decoder) HasRemaining

func (dec *Decoder) HasRemaining() bool

func (*Decoder) IsBin

func (dec *Decoder) IsBin() bool

func (*Decoder) IsBorsh

func (dec *Decoder) IsBorsh() bool

func (*Decoder) IsCompactU16

func (dec *Decoder) IsCompactU16() bool

func (*Decoder) Peek

func (dec *Decoder) Peek(n int) (out []byte, err error)

func (*Decoder) Position

func (dec *Decoder) Position() uint

func (*Decoder) Read

func (dec *Decoder) Read(buf []byte) (int, error)

func (*Decoder) ReadBool

func (dec *Decoder) ReadBool() (out bool, err error)

func (*Decoder) ReadByte

func (dec *Decoder) ReadByte() (out byte, err error)

func (*Decoder) ReadByteSlice

func (dec *Decoder) ReadByteSlice() (out []byte, err error)

func (*Decoder) ReadBytes

func (dec *Decoder) ReadBytes(n int) (out []byte, err error)

ReadBytes reads a byte slice of length n.

func (*Decoder) ReadCompactU16

func (dec *Decoder) ReadCompactU16() (out int, err error)

ReadCompactU16 reads a compact u16 from the decoder.

func (*Decoder) ReadCompactU16Length

func (dec *Decoder) ReadCompactU16Length() (int, error)

func (*Decoder) ReadFloat128

func (dec *Decoder) ReadFloat128(order binary.ByteOrder) (out Float128, err error)

func (*Decoder) ReadFloat32

func (dec *Decoder) ReadFloat32(order binary.ByteOrder) (out float32, err error)

func (*Decoder) ReadFloat64

func (dec *Decoder) ReadFloat64(order binary.ByteOrder) (out float64, err error)

func (*Decoder) ReadInt128

func (dec *Decoder) ReadInt128(order binary.ByteOrder) (out Int128, err error)

func (*Decoder) ReadInt16

func (dec *Decoder) ReadInt16(order binary.ByteOrder) (out int16, err error)

func (*Decoder) ReadInt32

func (dec *Decoder) ReadInt32(order binary.ByteOrder) (out int32, err error)

func (*Decoder) ReadInt64

func (dec *Decoder) ReadInt64(order binary.ByteOrder) (out int64, err error)

func (*Decoder) ReadInt8

func (dec *Decoder) ReadInt8() (out int8, err error)

func (*Decoder) ReadLength

func (dec *Decoder) ReadLength() (length int, err error)

func (*Decoder) ReadNBytes

func (dec *Decoder) ReadNBytes(n int) (out []byte, err error)

func (*Decoder) ReadRustString

func (dec *Decoder) ReadRustString() (out string, err error)

func (*Decoder) ReadString

func (dec *Decoder) ReadString() (out string, err error)

func (*Decoder) ReadTypeID

func (dec *Decoder) ReadTypeID() (out TypeID, err error)

func (*Decoder) ReadUint128

func (dec *Decoder) ReadUint128(order binary.ByteOrder) (out Uint128, err error)

func (*Decoder) ReadUint16

func (dec *Decoder) ReadUint16(order binary.ByteOrder) (out uint16, err error)

func (*Decoder) ReadUint32

func (dec *Decoder) ReadUint32(order binary.ByteOrder) (out uint32, err error)

func (*Decoder) ReadUint64

func (dec *Decoder) ReadUint64(order binary.ByteOrder) (out uint64, err error)

func (*Decoder) ReadUint8

func (dec *Decoder) ReadUint8() (out uint8, err error)

func (*Decoder) ReadUvarint16

func (dec *Decoder) ReadUvarint16() (out uint16, err error)

func (*Decoder) ReadUvarint32

func (dec *Decoder) ReadUvarint32() (out uint32, err error)

func (*Decoder) ReadUvarint64

func (dec *Decoder) ReadUvarint64() (uint64, error)

func (*Decoder) ReadVarint16

func (dec *Decoder) ReadVarint16() (out int16, err error)

func (*Decoder) ReadVarint32

func (dec *Decoder) ReadVarint32() (out int32, err error)

func (*Decoder) ReadVarint64

func (dec *Decoder) ReadVarint64() (out int64, err error)

func (*Decoder) Remaining

func (dec *Decoder) Remaining() int

func (*Decoder) Reset

func (dec *Decoder) Reset(data []byte)

Reset resets the decoder to decode a new message.

func (*Decoder) SafeReadUTF8String

func (dec *Decoder) SafeReadUTF8String() (out string, err error)

func (*Decoder) SetEncoding

func (dec *Decoder) SetEncoding(enc Encoding)

SetEncoding sets the encoding scheme to use for decoding.

func (*Decoder) SetPosition

func (dec *Decoder) SetPosition(idx uint) error

func (*Decoder) SkipBytes

func (dec *Decoder) SkipBytes(count uint) error

type Encoder

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

func NewBinEncoder

func NewBinEncoder(writer io.Writer) *Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) (err error)

func (*Encoder) WriteBool

func (e *Encoder) WriteBool(b bool) (err error)

func (*Encoder) WriteByte

func (e *Encoder) WriteByte(b byte) (err error)

func (*Encoder) WriteBytes

func (e *Encoder) WriteBytes(b []byte, writeLength bool) error

func (*Encoder) WriteCompactU16Length

func (e *Encoder) WriteCompactU16Length(ln int) (err error)

func (*Encoder) WriteFloat32

func (e *Encoder) WriteFloat32(f float32, order binary.ByteOrder) (err error)

func (*Encoder) WriteFloat64

func (e *Encoder) WriteFloat64(f float64, order binary.ByteOrder) (err error)

func (*Encoder) WriteInt128

func (e *Encoder) WriteInt128(i Int128, order binary.ByteOrder) (err error)

func (*Encoder) WriteInt16

func (e *Encoder) WriteInt16(i int16, order binary.ByteOrder) (err error)

func (*Encoder) WriteInt32

func (e *Encoder) WriteInt32(i int32, order binary.ByteOrder) (err error)

func (*Encoder) WriteInt64

func (e *Encoder) WriteInt64(i int64, order binary.ByteOrder) (err error)

func (*Encoder) WriteLength

func (e *Encoder) WriteLength(length int) error

func (*Encoder) WriteRustString

func (e *Encoder) WriteRustString(s string) (err error)

func (*Encoder) WriteString

func (e *Encoder) WriteString(s string) (err error)

func (*Encoder) WriteUVarInt

func (e *Encoder) WriteUVarInt(v int) (err error)

func (*Encoder) WriteUint128

func (e *Encoder) WriteUint128(i Uint128, order binary.ByteOrder) (err error)

func (*Encoder) WriteUint16

func (e *Encoder) WriteUint16(i uint16, order binary.ByteOrder) (err error)

func (*Encoder) WriteUint32

func (e *Encoder) WriteUint32(i uint32, order binary.ByteOrder) (err error)

func (*Encoder) WriteUint64

func (e *Encoder) WriteUint64(i uint64, order binary.ByteOrder) (err error)

func (*Encoder) WriteUint8

func (e *Encoder) WriteUint8(i uint8) (err error)

func (*Encoder) WriteVarInt

func (e *Encoder) WriteVarInt(v int) (err error)

func (*Encoder) Written

func (e *Encoder) Written() int

Written returns the count of bytes written.

type Encoding

type Encoding int
const (
	EncodingBin Encoding = iota
	EncodingCompactU16
	EncodingBorsh
)

func (Encoding) IsBin

func (enc Encoding) IsBin() bool

func (Encoding) IsBorsh

func (enc Encoding) IsBorsh() bool

func (Encoding) IsCompactU16

func (enc Encoding) IsCompactU16() bool

func (Encoding) String

func (enc Encoding) String() string

type Float128

type Float128 Uint128

func (Float128) MarshalJSON

func (i Float128) MarshalJSON() (data []byte, err error)

func (Float128) MarshalWithEncoder

func (i Float128) MarshalWithEncoder(enc *Encoder) error

func (*Float128) UnmarshalJSON

func (i *Float128) UnmarshalJSON(data []byte) error

func (*Float128) UnmarshalWithDecoder

func (i *Float128) UnmarshalWithDecoder(dec *Decoder) error

type Int128

type Int128 Uint128

Int128

func (Int128) BigInt

func (i Int128) BigInt() *big.Int

func (Int128) DecimalString

func (i Int128) DecimalString() string

func (Int128) MarshalJSON

func (i Int128) MarshalJSON() (data []byte, err error)

func (Int128) MarshalWithEncoder

func (i Int128) MarshalWithEncoder(enc *Encoder) error

func (Int128) String

func (i Int128) String() string

func (*Int128) UnmarshalJSON

func (i *Int128) UnmarshalJSON(data []byte) error

func (*Int128) UnmarshalWithDecoder

func (i *Int128) UnmarshalWithDecoder(dec *Decoder) error

type InvalidDecoderError

type InvalidDecoderError struct {
	Type reflect.Type
}

An InvalidDecoderError describes an invalid argument passed to Decoder. (The argument to Decoder must be a non-nil pointer.)

func (*InvalidDecoderError) Error

func (e *InvalidDecoderError) Error() string

type TypeID

type TypeID [8]byte

TypeID defines the internal representation of an instruction type ID (or account type, etc. in anchor programs) and it's used to associate instructions to decoders in the variant tracker.

func TypeIDFromBytes

func TypeIDFromBytes(slice []byte) (id TypeID)

TypeIDFromBytes converts a []byte to a TypeID. The provided slice must be 8 bytes long or less.

func TypeIDFromUint32

func TypeIDFromUint32(v uint32, bo binary.ByteOrder) TypeID

TypeIDFromUint32 converts a uint32 to a TypeID.

func TypeIDFromUint8

func TypeIDFromUint8(v uint8) TypeID

TypeIDFromUint32 converts a uint8 to a TypeID.

func (TypeID) Bytes

func (vid TypeID) Bytes() []byte

func (TypeID) Uint32

func (vid TypeID) Uint32() uint32

Uint32 parses the TypeID to a uint32.

func (TypeID) Uint8

func (vid TypeID) Uint8() uint8

Uint8 parses the TypeID to a Uint8.

type Uint128

type Uint128 struct {
	Lo         uint64
	Hi         uint64
	Endianness binary.ByteOrder
}

Uint128

func NewUint128BigEndian

func NewUint128BigEndian() *Uint128

func NewUint128LittleEndian

func NewUint128LittleEndian() *Uint128

func (Uint128) BigInt

func (i Uint128) BigInt() *big.Int

func (Uint128) Bytes

func (i Uint128) Bytes() []byte

func (Uint128) DecimalString

func (i Uint128) DecimalString() string

func (Uint128) HexString

func (i Uint128) HexString() string

func (Uint128) MarshalJSON

func (i Uint128) MarshalJSON() (data []byte, err error)

func (Uint128) MarshalWithEncoder

func (i Uint128) MarshalWithEncoder(enc *Encoder) error

func (Uint128) String

func (i Uint128) String() string

func (*Uint128) UnmarshalJSON

func (i *Uint128) UnmarshalJSON(data []byte) error

func (*Uint128) UnmarshalWithDecoder

func (i *Uint128) UnmarshalWithDecoder(dec *Decoder) error

Jump to

Keyboard shortcuts

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