Documentation ¶
Overview ¶
Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.
Copyright (c) 2018-2020. The asimov developers Copyright (c) 2013-2017 The btcsuite developers Use of this source code is governed by an ISC license that can be found in the LICENSE file.
Index ¶
- Constants
- func RandomUint64() (uint64, error)
- func ReadBool(r io.Reader, e *bool) error
- func ReadNBytes(r io.Reader, buf []byte, n int) error
- func ReadUint16(r io.Reader, e *uint16) error
- func ReadUint32(r io.Reader, e *uint32) error
- func ReadUint32B(r io.Reader, e *uint32) error
- func ReadUint64(r io.Reader, e *uint64) error
- func ReadUint64B(r io.Reader, e *uint64) error
- func ReadUint8(r io.Reader, e *uint8) 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 ReadVarUint(r io.Reader) (uint64, error)
- func VarIntSerializeSize(val uint64) int
- func WriteBool(w io.Writer, e bool) error
- func WriteNBytes(w io.Writer, bytes []byte) error
- func WriteUint16(w io.Writer, e uint16) error
- func WriteUint32(w io.Writer, e uint32) error
- func WriteUint32B(w io.Writer, e uint32) error
- func WriteUint64(w io.Writer, e uint64) error
- func WriteUint64B(w io.Writer, e uint64) error
- func WriteUint8(w io.Writer, e uint8) 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
- func WriteVarUint(w io.Writer, val uint64) error
- type MessageError
- type SerializableData
Constants ¶
const ( // MaxVarIntPayload is the maximum payload size for a variable length integer. MaxVarIntPayload = 9 // MaxVarStringPayload is the maximum payload size for a variable string. MaxVarStringPayload = 1024 )
Variables ¶
This section is empty.
Functions ¶
func RandomUint64 ¶
RandomUint64 returns a cryptographically random uint64 value.
func ReadNBytes ¶
ReadVarInt reads a variable length byte from r and returns it as a byte slice.
func ReadUint16 ¶
ReadVarInt reads a variable length integer from r with littleEndian and returns it as a uint16.
func ReadUint32 ¶
ReadVarInt reads a variable length integer from r with littleEndian and returns it as a uint32.
func ReadUint32B ¶
ReadVarInt reads a variable length integer from r with bigEndian and returns it as a uint32.
func ReadUint64 ¶
ReadVarInt reads a variable length integer from r with littleEndian and returns it as a uint64.
func ReadUint64B ¶
ReadVarInt reads a variable length integer from r with bigEndian and returns it as a uint64.
func ReadVarBytes ¶
serialization.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 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.
func WriteVarString ¶
WriteVarString serializes str to w as a variable length integer containing the length of the string followed by the bytes that represent the string itself.
Types ¶
type MessageError ¶
type MessageError struct { Func string // Function name Type string // Type Description string // Human readable description of the issue }
MessageError describes an issue with a message. An example of some potential issues are messages from the wrong bitcoin network, invalid commands, mismatched checksums, and exceeding max payloads.
This provides a mechanism for the caller to type assert the error to differentiate between general io errors such as io.EOF and issues that resulted from malformed messages.
func (*MessageError) Error ¶
func (e *MessageError) Error() string
Error satisfies the error interface and prints human-readable errors.