Documentation ¶
Overview ¶
Copyright (c) 2017-2018 The qitmeer developers
Index ¶
- Constants
- Variables
- func DeserializeUint64(valueBytes []byte) (uint64, error)
- func DeserializeVLQ(serialized []byte) (uint64, int)
- func PutVLQ(target []byte, n uint64) int
- func RandomUint64() (uint64, error)
- func ReadElements(r io.Reader, elements ...interface{}) error
- func ReadVarBytes(r io.Reader, pver uint32, maxAllowed uint32, fieldName string) ([]byte, error)
- func ReadVarInt(r io.Reader, pver uint32) (uint64, error)
- func ReadVarString(r io.Reader, pver uint32) (string, error)
- func SerializeSizeVLQ(n uint64) int
- func SerializeUint64(value uint64) []byte
- func VarIntSerializeSize(val uint64) int
- func WriteElements(w io.Writer, elements ...interface{}) error
- func WriteVarBytes(w io.Writer, pver uint32, bytes []byte) error
- func WriteVarInt(w io.Writer, pver uint32, val uint64) error
- func WriteVarString(w io.Writer, pver uint32, str string) error
- type Int64Time
- type Serializable
- type Uint32Time
Constants ¶
const ( // MaxVarIntPayload is the maximum payload size for a variable length integer. MaxVarIntPayload = 9 // MaxMessagePayload is the maximum bytes a message can be regardless of other // individual limits imposed by messages themselves. MaxMessagePayload = (1024 * 1024 * 32) // 32MB )
const CurrentCompressionVersion = 1
currentCompressionVersion is the current script compression version of the database.
Variables ¶
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.
var MaxUint32VLQSerializeSize = SerializeSizeVLQ(1<<32 - 1)
maxUint32VLQSerializeSize is the maximum number of bytes a max uint32 takes to serialize as a VLQ.
Functions ¶
func DeserializeUint64 ¶ added in v1.0.19
DeserializeUint64 deserializes bytes to uint64
func DeserializeVLQ ¶
DeserializeVLQ deserializes the provided variable-length quantity according to the format described above. It also returns the number of bytes deserialized.
func PutVLQ ¶
PutVLQ serializes the provided number to a variable-length quantity according to the format described above and returns the number of bytes of the encoded value. The result is placed directly into the passed byte slice which must be at least large enough to handle the number of bytes returned by the serializeSizeVLQ function or it will panic.
func RandomUint64 ¶
RandomUint64 returns a cryptographically random uint64 value.
func ReadElements ¶
ReadElements reads multiple items from r. It is equivalent to multiple calls to readElement.
func ReadVarBytes ¶
ReadVarBytes reads a variable length byte array. A byte array is encoded as a varInt containing the length of the array followed by the bytes themselves. An error is returned if the length is greater than the passed maxAllowed parameter which helps protect against memory exhaustion attacks and forced panics thorugh malformed messages. The fieldName parameter is only used for the error message so it provides more context in the error.
func ReadVarInt ¶
ReadVarInt reads a variable length integer from r and returns it as a uint64.
func ReadVarString ¶
ReadVarString reads a variable length string from r and returns it as a Go string. A variable length string is encoded as a variable length integer containing the length of the string followed by the bytes that represent the string itself. An error is returned if the length is greater than the maximum block payload size since it helps protect against memory exhaustion attacks and forced panics through malformed messages.
func SerializeSizeVLQ ¶
SerializeSizeVLQ returns the number of bytes it would take to serialize the passed number as a variable-length quantity according to the format described above.
func SerializeUint64 ¶ added in v1.0.19
SerializeUint64 serializes a uint64
func VarIntSerializeSize ¶
VarIntSerializeSize returns the number of bytes it would take to serialize val as a variable length integer.
func WriteElements ¶
WriteElements writes multiple items to w. It is equivalent to multiple calls to writeElement.
func WriteVarBytes ¶
WriteVarBytes serializes a variable length byte array to w as a varInt containing the number of bytes, followed by the bytes themselves.
func WriteVarInt ¶
WriteVarInt serializes val to w using a variable number of bytes depending on its value.
Types ¶
type Int64Time ¶
TODO fix time ambiguous int64Time represents a unix timestamp encoded with an int64. It is used as a way to signal the readElement function how to decode a timestamp into a Go time.Time since it is otherwise ambiguous.
type Serializable ¶
type Uint32Time ¶
TODO fix time ambiguous uint32Time represents a unix timestamp encoded with a uint32. It is used as a way to signal the readElement function how to decode a timestamp into a Go time.Time since it is otherwise ambiguous.