Documentation ¶
Overview ¶
Package bytesutil provides utility functions for working with bytes and byte streams that are useful when working with the RESP protocol.
Index ¶
- func AnyIntToInt64(m interface{}) int64
- func BufferedBytesDelim(br *bufio.Reader) ([]byte, error)
- func BufferedIntDelim(br *bufio.Reader) (int64, error)
- func BufferedPrefix(br *bufio.Reader, prefix []byte) error
- func Expand(b []byte, n int) []byte
- func GetBytes() *[]byte
- func MultiWrite(w io.Writer, bb ...[]byte) error
- func ParseInt(b []byte) (int64, error)
- func ParseUint(b []byte) (uint64, error)
- func PutBytes(b *[]byte)
- func ReadFloat(r io.Reader, precision, n int) (float64, error)
- func ReadInt(r io.Reader, n int) (int64, error)
- func ReadNAppend(r io.Reader, b []byte, n int) ([]byte, error)
- func ReadNDiscard(r io.Reader, n int) error
- func ReadUint(r io.Reader, n int) (uint64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyIntToInt64 ¶
func AnyIntToInt64(m interface{}) int64
AnyIntToInt64 converts a value of any of Go's integer types (signed and unsigned) into a signed int64.
If m is not of one of Go's built in integer types the call will panic.
func BufferedBytesDelim ¶
BufferedBytesDelim reads a line from br and checks that the line ends with \r\n, returning the line without \r\n.
func BufferedIntDelim ¶
BufferedIntDelim reads the current line from br as an integer.
func BufferedPrefix ¶
BufferedPrefix checks that the next bytes in the given *bufio.Reader are equal to prefix and discards them if they are equal.
func Expand ¶
Expand expands the given byte slice to exactly n bytes.
If cap(b) < n, a new slice will be allocated and filled with the bytes from b.
func GetBytes ¶
func GetBytes() *[]byte
GetBytes returns a non-nil pointer to a byte slice from a pool of byte slices.
The returned byte slice should be put back into the pool using PutBytes after usage.
func MultiWrite ¶
MultiWrite writes multiple byte slices into one writer.
This is equivalent to calling w.Write for each byte slice in bb, but may be optimized to reduce calls for some types of io.Writer.
func ParseInt ¶
ParseInt is a specialized version of strconv.ParseInt that parses a base-10 encoded signed integer from a []byte.
This can be used to avoid allocating a string, since strconv.ParseInt only takes a string.
func ParseUint ¶
ParseUint is a specialized version of strconv.ParseUint that parses a base-10 encoded integer from a []byte.
This can be used to avoid allocating a string, since strconv.ParseUint only takes a string.
func PutBytes ¶
func PutBytes(b *[]byte)
PutBytes puts the given byte slice pointer into a pool that can be accessed via GetBytes.
After calling PutBytes the given pointer and byte slice must not be accessed anymore.
func ReadFloat ¶
ReadFloat reads the next n bytes from r as a 64 bit floating point number with the given precision.
func ReadNAppend ¶
ReadNAppend appends exactly n bytes from r into b.
func ReadNDiscard ¶
ReadNDicard discards exactly n bytes from r.
Types ¶
This section is empty.