Documentation ¶
Overview ¶
Package common contains various helper functions.
Copyright © 2019 Annchain Authors <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- func ByteInt32(i int32) []byte
- func Bytes2Hex(d []byte) string
- func CopyBytes(b []byte) (copiedBytes []byte)
- func FromHex(s string) ([]byte, error)
- func GetInt32(b []byte, pos int) int32
- func Hex2Bytes(str string) ([]byte, error)
- func Hex2BytesFixed(str string, flen int) []byte
- func Hex2BytesNoError(str string) []byte
- func IsSameBytes(s, t []byte) bool
- func LeftPadBytes(slice []byte, l int) []byte
- func RightPadBytes(slice []byte, l int) []byte
- func SetInt32(b []byte, pos int, i int32)
- func ToHex(b []byte) stringdeprecated
- type Address
- func (h Address) Big() *big.Int
- func (z *Address) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Address) EncodeMsg(en *msgp.Writer) (err error)
- func (h Address) Format(s fmt.State, c rune)
- func (h Address) Generate(rand *rand.Rand, size int) reflect.Value
- func (h Address) Hex() string
- func (z *Address) MarshalMsg(b []byte) (o []byte, err error)
- func (h Address) MarshalText() ([]byte, error)
- func (z *Address) Msgsize() (s int)
- func (h *Address) MustSetBytes(b []byte)
- func (h *Address) SetBytes(b []byte) error
- func (h Address) ShortString() string
- func (h Address) String() string
- func (h Address) TerminalString() string
- func (h Address) ToBytes() []byte
- func (h *Address) UnmarshalJSON(input []byte) error
- func (z *Address) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (h *Address) UnmarshalText(input []byte) error
- type Hash
- func (h Hash) Big() *big.Int
- func (h Hash) Cmp(another Hash) int
- func (z *Hash) DecodeMsg(dc *msgp.Reader) (err error)
- func (h *Hash) Empty() bool
- func (z *Hash) EncodeMsg(en *msgp.Writer) (err error)
- func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value
- func (h Hash) Hex() string
- func (z *Hash) MarshalMsg(b []byte) (o []byte, err error)
- func (h Hash) MarshalText() ([]byte, error)
- func (z *Hash) Msgsize() (s int)
- func (h *Hash) MustSetBytes(b []byte, padding Padding)
- func (h *Hash) SetBytes(b []byte) error
- func (h Hash) String() string
- func (h Hash) TerminalString() string
- func (h Hash) ToBytes() []byte
- func (h *Hash) UnmarshalJSON(input []byte) error
- func (z *Hash) UnmarshalMsg(bts []byte) (o []byte, err error)
- func (h *Hash) UnmarshalText(input []byte) error
- type HashBytes
- type Hashes
- func (z *Hashes) DecodeMsg(dc *msgp.Reader) (err error)
- func (z Hashes) EncodeMsg(en *msgp.Writer) (err error)
- func (a Hashes) Len() int
- func (a Hashes) Less(i, j int) bool
- func (z Hashes) MarshalMsg(b []byte) (o []byte, err error)
- func (z Hashes) Msgsize() (s int)
- func (h Hashes) String() string
- func (a Hashes) Swap(i, j int)
- func (z *Hashes) UnmarshalMsg(bts []byte) (o []byte, err error)
- type IOSize
- type Padding
- type StorageSize
Constants ¶
const (
AddressLength = 20
)
Length of Addresses in bytes.
const (
HashLength = 32
)
Length of hash in bytes.
Variables ¶
This section is empty.
Functions ¶
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func Hex2BytesFixed ¶
Hex2BytesFixed returns bytes of a specified fixed length flen.
func Hex2BytesNoError ¶ added in v0.0.7
Hex2BytesNoError panics if hex is wrong. Use it ONLY in test code
func IsSameBytes ¶
IsSameBytes compares two byte slice. Return true if they are the same, otherwise false.
func LeftPadBytes ¶
LeftPadBytes zero-pads slice to the left up to length l.
func RightPadBytes ¶
RightPadBytes zero-pads slice to the right up to length l.
Types ¶
type Address ¶ added in v0.0.2
type Address struct {
Bytes [AddressLength]byte `msgp:"bytes"`
}
Address represents the 20 byte of address.
func BigToAddress ¶ added in v0.0.2
BigToAddress sets byte representation of b to Address. If b is larger than len(h), b will be cropped from the left.
func BytesToAddress ¶ added in v0.0.2
BytesToAddress sets b to hash. If b is larger than len(h), b will be cropped from the left.
func HexToAddress ¶ added in v0.0.2
HexToAddress sets byte representation of s to Address. If b is larger than len(h), b will be cropped from the left.
func HexToAddressNoError ¶ added in v0.0.7
func RandomAddress ¶ added in v0.0.2
func RandomAddress() Address
func StringToAddress ¶ added in v0.0.2
func (Address) Format ¶ added in v0.0.2
Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.
func (*Address) MarshalMsg ¶ added in v0.0.2
MarshalMsg implements msgp.Marshaler
func (Address) MarshalText ¶ added in v0.0.2
MarshalText returns the hex representation of h.
func (*Address) Msgsize ¶ added in v0.0.2
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Address) MustSetBytes ¶ added in v0.0.2
SetBytes sets the Address to the value of b. If b is larger than len(h), panic. It usually indicates a logic error.
func (Address) ShortString ¶ added in v0.0.2
func (Address) String ¶ added in v0.0.2
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (Address) TerminalString ¶ added in v0.0.2
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
func (*Address) UnmarshalJSON ¶ added in v0.0.2
UnmarshalJSON parses an Address in hex syntax.
func (*Address) UnmarshalMsg ¶ added in v0.0.2
UnmarshalMsg implements msgp.Unmarshaler
func (*Address) UnmarshalText ¶ added in v0.0.2
UnmarshalText parses an Address in hex syntax.
type Hash ¶ added in v0.0.2
type Hash struct {
Bytes [HashLength]byte `msgp:"bytes"`
}
Hash represents the 32 byte of Hash.
func BigToHash ¶ added in v0.0.2
BigToHash sets byte representation of b to Hash. If b is larger than len(h), b will be cropped from the left.
func BytesToHash ¶ added in v0.0.2
BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.
func HexToHash ¶ added in v0.0.2
HexToHash sets byte representation of s to Hash. If b is larger than len(h), b will be cropped from the left.
func HexToHashNoError ¶ added in v0.0.7
func RandomHash ¶ added in v0.0.2
func RandomHash() Hash
func (Hash) Cmp ¶ added in v0.0.2
Cmp compares two hashes. Returns 0 if two hashes are same. Returns -1 if the self hash is less than parameter hash. Returns 1 if the self hash is larger than parameter hash.
func (*Hash) MarshalMsg ¶ added in v0.0.2
MarshalMsg implements msgp.Marshaler
func (Hash) MarshalText ¶ added in v0.0.2
MarshalText returns the hex representation of h.
func (*Hash) Msgsize ¶ added in v0.0.2
Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (*Hash) MustSetBytes ¶ added in v0.0.2
SetBytes sets the Hash to the value of b. If b is larger than len(h), panic. It usually indicates a logic error.
func (Hash) String ¶ added in v0.0.2
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (Hash) TerminalString ¶ added in v0.0.2
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
func (*Hash) UnmarshalJSON ¶ added in v0.0.2
UnmarshalJSON parses an Hash in hex syntax.
func (*Hash) UnmarshalMsg ¶ added in v0.0.2
UnmarshalMsg implements msgp.Unmarshaler
func (*Hash) UnmarshalText ¶ added in v0.0.2
UnmarshalText parses an Hash in hex syntax.
type HashBytes ¶ added in v0.0.2
type HashBytes [HashLength]byte
func (*HashBytes) MarshalMsg ¶ added in v0.0.2
MarshalMsg implements msgp.Marshaler
type Hashes ¶ added in v0.0.2
type Hashes []Hash
func HexStringsToHashes ¶ added in v0.0.7
func (Hashes) MarshalMsg ¶ added in v0.0.2
MarshalMsg implements msgp.Marshaler
type IOSize ¶ added in v0.0.2
type IOSize float64
StorageSize is a wrapper around a float value that supports user friendly formatting.
func (IOSize) TerminalString ¶ added in v0.0.2
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
type Padding ¶ added in v0.0.2
type Padding uint
func (Padding) MarshalMsg ¶ added in v0.0.2
MarshalMsg implements msgp.Marshaler
type StorageSize ¶
type StorageSize float64
StorageSize is a wrapper around a float value that supports user friendly formatting.
func (StorageSize) String ¶
func (s StorageSize) String() string
String implements the stringer interface.
func (StorageSize) TerminalString ¶
func (s StorageSize) TerminalString() string
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package bitutil implements fast bitwise operations.
|
Package bitutil implements fast bitwise operations. |
Package hexutil implements hex encoding with 0x prefix.
|
Package hexutil implements hex encoding with 0x prefix. |
Package mclock is a wrapper for a monotonic clock source
|
Package mclock is a wrapper for a monotonic clock source |