Documentation ¶
Index ¶
- Constants
- Variables
- func BytesReverse(u []byte) []byte
- func BytesToHexString(data []byte) string
- func BytesToInt16(b []byte) int16
- func ClearBytes(arr []byte)
- func FromReversedString(reversed string) ([]byte, error)
- func FuncError(f string, desc string) error
- func GetIpFromAddr(addr string) string
- func Goid() string
- func HexStringToBytes(value string) ([]byte, error)
- func IntToBytes(n int) []byte
- func IsLetterOrNumber(s string) bool
- func ReadBytes(r io.Reader, length uint64) ([]byte, error)
- func ReadElement(r io.Reader, element interface{}) (err error)
- func ReadElements(r io.Reader, elements ...interface{}) error
- func ReadUint16(r io.Reader) (uint16, error)
- func ReadUint32(r io.Reader) (uint32, error)
- func ReadUint64(r io.Reader) (uint64, error)
- func ReadUint8(r io.Reader) (uint8, error)
- func ReadVarBytes(r io.Reader, maxAllowed uint32, fieldName string) ([]byte, error)
- func ReadVarString(r io.Reader) (string, error)
- func ReadVarUint(r io.Reader, pver uint32) (uint64, error)
- func Sha256D(data []byte) [32]byte
- func SortProgramHashByCodeHash(hashes []Uint168)
- func SortUint160(hashes []Uint160)
- func ToReversedString(hash Uint256) string
- func VarIntSerializeSize(val uint64) int
- func VarUintSerializeSize(val uint64) int
- func WriteElement(w io.Writer, element interface{}) (err error)
- func WriteElements(w io.Writer, elements ...interface{}) error
- func WriteUint16(w io.Writer, val uint16) error
- func WriteUint32(w io.Writer, val uint32) error
- func WriteUint64(w io.Writer, val uint64) error
- func WriteUint8(w io.Writer, val uint8) error
- func WriteVarBytes(w io.Writer, bytes []byte) error
- func WriteVarString(w io.Writer, str string) error
- func WriteVarUint(w io.Writer, val uint64) error
- type BinaryFreeList
- func (l BinaryFreeList) Borrow() []byte
- func (l BinaryFreeList) PutUint16(w io.Writer, byteOrder binary.ByteOrder, val uint16) error
- func (l BinaryFreeList) PutUint32(w io.Writer, byteOrder binary.ByteOrder, val uint32) error
- func (l BinaryFreeList) PutUint64(w io.Writer, byteOrder binary.ByteOrder, val uint64) error
- func (l BinaryFreeList) PutUint8(w io.Writer, val uint8) error
- func (l BinaryFreeList) Return(buf []byte)
- func (l BinaryFreeList) Uint16(r io.Reader, byteOrder binary.ByteOrder) (uint16, error)
- func (l BinaryFreeList) Uint32(r io.Reader, byteOrder binary.ByteOrder) (uint32, error)
- func (l BinaryFreeList) Uint64(r io.Reader, byteOrder binary.ByteOrder) (uint64, error)
- func (l BinaryFreeList) Uint8(r io.Reader) (uint8, error)
- type Fixed64
- type Serializable
- type Uint160
- type Uint168
- func (u Uint168) Bytes() []byte
- func (u Uint168) Compare(o Uint168) int
- func (u *Uint168) Deserialize(r io.Reader) error
- func (u Uint168) IsEqual(o Uint168) bool
- func (u *Uint168) Serialize(w io.Writer) error
- func (u Uint168) String() string
- func (u Uint168) ToAddress() (string, error)
- func (u Uint168) ToCodeHash() Uint160
- type Uint256
Constants ¶
const ( UINT168SIZE = 21 // Address types STANDARD = 0xAC DID = 0xAD MULTISIG = 0xAE CROSSCHAIN = 0xAF )
const ( // MaxVarStringLength is the maximum bytes a var string. MaxVarStringLength = 1024 * 1024 * 16 // 16MB )
const UINT160SIZE int = 20
const UINT256SIZE = 32
Variables ¶
var EmptyHash = Uint256{}
var EmptyProgramHash = Uint168{}
Functions ¶
func BytesReverse ¶
func BytesToHexString ¶
func BytesToInt16 ¶ added in v0.2.2
func ClearBytes ¶ added in v0.2.2
func ClearBytes(arr []byte)
func FromReversedString ¶ added in v0.7.0
func GetIpFromAddr ¶ added in v0.8.0
get ip string from addr string if addr is not the format x.x.x.x:port return empt string ""
func HexStringToBytes ¶
func IntToBytes ¶ added in v0.2.2
func IsLetterOrNumber ¶ added in v0.8.0
check if the string is only letter or number.
func ReadElement ¶ added in v0.2.2
readElement reads the next sequence of bytes from r using little endian depending on the concrete type of element pointed to.
func ReadElements ¶ added in v0.2.2
ReadElements reads multiple items from r. It is equivalent to multiple calls to ReadElement.
func ReadVarBytes ¶ added in v0.2.2
func ReadVarUint ¶ added in v0.2.2
ReadVarUint reads a variable length integer from r and returns it as a uint64.
func SortProgramHashByCodeHash ¶ added in v0.2.2
func SortProgramHashByCodeHash(hashes []Uint168)
func SortUint160 ¶ added in v0.2.2
func SortUint160(hashes []Uint160)
func ToReversedString ¶ added in v0.7.0
func VarIntSerializeSize ¶ added in v0.5.0
VarIntSerializeSize returns the number of bytes it would take to serialize val as a variable length integer.
func VarUintSerializeSize ¶ added in v0.2.2
VarUintSerializeSize returns the number of bytes it would take to serialize val as a variable length integer.
func WriteElement ¶ added in v0.2.2
WriteElement writes the little endian representation of element to w.
func WriteElements ¶ added in v0.2.2
WriteElements writes multiple items to w. It is equivalent to multiple calls to WriteElement.
Types ¶
type BinaryFreeList ¶ added in v0.5.0
type BinaryFreeList chan []byte
BinaryFreeList defines a concurrent safe free list of byte slices (up to the maximum number defined by the binaryFreeListMaxItems constant) that have a cap of 8 (thus it supports up to a uint64). It is used to provide temporary buffers for serializing and deserializing primitive numbers to and from their binary encoding in order to greatly reduce the number of allocations required.
For convenience, functions are provided for each of the primitive unsigned integers that automatically obtain a buffer from the free list, perform the necessary binary conversion, read from or write to the given io.Reader or io.Writer, and return the buffer to the free list.
var BinarySerializer BinaryFreeList = make(chan []byte, binaryFreeListMaxItems)
BinarySerializer provides a free list of buffers to use for serializing and deserializing primitive integer values to and from io.Readers and io.Writers.
func (BinaryFreeList) Borrow ¶ added in v0.5.0
func (l BinaryFreeList) Borrow() []byte
Borrow returns a byte slice from the free list with a length of 8. A new buffer is allocated if there are not any available on the free list.
func (BinaryFreeList) PutUint16 ¶ added in v0.5.0
PutUint16 serializes the provided uint16 using the given byte order into a buffer from the free list and writes the resulting two bytes to the given writer.
func (BinaryFreeList) PutUint32 ¶ added in v0.5.0
PutUint32 serializes the provided uint32 using the given byte order into a buffer from the free list and writes the resulting four bytes to the given writer.
func (BinaryFreeList) PutUint64 ¶ added in v0.5.0
PutUint64 serializes the provided uint64 using the given byte order into a buffer from the free list and writes the resulting eight bytes to the given writer.
func (BinaryFreeList) PutUint8 ¶ added in v0.5.0
func (l BinaryFreeList) PutUint8(w io.Writer, val uint8) error
PutUint8 copies the provided uint8 into a buffer from the free list and writes the resulting byte to the given writer.
func (BinaryFreeList) Return ¶ added in v0.5.0
func (l BinaryFreeList) Return(buf []byte)
Return puts the provided byte slice back on the free list. The buffer MUST have been obtained via the Borrow function and therefore have a cap of 8.
func (BinaryFreeList) Uint16 ¶ added in v0.5.0
Uint16 reads two bytes from the provided reader using a buffer from the free list, converts it to a number using the provided byte order, and returns the resulting uint16.
func (BinaryFreeList) Uint32 ¶ added in v0.5.0
Uint32 reads four bytes from the provided reader using a buffer from the free list, converts it to a number using the provided byte order, and returns the resulting uint32.
type Fixed64 ¶
type Fixed64 int64
the 64 bit fixed-point number, precise 10^-8
func Fixed64FromBytes ¶ added in v0.2.2
func StringToFixed64 ¶ added in v0.2.2
type Serializable ¶ added in v0.2.2
type Serializable interface { //Write data to writer Serialize(w io.Writer) error //read data to reader Deserialize(r io.Reader) error }
Serializable describe the data need be serialized.
type Uint160 ¶ added in v0.2.2
type Uint160 [UINT160SIZE]uint8
func ToCodeHash ¶ added in v0.2.2
func Uint160FromBytes ¶ added in v0.2.2
type Uint168 ¶
type Uint168 [UINT168SIZE]uint8
func ToProgramHash ¶ added in v0.2.2
func Uint168FromAddress ¶ added in v0.2.2
func Uint168FromBytes ¶
func Uint168FromCodeHash ¶ added in v0.2.2
func (Uint168) ToCodeHash ¶ added in v0.2.2
type Uint256 ¶
type Uint256 [UINT256SIZE]uint8