scale

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(in []byte, t interface{}) (interface{}, error)

Decode a byte array into interface

func DecodeCustom

func DecodeCustom(in []byte, t interface{}) error

DecodeCustom check if interface has method Decode, if so use that, otherwise use regular scale decoding

func DecodePtr

func DecodePtr(in []byte, t interface{}) error

DecodePtr a byte array into a interface pointer

func Encode

func Encode(in interface{}) ([]byte, error)

Encode returns the SCALE encoding of the given interface

func EncodeCustom

func EncodeCustom(in interface{}) ([]byte, error)

EncodeCustom checks if interface has method Encode, if so use that, otherwise use regular scale encoding

Types

type Decoder

type Decoder struct {
	Reader io.Reader
}

Decoder is a wrapping around io.Reader

func (*Decoder) Decode

func (sd *Decoder) Decode(t interface{}) (out interface{}, err error)

Decode is the high level function wrapping the specific type decoding functions

func (*Decoder) DecodeArray

func (sd *Decoder) DecodeArray(t interface{}) (interface{}, error)

DecodeArray decodes a fixed-length array

func (*Decoder) DecodeBigInt

func (sd *Decoder) DecodeBigInt() (output *big.Int, err error)

DecodeBigInt decodes a SCALE encoded byte array into a *big.Int Works for all integers, including ints > 2**64

func (*Decoder) DecodeBigIntArray

func (sd *Decoder) DecodeBigIntArray() ([]*big.Int, error)

DecodeBigIntArray decodes a byte array to an array of *big.Ints

func (*Decoder) DecodeBool

func (sd *Decoder) DecodeBool() (bool, error)

DecodeBool accepts a byte array representing a SCALE encoded bool and performs SCALE decoding of the bool then returns it. if invalid, return false and an error

func (*Decoder) DecodeBoolArray

func (sd *Decoder) DecodeBoolArray() ([]bool, error)

DecodeBoolArray decodes a byte array to an array of bools

func (*Decoder) DecodeByteArray

func (sd *Decoder) DecodeByteArray() (o []byte, err error)

DecodeByteArray accepts a byte array representing a SCALE encoded byte array and performs SCALE decoding of the byte array if the encoding is valid, it then returns the decoded byte array, the total number of input bytes decoded, and nil otherwise, it returns nil, 0, and error

func (*Decoder) DecodeCustom

func (sd *Decoder) DecodeCustom(t interface{}) (interface{}, error)

DecodeCustom check if interface has method Decode(io.Reader), if so use that, otherwise use regular scale decoding

func (*Decoder) DecodeFixedWidthInt

func (sd *Decoder) DecodeFixedWidthInt(t interface{}) (o interface{}, err error)

DecodeFixedWidthInt decodes integers < 2**32 by reading the bytes in little endian

func (*Decoder) DecodeIntArray

func (sd *Decoder) DecodeIntArray() ([]int, error)

DecodeIntArray decodes a byte array to an array of ints

func (*Decoder) DecodeInteger

func (sd *Decoder) DecodeInteger() (_ int64, err error)

DecodeInteger accepts a byte array representing a SCALE encoded integer and performs SCALE decoding of the int if the encoding is valid, it then returns (o, bytesDecoded, err) where o is the decoded integer, bytesDecoded is the number of input bytes decoded, and err is nil otherwise, it returns 0, 0, and error

func (*Decoder) DecodeInterface

func (sd *Decoder) DecodeInterface(t interface{}) (interface{}, error)

DecodeInterface will decode to interface

func (*Decoder) DecodePtr

func (sd *Decoder) DecodePtr(t interface{}) (err error)

DecodePtr is the high level function wrapping the specific type decoding functions The results of decode are written to t interface by reference (instead of returning

value as Decode does)

func (*Decoder) DecodePtrBigInt

func (sd *Decoder) DecodePtrBigInt(output *big.Int) (err error)

DecodePtrBigInt decodes a SCALE encoded byte array into a *big.Int

Changes the value of output to decoded value

Works for all integers, including ints > 2**64

func (*Decoder) DecodePtrBigIntArray

func (sd *Decoder) DecodePtrBigIntArray(output interface{}) error

DecodePtrBigIntArray decodes a byte array to an array of *big.Ints

writes value to output by reference

func (*Decoder) DecodePtrBool

func (sd *Decoder) DecodePtrBool(output interface{}) error

DecodePtrBool accepts a byte array representing a SCALE encoded bool and performs SCALE decoding of the bool then writes the result to output via reference. if invalid, false and an error

func (*Decoder) DecodePtrBoolArray

func (sd *Decoder) DecodePtrBoolArray(output interface{}) error

DecodePtrBoolArray decodes a byte array to an array of bools that is written to output by reference

func (*Decoder) DecodePtrByteArray

func (sd *Decoder) DecodePtrByteArray(output interface{}) error

DecodePtrByteArray accepts a byte array representing a SCALE encoded byte array and performs SCALE decoding of the byte array

func (*Decoder) DecodePtrFixedWidthInt

func (sd *Decoder) DecodePtrFixedWidthInt(t interface{}) (err error)

DecodePtrFixedWidthInt decodes integers < 2**32 by reading the bytes in little endian

and writes results by reference t

func (*Decoder) DecodePtrIntArray

func (sd *Decoder) DecodePtrIntArray(t interface{}) error

DecodePtrIntArray decodes a byte array to an array of ints

func (*Decoder) DecodeSlice added in v0.2.0

func (sd *Decoder) DecodeSlice(t interface{}) (interface{}, error)

DecodeSlice will decode a slice

func (*Decoder) DecodeStringArray

func (sd *Decoder) DecodeStringArray() ([]string, error)

DecodeStringArray will decode to string array

func (*Decoder) DecodeTuple

func (sd *Decoder) DecodeTuple(t interface{}) (interface{}, error)

DecodeTuple accepts a byte array representing the SCALE encoded tuple and an interface. This interface should be a pointer to a struct which the encoded tuple should be marshaled into. If it is a valid encoding for the struct, it returns the decoded struct, otherwise error, Note that we return the same interface that was passed to this function; this is because we are writing directly to the struct that is passed in, using reflect to get each of the fields.

func (*Decoder) DecodeUnsignedInteger

func (sd *Decoder) DecodeUnsignedInteger() (o uint64, err error)

DecodeUnsignedInteger will decode unsigned integer

func (*Decoder) ReadByte

func (sd *Decoder) ReadByte() (byte, error)

ReadByte reads the one byte from the buffer

type Encoder

type Encoder struct {
	Writer io.Writer
}

Encoder is a wrapping around io.Writer

func (*Encoder) Encode

func (se *Encoder) Encode(b interface{}) (n int, err error)

Encode is the top-level function which performs SCALE encoding of b which may be of type []byte, int16, int32, int64, or bool

func (*Encoder) EncodeCustom added in v0.2.0

func (se *Encoder) EncodeCustom(in interface{}) (int, error)

EncodeCustom checks if interface has method Encode, if so use that, otherwise return error

Jump to

Keyboard shortcuts

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