Documentation ¶
Overview ¶
Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.
Copyright (c) 2020 The JaxNetwork developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.
Index ¶
- Constants
- Variables
- func PutUint32(w io.Writer, val uint32) error
- func PutUint64(w io.Writer, val uint64) error
- func RandomUint64() (uint64, error)
- func ReadElement(r io.Reader, element interface{}) error
- func ReadElements(r io.Reader, elements ...interface{}) error
- func ReadInvVect(r io.Reader, iv *types.InvVect) error
- func ReadNetAddress(r io.Reader, pver uint32, na *types.NetAddress, ts bool) 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 Uint32(r io.Reader) (uint32, error)
- func Uint64(r io.Reader) (uint64, error)
- func VarIntSerializeSize(val uint64) int
- func WriteElement(w io.Writer, element interface{}) error
- func WriteElements(w io.Writer, elements ...interface{}) error
- func WriteInvVect(w io.Writer, iv *types.InvVect) error
- func WriteNetAddress(w io.Writer, pver uint32, na *types.NetAddress, ts bool) error
- func WriteVarBytes(w io.Writer, pver uint32, bytes []byte) error
- func WriteVarInt(w io.Writer, val uint64) error
- func WriteVarString(w io.Writer, pver uint32, str string) error
- type Int64Time
- type MessageEncoding
- type Uint32Time
Constants ¶
const ( // MaxVarIntPayload is the maximum payload size for a variable length integer. MaxVarIntPayload = 9 CommandSize = 12 MaxMessagePayload = 1024 * 1024 * 32 // 32MB )
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.
Functions ¶
func RandomUint64 ¶
RandomUint64 returns a cryptographically random uint64 value.
func ReadElement ¶
readElement reads the next sequence of bytes from r using little endian depending on the concrete type of element pointed to.
func ReadElements ¶
readElements reads multiple items from r. It is equivalent to multiple calls to readElement.
func ReadInvVect ¶
ReadInvVect reads an encoded InvVect from r depending on the protocol version.
func ReadNetAddress ¶
readNetAddress reads an encoded NetAddress from r depending on the protocol version and whether or not the timestamp is included per ts. Some messages like version do not include the timestamp.
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 through 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 VarIntSerializeSize ¶
VarIntSerializeSize returns the number of bytes it would take to serialize val as a variable length integer.
func WriteElement ¶
writeElement writes the little endian representation of element to w.
func WriteElements ¶
writeElements writes multiple items to w. It is equivalent to multiple calls to writeElement.
func WriteInvVect ¶
WriteInvVect serializes an InvVect to w depending on the protocol version.
func WriteNetAddress ¶
writeNetAddress serializes a NetAddress to w depending on the protocol version and whether or not the timestamp is included per ts. Some messages like version do not include the timestamp.
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 ¶
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 MessageEncoding ¶
type MessageEncoding uint32
type Uint32Time ¶
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.