bytesutil

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: MIT Imports: 5 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 Expand

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

Expand expands the given byte slice to exactly n bytes. It will not return nil.

If cap(b) < n then a new slice will be allocated.

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 ReadBytesDelim

func ReadBytesDelim(br resp.BufferedReader) ([]byte, error)

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

func ReadFloat

func ReadFloat(r io.Reader, precision, n int, scratch *[]byte) (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, scratch *[]byte) (int64, error)

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

func ReadIntDelim

func ReadIntDelim(br resp.BufferedReader) (int64, error)

ReadIntDelim reads the current line from br as an integer, checks that the line ends with \r\n, and returns the 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, scratch *[]byte) error

ReadNDiscard discards exactly n bytes from r.

func ReadUint

func ReadUint(r io.Reader, n int, scratch *[]byte) (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