Documentation ¶
Index ¶
- Constants
- func RandomUint64() (uint64, error)
- func ReadVarBytes(r io.Reader, maxAllowed uint32, fieldName string) ([]byte, error)
- func ReadVarInt(r io.Reader) (uint64, error)
- func VarIntSerializeSize(val uint64) int
- func WriteVarBytes(w io.Writer, bytes []byte) error
- func WriteVarInt(w io.Writer, val uint64) error
Constants ¶
const (
// MaxVarIntPayload is the maximum payload size for a variable length integer.
MaxVarIntPayload = 9
)
Variables ¶
This section is empty.
Functions ¶
func RandomUint64 ¶
RandomUint64 returns a cryptographically random uint64 value.
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 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.
Types ¶
This section is empty.