bytesutil

package
v3.0.0-...-edc725d Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package bytesutil provides utility functions for working with bytes and byte streams that are useful when working with the RESP protocol.

Index

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

func BufferedBytesDelim(br *bufio.Reader) ([]byte, error)

BufferedBytesDelim reads a line from br and checks that the line ends with \r\n, returning the line without \r\n.

func BufferedIntDelim

func BufferedIntDelim(br *bufio.Reader) (int64, error)

BufferedIntDelim reads the current line from br as an integer.

func Expand

func Expand(b []byte, n int) []byte

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 ParseInt

func ParseInt(b []byte) (int64, error)

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

func ParseUint(b []byte) (uint64, error)

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

func ReadFloat(r io.Reader, precision, n int) (float64, error)

ReadFloat reads the next n bytes from r as a 64 bit floating point number with the given precision.

func ReadInt

func ReadInt(r io.Reader, n int) (int64, error)

ReadInt reads the next n bytes from r as a signed 64 bit integer.

func ReadNAppend

func ReadNAppend(r io.Reader, b []byte, n int) ([]byte, error)

ReadNAppend appends exactly n bytes from r into b.

func ReadNDiscard

func ReadNDiscard(r io.Reader, n int) error

ReadNDicard discards exactly n bytes from r.

func ReadUint

func ReadUint(r io.Reader, n int) (uint64, error)

ReadUint reads the next n bytes from r as an unsigned 64 bit integer.

Types

This section is empty.

Jump to

Keyboard shortcuts

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