bytesExt

package
v0.0.0-...-f277093 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package bytes provides utilities that extend the Go standard library's bytes package

Index

Constants

This section is empty.

Variables

View Source
var ErrInsufficientBytes = errors.New("insufficient bytes for conversion")

ErrInsufficientBytes is returned when a byte slice doesn't have enough bytes for conversion

Functions

func ContainsAny

func ContainsAny(b []byte, chars []byte) bool

ContainsAny returns true if the byte slice contains any of the bytes in chars

func FromFloat32

func FromFloat32(v float32, order binary.ByteOrder) []byte

FromFloat32 converts float32 to a byte slice using the specified byte order

func FromFloat64

func FromFloat64(v float64, order binary.ByteOrder) []byte

FromFloat64 converts float64 to a byte slice using the specified byte order

func FromUint16

func FromUint16(v uint16, order binary.ByteOrder) []byte

FromUint16 converts uint16 to a byte slice using the specified byte order

func FromUint32

func FromUint32(v uint32, order binary.ByteOrder) []byte

FromUint32 converts uint32 to a byte slice using the specified byte order

func FromUint64

func FromUint64(v uint64, order binary.ByteOrder) []byte

FromUint64 converts uint64 to a byte slice using the specified byte order

func IsASCII

func IsASCII(b []byte) bool

IsASCII checks if all bytes in the slice are valid ASCII characters

func RemoveAll

func RemoveAll(s, chars []byte) []byte

RemoveAll returns a copy with all occurrences of the given bytes removed

func Repeat

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

Repeat creates a new byte slice by repeating the input slice n times

func Reverse

func Reverse(b []byte) []byte

Reverse returns a new byte slice with the elements in reverse order

func ReverseInPlace

func ReverseInPlace(b []byte)

ReverseInPlace reverses a byte slice in place

func SafeSlice

func SafeSlice(b []byte, start, length int) []byte

SafeSlice returns a slice of the specified length from the input bytes, or a smaller slice if the input is not long enough

func ToFloat32

func ToFloat32(b []byte, order binary.ByteOrder) (float32, error)

ToFloat32 converts a byte slice to float32 using the specified byte order

func ToFloat64

func ToFloat64(b []byte, order binary.ByteOrder) (float64, error)

ToFloat64 converts a byte slice to float64 using the specified byte order

func ToUint16

func ToUint16(b []byte, order binary.ByteOrder) (uint16, error)

ToUint16 converts a byte slice to uint16 using the specified byte order

func ToUint32

func ToUint32(b []byte, order binary.ByteOrder) (uint32, error)

ToUint32 converts a byte slice to uint32 using the specified byte order

func ToUint64

func ToUint64(b []byte, order binary.ByteOrder) (uint64, error)

ToUint64 converts a byte slice to uint64 using the specified byte order

Types

This section is empty.

Jump to

Keyboard shortcuts

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