字节集类

package
v0.0.0-...-2910145 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gbinary 提供了处理二进制/字节数据的有用 API。

注意,gbinary 包默认使用 LittleEndian 编码方式对数据进行编码。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeDecode

func BeDecode(b []byte, values ...interface{}) error

func BeDecodeToBool

func BeDecodeToBool(b []byte) bool

func BeDecodeToFloat32

func BeDecodeToFloat32(b []byte) float32

func BeDecodeToFloat64

func BeDecodeToFloat64(b []byte) float64

func BeDecodeToInt

func BeDecodeToInt(b []byte) int

func BeDecodeToInt16

func BeDecodeToInt16(b []byte) int16

func BeDecodeToInt32

func BeDecodeToInt32(b []byte) int32

func BeDecodeToInt64

func BeDecodeToInt64(b []byte) int64

func BeDecodeToInt8

func BeDecodeToInt8(b []byte) int8

func BeDecodeToString

func BeDecodeToString(b []byte) string

func BeDecodeToUint

func BeDecodeToUint(b []byte) uint

func BeDecodeToUint16

func BeDecodeToUint16(b []byte) uint16

func BeDecodeToUint32

func BeDecodeToUint32(b []byte) uint32

func BeDecodeToUint64

func BeDecodeToUint64(b []byte) uint64

func BeDecodeToUint8

func BeDecodeToUint8(b []byte) uint8

func BeEncode

func BeEncode(values ...interface{}) []byte

BeEncode 采用大端序(BigEndian)将一个或多个 `values` 值编码为字节。 它通过类型断言检查 `values` 中每个值的类型,并在内部调用相应的转换函数进行字节转换。

它支持常见的变量类型断言,最终使用 fmt.Sprintf 将值转换为字符串,然后再转为字节。

func BeEncodeBool

func BeEncodeBool(b bool) []byte

func BeEncodeByLength

func BeEncodeByLength(length int, values ...interface{}) []byte

func BeEncodeFloat32

func BeEncodeFloat32(f float32) []byte

func BeEncodeFloat64

func BeEncodeFloat64(f float64) []byte

func BeEncodeInt

func BeEncodeInt(i int) []byte

func BeEncodeInt16

func BeEncodeInt16(i int16) []byte

func BeEncodeInt32

func BeEncodeInt32(i int32) []byte

func BeEncodeInt64

func BeEncodeInt64(i int64) []byte

func BeEncodeInt8

func BeEncodeInt8(i int8) []byte

func BeEncodeString

func BeEncodeString(s string) []byte

func BeEncodeUint

func BeEncodeUint(i uint) []byte

func BeEncodeUint16

func BeEncodeUint16(i uint16) []byte

func BeEncodeUint32

func BeEncodeUint32(i uint32) []byte

func BeEncodeUint64

func BeEncodeUint64(i uint64) []byte

func BeEncodeUint8

func BeEncodeUint8(i uint8) []byte

func BeFillUpSize

func BeFillUpSize(b []byte, l int) []byte

BeFillUpSize 使用大端序将字节切片`b`填充到给定长度`l`。

注意:为了防止改变原始参数字节,它会通过复制原始字节切片创建一个新的字节切片。

func Decode

func Decode(b []byte, values ...interface{}) error

func DecodeBits

func DecodeBits(bits []Bit) int

DecodeBits .将位解码为整数 解析为整数

func DecodeBitsToUint

func DecodeBitsToUint(bits []Bit) uint

DecodeBitsToUint 解码bits并转换为uint类型

func DecodeToBool

func DecodeToBool(b []byte) bool

func DecodeToFloat32

func DecodeToFloat32(b []byte) float32

func DecodeToFloat64

func DecodeToFloat64(b []byte) float64

func DecodeToInt

func DecodeToInt(b []byte) int

func DecodeToInt16

func DecodeToInt16(b []byte) int16

func DecodeToInt32

func DecodeToInt32(b []byte) int32

func DecodeToInt64

func DecodeToInt64(b []byte) int64

func DecodeToInt8

func DecodeToInt8(b []byte) int8

func DecodeToString

func DecodeToString(b []byte) string

func DecodeToUint

func DecodeToUint(b []byte) uint

func DecodeToUint16

func DecodeToUint16(b []byte) uint16

func DecodeToUint32

func DecodeToUint32(b []byte) uint32

func DecodeToUint64

func DecodeToUint64(b []byte) uint64

func DecodeToUint8

func DecodeToUint8(b []byte) uint8

func Encode

func Encode(values ...interface{}) []byte

func EncodeBitsToBytes

func EncodeBitsToBytes(bits []Bit) []byte

EncodeBitsToBytes . 将位编码为字节 将位转换为[] byte,从左到右进行编码,并在末尾不足1字节时添加0填充。

func EncodeBool

func EncodeBool(b bool) []byte

func EncodeByLength

func EncodeByLength(length int, values ...interface{}) []byte

func EncodeFloat32

func EncodeFloat32(f float32) []byte

func EncodeFloat64

func EncodeFloat64(f float64) []byte

func EncodeInt

func EncodeInt(i int) []byte

func EncodeInt16

func EncodeInt16(i int16) []byte

func EncodeInt32

func EncodeInt32(i int32) []byte

func EncodeInt64

func EncodeInt64(i int64) []byte

func EncodeInt8

func EncodeInt8(i int8) []byte

func EncodeString

func EncodeString(s string) []byte

func EncodeUint

func EncodeUint(i uint) []byte

func EncodeUint16

func EncodeUint16(i uint16) []byte

func EncodeUint32

func EncodeUint32(i uint32) []byte

func EncodeUint64

func EncodeUint64(i uint64) []byte

func EncodeUint8

func EncodeUint8(i uint8) []byte

func LeDecode

func LeDecode(b []byte, values ...interface{}) error

func LeDecodeToBool

func LeDecodeToBool(b []byte) bool

func LeDecodeToFloat32

func LeDecodeToFloat32(b []byte) float32

func LeDecodeToFloat64

func LeDecodeToFloat64(b []byte) float64

func LeDecodeToInt

func LeDecodeToInt(b []byte) int

func LeDecodeToInt16

func LeDecodeToInt16(b []byte) int16

func LeDecodeToInt32

func LeDecodeToInt32(b []byte) int32

func LeDecodeToInt64

func LeDecodeToInt64(b []byte) int64

func LeDecodeToInt8

func LeDecodeToInt8(b []byte) int8

func LeDecodeToString

func LeDecodeToString(b []byte) string

func LeDecodeToUint

func LeDecodeToUint(b []byte) uint

func LeDecodeToUint16

func LeDecodeToUint16(b []byte) uint16

func LeDecodeToUint32

func LeDecodeToUint32(b []byte) uint32

func LeDecodeToUint64

func LeDecodeToUint64(b []byte) uint64

func LeDecodeToUint8

func LeDecodeToUint8(b []byte) uint8

func LeEncode

func LeEncode(values ...interface{}) []byte

LeEncode 使用LittleEndian对一个或多个`values`进行编码成字节。 它通过类型断言检查`values`中每个值的类型,并在内部调用相应的转换函数完成字节转换。

它支持通用变量类型的断言,最后使用fmt.Sprintf将值转换为字符串,然后再转换为字节。

func LeEncodeBool

func LeEncodeBool(b bool) []byte

func LeEncodeByLength

func LeEncodeByLength(length int, values ...interface{}) []byte

func LeEncodeFloat32

func LeEncodeFloat32(f float32) []byte

func LeEncodeFloat64

func LeEncodeFloat64(f float64) []byte

func LeEncodeInt

func LeEncodeInt(i int) []byte

func LeEncodeInt16

func LeEncodeInt16(i int16) []byte

func LeEncodeInt32

func LeEncodeInt32(i int32) []byte

func LeEncodeInt64

func LeEncodeInt64(i int64) []byte

func LeEncodeInt8

func LeEncodeInt8(i int8) []byte

func LeEncodeString

func LeEncodeString(s string) []byte

func LeEncodeUint

func LeEncodeUint(i uint) []byte

func LeEncodeUint16

func LeEncodeUint16(i uint16) []byte

func LeEncodeUint32

func LeEncodeUint32(i uint32) []byte

func LeEncodeUint64

func LeEncodeUint64(i uint64) []byte

func LeEncodeUint8

func LeEncodeUint8(i uint8) []byte

func LeFillUpSize

func LeFillUpSize(b []byte, l int) []byte

LeFillUpSize 函数使用LittleEndian方式填充字节切片`b`,使其长度达到给定的`l`。

注意:该函数通过复制原始字节切片创建一个新的字节切片来实现填充,以避免修改原参数字节。

Types

type Bit

type Bit int8

二进制位 (0 | 1)

func DecodeBytesToBits

func DecodeBytesToBits(bs []byte) []Bit

DecodeBytesToBits .将字节切片解析为字符数组(uint8切片)

func EncodeBits

func EncodeBits(bits []Bit, i int, l int) []Bit

EncodeBits 对比特进行编码,并返回编码后的比特,默认采用默认编码方式

func EncodeBitsWithUint

func EncodeBitsWithUint(bits []Bit, ui uint, l int) []Bit

EncodeBitsWithUint . 将ui的按位与bits数组进行合并,并占用length位 (注意:二进制的0 | 1数字存储在uis数组中)

Jump to

Keyboard shortcuts

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