Documentation ¶
Index ¶
- Constants
- Variables
- func BinByteCount(v interface{}) (uint64, error)
- func BorshByteCount(v interface{}) (uint64, error)
- func CompactU16ByteCount(v interface{}) (uint64, error)
- func DecodeCompactU16(bytes []byte) (int, int, error)
- func DecodeCompactU16LengthFromByteReader(reader io.ByteReader) (int, error)
- func EncodeCompactU16Length(buf *[]byte, ln int) error
- func FormatByteSlice(buf []byte) string
- func FormatDiscriminator(disc [8]byte) string
- func IsByteSlice(v interface{}) bool
- func MarshalBin(v interface{}) ([]byte, error)
- func MarshalBorsh(v interface{}) ([]byte, error)
- func MarshalCompactU16(v interface{}) ([]byte, error)
- func MustBinByteCount(v interface{}) uint64
- func MustBorshByteCount(v interface{}) uint64
- func MustCompactU16ByteCount(v interface{}) uint64
- func ReverseBytes(s []byte)
- func Sighash(namespace string, name string) []byte
- func SighashAccount(name string) []byte
- func SighashInstruction(name string) []byte
- func ToPascalCase(s string) string
- func ToRustSnakeCase(s string) string
- func ToSnakeForSighash(s string) string
- func Uint32FromTypeID(vid TypeID, order binary.ByteOrder) (out uint32)
- func Uint8FromTypeID(vid TypeID) (out uint8)
- func UnmarshalBin(v interface{}, b []byte) error
- func UnmarshalBorsh(v interface{}, b []byte) error
- func UnmarshalCompactU16(v interface{}, b []byte) error
- func Uvarint32FromTypeID(vid TypeID) (out uint32)
- type BaseVariant
- type BinaryMarshaler
- type BinaryUnmarshaler
- type Bool
- type BorshEnum
- type Decoder
- func (dec *Decoder) Decode(v interface{}) (err error)
- func (dec *Decoder) Discard(n int) (err error)
- func (dec *Decoder) HasRemaining() bool
- func (dec *Decoder) IsBin() bool
- func (dec *Decoder) IsBorsh() bool
- func (dec *Decoder) IsCompactU16() bool
- func (dec *Decoder) Len() int
- func (dec *Decoder) Peek(n int) (out []byte, err error)
- func (dec *Decoder) PeekDiscriminator() (out TypeID, err error)
- func (dec *Decoder) Position() uint
- func (d *Decoder) Read(buf []byte) (int, error)
- func (dec *Decoder) ReadBool() (out bool, err error)
- func (dec *Decoder) ReadByte() (out byte, err error)
- func (dec *Decoder) ReadByteSlice() (out []byte, err error)
- func (dec *Decoder) ReadBytes(n int) (out []byte, err error)
- func (dec *Decoder) ReadCOption() (out bool, err error)
- func (dec *Decoder) ReadCompactU16() (out int, err error)
- func (dec *Decoder) ReadCompactU16Length() (int, error)
- func (dec *Decoder) ReadDiscriminator() (out TypeID, err error)
- func (dec *Decoder) ReadFloat128(order binary.ByteOrder) (out Float128, err error)
- func (dec *Decoder) ReadFloat32(order binary.ByteOrder) (out float32, err error)
- func (dec *Decoder) ReadFloat64(order binary.ByteOrder) (out float64, err error)
- func (dec *Decoder) ReadInt128(order binary.ByteOrder) (out Int128, err error)
- func (dec *Decoder) ReadInt16(order binary.ByteOrder) (out int16, err error)
- func (dec *Decoder) ReadInt32(order binary.ByteOrder) (out int32, err error)
- func (dec *Decoder) ReadInt64(order binary.ByteOrder) (out int64, err error)
- func (dec *Decoder) ReadInt8() (out int8, err error)
- func (dec *Decoder) ReadLength() (length int, err error)
- func (dec *Decoder) ReadNBytes(n int) (out []byte, err error)
- func (dec *Decoder) ReadOption() (out bool, err error)
- func (dec *Decoder) ReadRustString() (out string, err error)
- func (dec *Decoder) ReadString() (out string, err error)
- func (dec *Decoder) ReadTypeID() (out TypeID, err error)
- func (dec *Decoder) ReadUint128(order binary.ByteOrder) (out Uint128, err error)
- func (dec *Decoder) ReadUint16(order binary.ByteOrder) (out uint16, err error)
- func (dec *Decoder) ReadUint32(order binary.ByteOrder) (out uint32, err error)
- func (dec *Decoder) ReadUint64(order binary.ByteOrder) (out uint64, err error)
- func (dec *Decoder) ReadUint8() (out uint8, err error)
- func (dec *Decoder) ReadUvarint16() (out uint16, err error)
- func (dec *Decoder) ReadUvarint32() (out uint32, err error)
- func (dec *Decoder) ReadUvarint64() (uint64, error)
- func (dec *Decoder) ReadVarint16() (out int16, err error)
- func (dec *Decoder) ReadVarint32() (out int32, err error)
- func (d *Decoder) ReadVarint64() (out int64, err error)
- func (dec *Decoder) Remaining() int
- func (dec *Decoder) Reset(data []byte)
- func (dec *Decoder) SafeReadUTF8String() (out string, err error)
- func (dec *Decoder) SetEncoding(enc Encoding)
- func (dec *Decoder) SetPosition(idx uint) error
- func (dec *Decoder) SkipBytes(count uint) error
- type EmptyVariant
- type Encoder
- func (e *Encoder) Encode(v interface{}) (err error)
- func (enc *Encoder) IsBin() bool
- func (enc *Encoder) IsBorsh() bool
- func (enc *Encoder) IsCompactU16() bool
- func (e *Encoder) Write(b []byte) (n int, err error)
- func (e *Encoder) WriteBool(b bool) (err error)
- func (e *Encoder) WriteByte(b byte) (err error)
- func (e *Encoder) WriteBytes(b []byte, writeLength bool) error
- func (e *Encoder) WriteCOption(b bool) (err error)
- func (e *Encoder) WriteCompactU16(ln int) (err error)
- func (e *Encoder) WriteCompactU16Length(ln int) (err error)
- func (e *Encoder) WriteFloat32(f float32, order binary.ByteOrder) (err error)
- func (e *Encoder) WriteFloat64(f float64, order binary.ByteOrder) (err error)
- func (e *Encoder) WriteInt128(i Int128, order binary.ByteOrder) (err error)
- func (e *Encoder) WriteInt16(i int16, order binary.ByteOrder) (err error)
- func (e *Encoder) WriteInt32(i int32, order binary.ByteOrder) (err error)
- func (e *Encoder) WriteInt64(i int64, order binary.ByteOrder) (err error)
- func (e *Encoder) WriteInt8(i int8) (err error)
- func (e *Encoder) WriteLength(length int) error
- func (e *Encoder) WriteOption(b bool) (err error)
- func (e *Encoder) WriteRustString(s string) (err error)
- func (e *Encoder) WriteString(s string) (err error)
- func (e *Encoder) WriteUVarInt(v int) (err error)
- func (e *Encoder) WriteUint128(i Uint128, order binary.ByteOrder) (err error)
- func (e *Encoder) WriteUint16(i uint16, order binary.ByteOrder) (err error)
- func (e *Encoder) WriteUint32(i uint32, order binary.ByteOrder) (err error)
- func (e *Encoder) WriteUint64(i uint64, order binary.ByteOrder) (err error)
- func (e *Encoder) WriteUint8(i uint8) (err error)
- func (e *Encoder) WriteVarInt(v int) (err error)
- func (e *Encoder) Written() int
- type EncoderDecoder
- type Encoding
- type Float128
- type HexBytes
- type Int128
- func (i Int128) BigInt() *big.Int
- func (i Int128) DecimalString() string
- func (i Int128) MarshalJSON() (data []byte, err error)
- func (i Int128) MarshalWithEncoder(enc *Encoder) error
- func (i Int128) String() string
- func (i *Int128) UnmarshalJSON(data []byte) error
- func (i *Int128) UnmarshalWithDecoder(dec *Decoder) error
- type Int64
- type InvalidDecoderError
- type JSONFloat64
- type OnVariant
- type SafeString
- type TypeID
- type TypeIDEncoding
- type Uint128
- func (i Uint128) BigInt() *big.Int
- func (i Uint128) Bytes() []byte
- func (i Uint128) DecimalString() string
- func (i Uint128) HexString() string
- func (i Uint128) MarshalJSON() (data []byte, err error)
- func (i Uint128) MarshalWithEncoder(enc *Encoder) error
- func (i Uint128) String() string
- func (i *Uint128) UnmarshalJSON(data []byte) error
- func (i *Uint128) UnmarshalWithDecoder(dec *Decoder) error
- type Uint64
- type Variant
- type VariantDefinition
- type VariantImplFactory
- type VariantType
- type Varint16
- type Varint32
- type Varuint16
- type Varuint32
- type WriteByWrite
Constants ¶
const ACCOUNT_DISCRIMINATOR_SIZE = 8
const SIGHASH_ACCOUNT_NAMESPACE string = "account"
const SIGHASH_GLOBAL_NAMESPACE string = "global"
Namespace for calculating instruction sighash signatures for any instruction not affecting program state.
const SIGHASH_STATE_NAMESPACE string = "state"
Namespace for calculating state instruction sighash signatures.
Variables ¶
var ( LE binary.ByteOrder = binary.LittleEndian BE binary.ByteOrder = binary.BigEndian )
var ErrVarIntBufferSize = errors.New("varint: invalid buffer size")
var NoTypeIDDefaultID = TypeIDFromUint8(0)
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 }{ Byte: 1, Bool: 1, Int8: 1, Int16: 2, Uint8: 1, Uint16: 2, Uint32: 4, Uint64: 8, Uint128: 16, Float32: 4, Float64: 8, PublicKey: 32, Signature: 64, }
Functions ¶
func BinByteCount ¶
BinByteCount computes the byte count size for the received populated structure. The reported size is the one for the populated structure received in arguments. Depending on how serialization of your fields is performed, size could vary for different structure.
func BorshByteCount ¶
BorshByteCount computes the byte count size for the received populated structure. The reported size is the one for the populated structure received in arguments. Depending on how serialization of your fields is performed, size could vary for different structure.
func CompactU16ByteCount ¶
CompactU16ByteCount computes the byte count size for the received populated structure. The reported size is the one for the populated structure received in arguments. Depending on how serialization of your fields is performed, size could vary for different structure.
func DecodeCompactU16LengthFromByteReader ¶
func DecodeCompactU16LengthFromByteReader(reader io.ByteReader) (int, error)
DecodeCompactU16LengthFromByteReader decodes a "Compact-u16" length from the provided io.ByteReader.
func EncodeCompactU16Length ¶
EncodeCompactU16Length encodes a "Compact-u16" length into the provided slice pointer. See https://docs.solana.com/developing/programming-model/transactions#compact-u16-format See https://github.com/solana-labs/solana/blob/2ef2b6daa05a7cff057e9d3ef95134cee3e4045d/web3.js/src/util/shortvec-encoding.ts
func FormatByteSlice ¶
FormatByteSlice formats the given byte slice into a readable format.
func FormatDiscriminator ¶ added in v0.7.4
func IsByteSlice ¶
func IsByteSlice(v interface{}) bool
IsByteSlice returns true if the provided element is a []byte.
func MarshalBin ¶
func MarshalBorsh ¶
func MarshalCompactU16 ¶
func MustBinByteCount ¶
func MustBinByteCount(v interface{}) uint64
MustBinByteCount acts just like BinByteCount but panics if it encounters any encoding errors.
func MustBorshByteCount ¶
func MustBorshByteCount(v interface{}) uint64
MustBorshByteCount acts just like BorshByteCount but panics if it encounters any encoding errors.
func MustCompactU16ByteCount ¶
func MustCompactU16ByteCount(v interface{}) uint64
MustCompactU16ByteCount acts just like CompactU16ByteCount but panics if it encounters any encoding errors.
func ReverseBytes ¶ added in v0.6.0
func ReverseBytes(s []byte)
func Sighash ¶
Sighash creates an anchor sighash for the provided namespace and element. An anchor sighash is the first 8 bytes of the sha256 of {namespace}:{name} NOTE: you must first convert the name to snake case using `ToSnakeForSighash`.
func SighashAccount ¶ added in v0.7.2
func SighashInstruction ¶ added in v0.7.2
func ToPascalCase ¶ added in v0.7.6
ToPascalCase converts a string to upper camel case.
func ToRustSnakeCase ¶ added in v0.7.2
ToRustSnakeCase converts the given string to a snake_case string. Ported from https://github.com/withoutboats/heck/blob/c501fc95db91ce20eaef248a511caec7142208b4/src/lib.rs#L75 as used by Anchor.
func ToSnakeForSighash ¶ added in v0.7.2
func Uint32FromTypeID ¶
Uint32FromTypeID parses a TypeID bytes to a uint32.
func Uint8FromTypeID ¶
Uint32FromTypeID parses a TypeID bytes to a uint8.
func UnmarshalBin ¶
func UnmarshalBorsh ¶
func UnmarshalCompactU16 ¶
func Uvarint32FromTypeID ¶
Uvarint32FromTypeID parses a TypeID bytes to a uvarint 32.
Types ¶
type BaseVariant ¶
type BaseVariant struct { TypeID TypeID Impl interface{} }
func (*BaseVariant) Assign ¶
func (a *BaseVariant) Assign(typeID TypeID, impl interface{})
func (*BaseVariant) Obtain ¶
func (a *BaseVariant) Obtain(def *VariantDefinition) (typeID TypeID, typeName string, impl interface{})
func (*BaseVariant) UnmarshalBinaryVariant ¶
func (a *BaseVariant) UnmarshalBinaryVariant(decoder *Decoder, def *VariantDefinition) (err error)
type BinaryMarshaler ¶
type BinaryUnmarshaler ¶
type Bool ¶
type Bool bool
func (Bool) MarshalWithEncoder ¶
func (*Bool) UnmarshalJSON ¶
func (*Bool) UnmarshalWithDecoder ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewBinDecoder ¶
func NewBorshDecoder ¶
func NewCompactU16Decoder ¶
func NewDecoderWithEncoding ¶
func (*Decoder) HasRemaining ¶
func (*Decoder) IsCompactU16 ¶
func (*Decoder) PeekDiscriminator ¶ added in v0.7.5
func (*Decoder) ReadByteSlice ¶
func (*Decoder) ReadCOption ¶ added in v0.7.3
func (*Decoder) ReadCompactU16 ¶ added in v0.7.2
ReadCompactU16 reads a compact u16 from the decoder.
func (*Decoder) ReadCompactU16Length ¶
func (*Decoder) ReadDiscriminator ¶ added in v0.7.3
func (*Decoder) ReadFloat128 ¶
func (*Decoder) ReadFloat32 ¶
func (*Decoder) ReadFloat64 ¶
func (*Decoder) ReadInt128 ¶
func (*Decoder) ReadLength ¶ added in v0.5.0
func (*Decoder) ReadOption ¶ added in v0.7.3
func (*Decoder) ReadRustString ¶ added in v0.5.1
func (*Decoder) ReadString ¶
func (*Decoder) ReadTypeID ¶
func (*Decoder) ReadUint128 ¶
func (*Decoder) ReadUint16 ¶
func (*Decoder) ReadUint32 ¶
func (*Decoder) ReadUint64 ¶
func (*Decoder) ReadUvarint16 ¶
func (*Decoder) ReadUvarint32 ¶
func (*Decoder) ReadUvarint64 ¶
func (*Decoder) ReadVarint16 ¶
func (*Decoder) ReadVarint32 ¶
func (*Decoder) ReadVarint64 ¶
func (*Decoder) SafeReadUTF8String ¶
func (*Decoder) SetEncoding ¶ added in v0.7.2
SetEncoding sets the encoding scheme to use for decoding.
func (*Decoder) SetPosition ¶
type EmptyVariant ¶ added in v0.7.0
type EmptyVariant struct{}
EmptyVariant is an empty borsh enum variant.
func (*EmptyVariant) MarshalWithEncoder ¶ added in v0.7.0
func (*EmptyVariant) MarshalWithEncoder(_ *Encoder) error
func (*EmptyVariant) UnmarshalWithDecoder ¶ added in v0.7.0
func (*EmptyVariant) UnmarshalWithDecoder(_ *Decoder) error
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewBinEncoder ¶
func NewBorshEncoder ¶
func NewCompactU16Encoder ¶
func (*Encoder) IsCompactU16 ¶
func (*Encoder) WriteCOption ¶ added in v0.7.3
func (*Encoder) WriteCompactU16 ¶ added in v0.7.9
func (*Encoder) WriteCompactU16Length ¶
func (*Encoder) WriteFloat32 ¶
func (*Encoder) WriteFloat64 ¶
func (*Encoder) WriteInt128 ¶
func (*Encoder) WriteInt16 ¶
func (*Encoder) WriteInt32 ¶
func (*Encoder) WriteInt64 ¶
func (*Encoder) WriteLength ¶ added in v0.5.0
func (*Encoder) WriteOption ¶ added in v0.7.3
func (*Encoder) WriteRustString ¶ added in v0.5.1
func (*Encoder) WriteString ¶
func (*Encoder) WriteUVarInt ¶
func (*Encoder) WriteUint128 ¶
func (*Encoder) WriteUint16 ¶
func (*Encoder) WriteUint32 ¶
func (*Encoder) WriteUint64 ¶
func (*Encoder) WriteUint8 ¶
func (*Encoder) WriteVarInt ¶
type EncoderDecoder ¶
type EncoderDecoder interface { BinaryMarshaler BinaryUnmarshaler }
type Float128 ¶
type Float128 Uint128
func (Float128) MarshalJSON ¶
func (Float128) MarshalWithEncoder ¶
func (*Float128) UnmarshalJSON ¶
func (*Float128) UnmarshalWithDecoder ¶
type HexBytes ¶
type HexBytes []byte
func (HexBytes) MarshalJSON ¶
func (HexBytes) MarshalWithEncoder ¶
func (*HexBytes) UnmarshalJSON ¶
func (*HexBytes) UnmarshalWithDecoder ¶
type Int128 ¶
type Int128 Uint128
Int128
func (Int128) DecimalString ¶
func (Int128) MarshalJSON ¶
func (Int128) MarshalWithEncoder ¶
func (*Int128) UnmarshalJSON ¶
func (*Int128) UnmarshalWithDecoder ¶
type Int64 ¶
type Int64 int64
func (Int64) MarshalJSON ¶
func (Int64) MarshalWithEncoder ¶
func (*Int64) UnmarshalJSON ¶
func (*Int64) UnmarshalWithDecoder ¶
type InvalidDecoderError ¶
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 JSONFloat64 ¶
type JSONFloat64 float64
func (JSONFloat64) MarshalWithEncoder ¶
func (f JSONFloat64) MarshalWithEncoder(enc *Encoder) error
func (*JSONFloat64) UnmarshalJSON ¶
func (f *JSONFloat64) UnmarshalJSON(data []byte) error
func (*JSONFloat64) UnmarshalWithDecoder ¶
func (f *JSONFloat64) UnmarshalWithDecoder(dec *Decoder) error
type SafeString ¶
type SafeString string
func (SafeString) MarshalWithEncoder ¶
func (ss SafeString) MarshalWithEncoder(encoder *Encoder) error
func (*SafeString) UnmarshalWithDecoder ¶
func (ss *SafeString) UnmarshalWithDecoder(d *Decoder) error
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 SighashTypeID ¶
NOTE: no casing conversion is done here, it's up to the caller to provide the correct casing.
func TypeIDFromBytes ¶
TypeIDFromBytes converts a []byte to a TypeID. The provided slice must be 8 bytes long or less.
func TypeIDFromSighash ¶
TypeIDFromSighash converts a sighash bytes to a TypeID.
func TypeIDFromUint32 ¶
TypeIDFromUint32 converts a uint32 to a TypeID.
func TypeIDFromUint8 ¶
TypeIDFromUint32 converts a uint8 to a TypeID.
func TypeIDFromUvarint32 ¶
TypeIDFromUvarint32 converts a Uvarint to a TypeID.
type TypeIDEncoding ¶
type TypeIDEncoding uint32
const ( Uvarint32TypeIDEncoding TypeIDEncoding = iota Uint32TypeIDEncoding Uint8TypeIDEncoding // AnchorTypeIDEncoding is the instruction ID encoding used by programs // written using the anchor SDK. // The typeID is the sighash of the instruction. AnchorTypeIDEncoding // No type ID; ONLY ONE VARIANT PER PROGRAM. NoTypeIDEncoding )
type Uint128 ¶
Uint128
func NewUint128BigEndian ¶ added in v0.6.0
func NewUint128BigEndian() *Uint128
func NewUint128LittleEndian ¶ added in v0.6.0
func NewUint128LittleEndian() *Uint128
func (Uint128) DecimalString ¶
func (Uint128) MarshalJSON ¶
func (Uint128) MarshalWithEncoder ¶
func (*Uint128) UnmarshalJSON ¶
func (*Uint128) UnmarshalWithDecoder ¶
type Uint64 ¶
type Uint64 uint64
func (Uint64) MarshalJSON ¶
func (Uint64) MarshalWithEncoder ¶
func (*Uint64) UnmarshalJSON ¶
func (*Uint64) UnmarshalWithDecoder ¶
type Variant ¶
type Variant interface { Assign(typeID TypeID, impl interface{}) Obtain(*VariantDefinition) (typeID TypeID, typeName string, impl interface{}) }
type VariantDefinition ¶
type VariantDefinition struct {
// contains filtered or unexported fields
}
func NewVariantDefinition ¶
func NewVariantDefinition(typeIDEncoding TypeIDEncoding, types []VariantType) (out *VariantDefinition)
NewVariantDefinition creates a variant definition based on the *ordered* provided types.
- For anchor instructions, it's the name that defines the binary variant value.
- For all other types, it's the ordering that defines the binary variant value just like in native `nodeos` C++ and in Smart Contract via the `std::variant` type. It's important to pass the entries in the right order!
This variant definition can now be passed to functions of `BaseVariant` to implement marshal/unmarshaling functionalities for binary & JSON.
func (*VariantDefinition) TypeID ¶
func (d *VariantDefinition) TypeID(name string) TypeID
type VariantImplFactory ¶
type VariantImplFactory = func() interface{}
type VariantType ¶
type VariantType struct { Name string Type interface{} }
type Varint16 ¶
type Varint16 int16
func (Varint16) MarshalWithEncoder ¶
func (*Varint16) UnmarshalWithDecoder ¶
type Varint32 ¶
type Varint32 int32
func (Varint32) MarshalWithEncoder ¶
func (*Varint32) UnmarshalWithDecoder ¶
type Varuint16 ¶
type Varuint16 uint16
func (Varuint16) MarshalWithEncoder ¶
func (*Varuint16) UnmarshalWithDecoder ¶
type Varuint32 ¶
type Varuint32 uint32
func (Varuint32) MarshalWithEncoder ¶
func (*Varuint32) UnmarshalWithDecoder ¶
type WriteByWrite ¶
type WriteByWrite struct {
// contains filtered or unexported fields
}
func NewWriteByWrite ¶
func NewWriteByWrite(name string) *WriteByWrite
func (*WriteByWrite) Bytes ¶
func (rec *WriteByWrite) Bytes() []byte
func (WriteByWrite) String ¶
func (rec WriteByWrite) String() string