common

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2020 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

* Copyright (C) 2018 The ontology Authors * This file is part of The ontology library. * * The ontology is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The ontology is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with The ontology. If not, see <http://www.gnu.org/licenses/>.

* Copyright (C) 2018 The ontology Authors * This file is part of The ontology library. * * The ontology is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * The ontology is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with The ontology. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	UINT16_SIZE  = 2
	UINT32_SIZE  = 4
	UINT64_SIZE  = 8
	UINT256_SIZE = 32
)
View Source
const ADDR_LEN = 20
View Source
const (
	Decimal = 100000000
)
View Source
const I128_SIZE = 16
View Source
const (
	MAX_UINT64 = math.MaxUint64
)
View Source
const MaxBase58AddrLen = 2048 // just to avoid dos

Variables

View Source
var ADDRESS_EMPTY = Address{}
View Source
var ErrIrregularData = errors.New("irregular data")
View Source
var ErrTooLarge = errors.New("bytes.Buffer: too large")
View Source
var ErrWriteExceedLimitedCount = errors.New("writer exceed limited count")
View Source
var U128_EMPTY = U128{}
View Source
var UINT256_EMPTY = Uint256{}

Functions

func BigIntFromNeoBytes

func BigIntFromNeoBytes(ba []byte) *big.Int

func FileExisted

func FileExisted(filename string) bool

FileExisted checks whether filename exists in filesystem

func GetNonce

func GetNonce() uint64

GetNonce returns random nonce

func HexToBytes

func HexToBytes(value string) ([]byte, error)

HexToBytes convert hex string to []byte

func SafeAdd

func SafeAdd(x, y uint64) (uint64, bool)

func SafeMul

func SafeMul(x, y uint64) (uint64, bool)

func SafeSub

func SafeSub(x, y uint64) (uint64, bool)

func SerializeToBytes

func SerializeToBytes(values ...Serializable) []byte

func ToArrayReverse

func ToArrayReverse(arr []byte) []byte

func ToHexString

func ToHexString(data []byte) string

ToHexString convert []byte to hex string

Types

type Address

type Address [ADDR_LEN]byte

func AddressFromBase58

func AddressFromBase58(encoded string) (Address, error)

AddressFromBase58 returns Address from encoded base58 string

func AddressFromHexString

func AddressFromHexString(s string) (Address, error)

AddressParseFromHexString returns parsed Address

func AddressFromVmCode

func AddressFromVmCode(code []byte) Address

func AddressParseFromBytes

func AddressParseFromBytes(f []byte) (Address, error)

AddressParseFromBytes returns parsed Address

func (*Address) Deserialization

func (self *Address) Deserialization(source *ZeroCopySource) error

Deserialize deserialize Address from io.Reader

func (*Address) Serialization

func (self *Address) Serialization(sink *ZeroCopySink)

Serialize serialize Address into io.Writer

func (*Address) ToBase58

func (f *Address) ToBase58() string

ToBase58 returns base58 encoded address string

func (*Address) ToHexString

func (self *Address) ToHexString() string

ToHexString returns hex string representation of Address

type Fixed64

type Fixed64 int64

the 64 bit fixed-point number, precise 10^-8

func FromDecimal

func FromDecimal(value int64) Fixed64

func (*Fixed64) Deserialization

func (f *Fixed64) Deserialization(source *ZeroCopySource) error

func (Fixed64) GetData

func (f Fixed64) GetData() int64

func (*Fixed64) Serialization

func (f *Fixed64) Serialization(sink *ZeroCopySink)

func (Fixed64) String

func (f Fixed64) String() string

type I128

type I128 [I128_SIZE]byte // little endian i128

func I128FromBigInt

func I128FromBigInt(val *big.Int) (I128, error)

val should in i128 range

func I128FromInt64

func I128FromInt64(val int64) I128

func I128FromUint64

func I128FromUint64(val uint64) I128

func (*I128) ToBEHex

func (self *I128) ToBEHex() string

to big endian hex string

func (I128) ToBigInt

func (self I128) ToBigInt() *big.Int

func (*I128) ToLEHex

func (self *I128) ToLEHex() string

to little endian hex string

func (*I128) ToNumString

func (self *I128) ToNumString() string

type InventoryType

type InventoryType byte
const (
	TRANSACTION InventoryType = 0x01
	BLOCK       InventoryType = 0x02
	CONSENSUS   InventoryType = 0xe0
)

type LimitedWriter

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

func NewLimitedWriter

func NewLimitedWriter(w io.Writer, max uint64) *LimitedWriter

func (*LimitedWriter) Count

func (self *LimitedWriter) Count() uint64

Count function return counted bytes

func (*LimitedWriter) Write

func (self *LimitedWriter) Write(buf []byte) (int, error)

type Serializable

type Serializable interface {
	Serialization(sink *ZeroCopySink)
}

type U128

type U128 [I128_SIZE]byte // little endian u128

func (U128) ToBigInt

func (self U128) ToBigInt() *big.Int

func (U128) ToI128

func (self U128) ToI128() I128

type Uint256

type Uint256 [UINT256_SIZE]byte

func ComputeMerkleRoot

func ComputeMerkleRoot(hashes []Uint256) Uint256

param hashes will be used as workspace

func Uint256FromHexString

func Uint256FromHexString(s string) (Uint256, error)

func Uint256ParseFromBytes

func Uint256ParseFromBytes(f []byte) (Uint256, error)

func (*Uint256) Deserialize

func (u *Uint256) Deserialize(r io.Reader) error

func (*Uint256) Serialize

func (u *Uint256) Serialize(w io.Writer) error

func (*Uint256) ToArray

func (u *Uint256) ToArray() []byte

func (*Uint256) ToHexString

func (u *Uint256) ToHexString() string

type ZeroCopySink

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

func NewZeroCopySink

func NewZeroCopySink(b []byte) *ZeroCopySink

NewReader returns a new ZeroCopySink reading from b.

func (*ZeroCopySink) BackUp

func (self *ZeroCopySink) BackUp(n uint64)

Backs up a number of bytes, so that the next call to NextXXX() returns data again that was already returned by the last call to NextXXX().

func (*ZeroCopySink) Bytes

func (self *ZeroCopySink) Bytes() []byte

func (*ZeroCopySink) NextBytes

func (self *ZeroCopySink) NextBytes(n uint64) (data []byte)

func (*ZeroCopySink) Reset

func (self *ZeroCopySink) Reset()

func (*ZeroCopySink) Size

func (self *ZeroCopySink) Size() uint64

func (*ZeroCopySink) WriteAddress

func (self *ZeroCopySink) WriteAddress(addr Address)

func (*ZeroCopySink) WriteBool

func (self *ZeroCopySink) WriteBool(data bool)

func (*ZeroCopySink) WriteByte

func (self *ZeroCopySink) WriteByte(c byte)

func (*ZeroCopySink) WriteBytes

func (self *ZeroCopySink) WriteBytes(p []byte)

func (*ZeroCopySink) WriteHash

func (self *ZeroCopySink) WriteHash(hash Uint256)

func (*ZeroCopySink) WriteI128

func (self *ZeroCopySink) WriteI128(i128 I128)

func (*ZeroCopySink) WriteInt16

func (self *ZeroCopySink) WriteInt16(data int16)

func (*ZeroCopySink) WriteInt32

func (self *ZeroCopySink) WriteInt32(data int32)

func (*ZeroCopySink) WriteInt64

func (self *ZeroCopySink) WriteInt64(data int64)

func (*ZeroCopySink) WriteString

func (self *ZeroCopySink) WriteString(data string) (size uint64)

func (*ZeroCopySink) WriteU128

func (self *ZeroCopySink) WriteU128(u128 U128)

func (*ZeroCopySink) WriteUint16

func (self *ZeroCopySink) WriteUint16(data uint16)

func (*ZeroCopySink) WriteUint32

func (self *ZeroCopySink) WriteUint32(data uint32)

func (*ZeroCopySink) WriteUint64

func (self *ZeroCopySink) WriteUint64(data uint64)

func (*ZeroCopySink) WriteUint8

func (self *ZeroCopySink) WriteUint8(data uint8)

func (*ZeroCopySink) WriteVarBytes

func (self *ZeroCopySink) WriteVarBytes(data []byte) (size uint64)

func (*ZeroCopySink) WriteVarUint

func (self *ZeroCopySink) WriteVarUint(data uint64) (size uint64)

type ZeroCopySource

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

func NewZeroCopySource

func NewZeroCopySource(b []byte) *ZeroCopySource

NewReader returns a new ZeroCopySource reading from b.

func (*ZeroCopySource) BackUp

func (self *ZeroCopySource) BackUp(n uint64)

Backs up a number of bytes, so that the next call to NextXXX() returns data again that was already returned by the last call to NextXXX().

func (*ZeroCopySource) Len

func (self *ZeroCopySource) Len() uint64

Len returns the number of bytes of the unread portion of the slice.

func (*ZeroCopySource) NextAddress

func (self *ZeroCopySource) NextAddress() (data Address, eof bool)

func (*ZeroCopySource) NextBool

func (self *ZeroCopySource) NextBool() (data bool, irregular bool, eof bool)

func (*ZeroCopySource) NextByte

func (self *ZeroCopySource) NextByte() (data byte, eof bool)

ReadByte implements the io.ByteReader interface.

func (*ZeroCopySource) NextBytes

func (self *ZeroCopySource) NextBytes(n uint64) (data []byte, eof bool)

Read implements the io.ZeroCopySource interface.

func (*ZeroCopySource) NextHash

func (self *ZeroCopySource) NextHash() (data Uint256, eof bool)

func (*ZeroCopySource) NextI128

func (self *ZeroCopySource) NextI128() (data I128, eof bool)

func (*ZeroCopySource) NextInt16

func (self *ZeroCopySource) NextInt16() (data int16, eof bool)

func (*ZeroCopySource) NextInt32

func (self *ZeroCopySource) NextInt32() (data int32, eof bool)

func (*ZeroCopySource) NextInt64

func (self *ZeroCopySource) NextInt64() (data int64, eof bool)

func (*ZeroCopySource) NextString

func (self *ZeroCopySource) NextString() (data string, size uint64, irregular bool, eof bool)

func (*ZeroCopySource) NextUint16

func (self *ZeroCopySource) NextUint16() (data uint16, eof bool)

func (*ZeroCopySource) NextUint32

func (self *ZeroCopySource) NextUint32() (data uint32, eof bool)

func (*ZeroCopySource) NextUint64

func (self *ZeroCopySource) NextUint64() (data uint64, eof bool)

func (*ZeroCopySource) NextUint8

func (self *ZeroCopySource) NextUint8() (data uint8, eof bool)

func (*ZeroCopySource) NextVarBytes

func (self *ZeroCopySource) NextVarBytes() (data []byte, size uint64, irregular bool, eof bool)

func (*ZeroCopySource) NextVarUint

func (self *ZeroCopySource) NextVarUint() (data uint64, size uint64, irregular bool, eof bool)

func (*ZeroCopySource) Pos

func (self *ZeroCopySource) Pos() uint64

func (*ZeroCopySource) ReadString

func (self *ZeroCopySource) ReadString() (string, error)

func (*ZeroCopySource) ReadUint32

func (self *ZeroCopySource) ReadUint32() (data uint32, err error)

func (*ZeroCopySource) ReadVarBytes

func (self *ZeroCopySource) ReadVarBytes() (data []byte, err error)

func (*ZeroCopySource) Size

func (self *ZeroCopySource) Size() uint64

Size returns the original length of the underlying byte slice. Size is the number of bytes available for reading via ReadAt. The returned value is always the same and is not affected by calls to any other method.

func (*ZeroCopySource) Skip

func (self *ZeroCopySource) Skip(n uint64) (eof bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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