wire

package
v0.0.0-...-a6a19e8 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxVarIntPayload is the maximum payload size for a variable length integer.
	MaxVarIntPayload = 9
)

Variables

This section is empty.

Functions

func RandomUint64

func RandomUint64() (uint64, error)

RandomUint64 returns a cryptographically random uint64 value.

func ReadVarBytes

func ReadVarBytes(r io.Reader, maxAllowed uint32,
	fieldName string) ([]byte, error)

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

func ReadVarInt(r io.Reader) (uint64, error)

ReadVarInt reads a variable length integer from r and returns it as a uint64.

func VarIntSerializeSize

func VarIntSerializeSize(val uint64) int

VarIntSerializeSize returns the number of bytes it would take to serialize val as a variable length integer.

func WriteVarBytes

func WriteVarBytes(w io.Writer, bytes []byte) error

WriteVarBytes serializes a variable length byte array to w as a varInt containing the number of bytes, followed by the bytes themselves.

func WriteVarInt

func WriteVarInt(w io.Writer, val uint64) error

WriteVarInt serializes val to w using a variable number of bytes depending on its value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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