Documentation ¶
Index ¶
- Constants
- func RandomUint64() (uint64, error)
- func ReadElements(r io.Reader, elements ...interface{}) error
- func ReadVarBytes(r io.Reader, maxAllowed uint32, fieldName string) ([]byte, error)
- func ReadVarBytesBuf(r io.Reader, buf []byte, maxAllowed uint32, fieldName string) ([]byte, error)
- func ReadVarInt(r io.Reader) (uint64, error)
- func ReadVarIntBuf(r io.Reader, buf []byte) (uint64, error)
- func ReadVarString(r io.Reader, maxAllowed uint64) (string, error)
- func VarIntSerializeSize(val uint64) int
- func WriteElements(w io.Writer, elements ...interface{}) error
- func WriteVarBytes(w io.Writer, bytes []byte) error
- func WriteVarBytesBuf(w io.Writer, bytes, buf []byte) error
- func WriteVarInt(w io.Writer, val uint64) error
- func WriteVarIntBuf(w io.Writer, val uint64, buf []byte) error
- func WriteVarString(w io.Writer, str string) error
- type Int64Time
- type Uint32Time
- type VarByte
Constants ¶
const ( // MaxVarIntPayload is the maximum payload size for a variable length integer. MaxVarIntPayload = 9 CommandNameSize = 12 )
Variables ¶
This section is empty.
Functions ¶
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 through malformed messages. The fieldName parameter is only used for the error message so it provides more context in the error.
func ReadVarBytesBuf ¶
ReadVarBytesBuf 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. If b is non-nil, the provided buffer will be used for serializing small values. Otherwise a buffer will be drawn from the binarySerializer's pool and return when the method finishes.
func ReadVarInt ¶
ReadVarInt reads a variable length integer from r and returns it as a uint64.
func ReadVarIntBuf ¶
ReadVarIntBuf reads a variable length integer from r using a preallocated scratch buffer and returns it as a uint64.
NOTE: buf MUST at least an 8-byte slice.
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 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 WriteVarBytesBuf ¶
WriteVarBytesBuf serializes a variable length byte array to w as a varInt containing the number of bytes, followed by the bytes themselves. If b is non-nil, the provided buffer will be used for serializing small values. Otherwise a buffer will be drawn from the binarySerializer's pool and return when the method finishes.
func WriteVarInt ¶
WriteVarInt serializes val to w using a variable number of bytes depending on its value.
func WriteVarIntBuf ¶
WriteVarIntBuf serializes val to w using a variable number of bytes depending on its value using a preallocated scratch buffer.
NOTE: buf MUST at least an 8-byte slice.
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 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.