gf: github.com/gogf/gf/encoding/gbinary Index | Files

package gbinary

import "github.com/gogf/gf/encoding/gbinary"

Package gbinary provides useful API for handling binary/bytes data.

Note that package gbinary encodes the data using LittleEndian in default.

Index

Package Files

gbinary.go gbinary_be.go gbinary_bit.go gbinary_func.go gbinary_le.go

func BeDecode Uses

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

整形二进制解包,注意第二个及其后参数为字长确定的整形变量的指针地址,以便确定解析的[]byte长度, 例如:int8/16/32/64、uint8/16/32/64、float32/64等等

func BeDecodeToBool Uses

func BeDecodeToBool(b []byte) bool

将二进制解析为bool类型,识别标准是判断二进制中数值是否都为0,或者为空。

func BeDecodeToFloat32 Uses

func BeDecodeToFloat32(b []byte) float32

func BeDecodeToFloat64 Uses

func BeDecodeToFloat64(b []byte) float64

func BeDecodeToInt Uses

func BeDecodeToInt(b []byte) int

将二进制解析为int类型,根据[]byte的长度进行自动转换. 注意内部使用的是uint*,使用int会造成位丢失。

func BeDecodeToInt16 Uses

func BeDecodeToInt16(b []byte) int16

func BeDecodeToInt32 Uses

func BeDecodeToInt32(b []byte) int32

func BeDecodeToInt64 Uses

func BeDecodeToInt64(b []byte) int64

func BeDecodeToInt8 Uses

func BeDecodeToInt8(b []byte) int8

func BeDecodeToString Uses

func BeDecodeToString(b []byte) string

func BeDecodeToUint Uses

func BeDecodeToUint(b []byte) uint

将二进制解析为uint类型,根据[]byte的长度进行自动转换

func BeDecodeToUint16 Uses

func BeDecodeToUint16(b []byte) uint16

func BeDecodeToUint32 Uses

func BeDecodeToUint32(b []byte) uint32

func BeDecodeToUint64 Uses

func BeDecodeToUint64(b []byte) uint64

func BeDecodeToUint8 Uses

func BeDecodeToUint8(b []byte) uint8

func BeEncode Uses

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

BeEncode encodes one or multiple <values> into bytes using BigEndian. It uses type asserting checking the type of each value of <values> and internally calls corresponding converting function do the bytes converting.

It supports common variable type asserting, and finally it uses fmt.Sprintf converting value to string and then to bytes.

func BeEncodeBool Uses

func BeEncodeBool(b bool) []byte

func BeEncodeByLength Uses

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

将变量转换为二进制[]byte,并指定固定的[]byte长度返回,长度单位为字节(byte); 如果转换的二进制长度超过指定长度,那么进行截断处理

func BeEncodeFloat32 Uses

func BeEncodeFloat32(f float32) []byte

func BeEncodeFloat64 Uses

func BeEncodeFloat64(f float64) []byte

func BeEncodeInt Uses

func BeEncodeInt(i int) []byte

自动识别int类型长度,转换为[]byte

func BeEncodeInt16 Uses

func BeEncodeInt16(i int16) []byte

func BeEncodeInt32 Uses

func BeEncodeInt32(i int32) []byte

func BeEncodeInt64 Uses

func BeEncodeInt64(i int64) []byte

func BeEncodeInt8 Uses

func BeEncodeInt8(i int8) []byte

func BeEncodeString Uses

func BeEncodeString(s string) []byte

func BeEncodeUint Uses

func BeEncodeUint(i uint) []byte

自动识别uint类型长度,转换为[]byte

func BeEncodeUint16 Uses

func BeEncodeUint16(i uint16) []byte

func BeEncodeUint32 Uses

func BeEncodeUint32(i uint32) []byte

func BeEncodeUint64 Uses

func BeEncodeUint64(i uint64) []byte

func BeEncodeUint8 Uses

func BeEncodeUint8(i uint8) []byte

func BeFillUpSize Uses

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

BeFillUpSize fills up the bytes <b> to given length <l> using big BigEndian.

Note that it creates a new bytes slice by copying the original one to avoid changing the original parameter bytes.

func Decode Uses

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

func DecodeBits Uses

func DecodeBits(bits []Bit) int

解析为int

func DecodeBitsToUint Uses

func DecodeBitsToUint(bits []Bit) uint

解析为uint

func DecodeToBool Uses

func DecodeToBool(b []byte) bool

func DecodeToFloat32 Uses

func DecodeToFloat32(b []byte) float32

func DecodeToFloat64 Uses

func DecodeToFloat64(b []byte) float64

func DecodeToInt Uses

func DecodeToInt(b []byte) int

func DecodeToInt16 Uses

func DecodeToInt16(b []byte) int16

func DecodeToInt32 Uses

func DecodeToInt32(b []byte) int32

func DecodeToInt64 Uses

func DecodeToInt64(b []byte) int64

func DecodeToInt8 Uses

func DecodeToInt8(b []byte) int8

func DecodeToString Uses

func DecodeToString(b []byte) string

func DecodeToUint Uses

func DecodeToUint(b []byte) uint

func DecodeToUint16 Uses

func DecodeToUint16(b []byte) uint16

func DecodeToUint32 Uses

func DecodeToUint32(b []byte) uint32

func DecodeToUint64 Uses

func DecodeToUint64(b []byte) uint64

func DecodeToUint8 Uses

func DecodeToUint8(b []byte) uint8

func Encode Uses

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

func EncodeBitsToBytes Uses

func EncodeBitsToBytes(bits []Bit) []byte

将bits转换为[]byte,从左至右进行编码,不足1 byte按0往末尾补充

func EncodeBool Uses

func EncodeBool(b bool) []byte

func EncodeByLength Uses

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

func EncodeFloat32 Uses

func EncodeFloat32(f float32) []byte

func EncodeFloat64 Uses

func EncodeFloat64(f float64) []byte

func EncodeInt Uses

func EncodeInt(i int) []byte

func EncodeInt16 Uses

func EncodeInt16(i int16) []byte

func EncodeInt32 Uses

func EncodeInt32(i int32) []byte

func EncodeInt64 Uses

func EncodeInt64(i int64) []byte

func EncodeInt8 Uses

func EncodeInt8(i int8) []byte

func EncodeString Uses

func EncodeString(s string) []byte

func EncodeUint Uses

func EncodeUint(i uint) []byte

func EncodeUint16 Uses

func EncodeUint16(i uint16) []byte

func EncodeUint32 Uses

func EncodeUint32(i uint32) []byte

func EncodeUint64 Uses

func EncodeUint64(i uint64) []byte

func EncodeUint8 Uses

func EncodeUint8(i uint8) []byte

func LeDecode Uses

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

整形二进制解包,注意第二个及其后参数为字长确定的整形变量的指针地址,以便确定解析的[]byte长度, 例如:int8/16/32/64、uint8/16/32/64、float32/64等等

func LeDecodeToBool Uses

func LeDecodeToBool(b []byte) bool

将二进制解析为bool类型,识别标准是判断二进制中数值是否都为0,或者为空。

func LeDecodeToFloat32 Uses

func LeDecodeToFloat32(b []byte) float32

func LeDecodeToFloat64 Uses

func LeDecodeToFloat64(b []byte) float64

func LeDecodeToInt Uses

func LeDecodeToInt(b []byte) int

将二进制解析为int类型,根据[]byte的长度进行自动转换. 注意内部使用的是uint*,使用int会造成位丢失。

func LeDecodeToInt16 Uses

func LeDecodeToInt16(b []byte) int16

func LeDecodeToInt32 Uses

func LeDecodeToInt32(b []byte) int32

func LeDecodeToInt64 Uses

func LeDecodeToInt64(b []byte) int64

func LeDecodeToInt8 Uses

func LeDecodeToInt8(b []byte) int8

func LeDecodeToString Uses

func LeDecodeToString(b []byte) string

func LeDecodeToUint Uses

func LeDecodeToUint(b []byte) uint

将二进制解析为uint类型,根据[]byte的长度进行自动转换

func LeDecodeToUint16 Uses

func LeDecodeToUint16(b []byte) uint16

func LeDecodeToUint32 Uses

func LeDecodeToUint32(b []byte) uint32

func LeDecodeToUint64 Uses

func LeDecodeToUint64(b []byte) uint64

func LeDecodeToUint8 Uses

func LeDecodeToUint8(b []byte) uint8

func LeEncode Uses

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

LeEncode encodes one or multiple <values> into bytes using LittleEndian. It uses type asserting checking the type of each value of <values> and internally calls corresponding converting function do the bytes converting.

It supports common variable type asserting, and finally it uses fmt.Sprintf converting value to string and then to bytes.

func LeEncodeBool Uses

func LeEncodeBool(b bool) []byte

func LeEncodeByLength Uses

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

将变量转换为二进制[]byte,并指定固定的[]byte长度返回,长度单位为字节(byte); 如果转换的二进制长度超过指定长度,那么进行截断处理

func LeEncodeFloat32 Uses

func LeEncodeFloat32(f float32) []byte

func LeEncodeFloat64 Uses

func LeEncodeFloat64(f float64) []byte

func LeEncodeInt Uses

func LeEncodeInt(i int) []byte

自动识别int类型长度,转换为[]byte

func LeEncodeInt16 Uses

func LeEncodeInt16(i int16) []byte

func LeEncodeInt32 Uses

func LeEncodeInt32(i int32) []byte

func LeEncodeInt64 Uses

func LeEncodeInt64(i int64) []byte

func LeEncodeInt8 Uses

func LeEncodeInt8(i int8) []byte

func LeEncodeString Uses

func LeEncodeString(s string) []byte

func LeEncodeUint Uses

func LeEncodeUint(i uint) []byte

自动识别uint类型长度,转换为[]byte

func LeEncodeUint16 Uses

func LeEncodeUint16(i uint16) []byte

func LeEncodeUint32 Uses

func LeEncodeUint32(i uint32) []byte

func LeEncodeUint64 Uses

func LeEncodeUint64(i uint64) []byte

func LeEncodeUint8 Uses

func LeEncodeUint8(i uint8) []byte

func LeFillUpSize Uses

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

当b位数不够时,进行高位补0。 注意这里为了不影响原有输入参数,是采用的值复制设计。

type Bit Uses

type Bit int8

二进制位(0|1)

func DecodeBytesToBits Uses

func DecodeBytesToBits(bs []byte) []Bit

解析[]byte为字位数组[]uint8

func EncodeBits Uses

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

默认编码

func EncodeBitsWithUint Uses

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

将ui按位合并到bits数组中,并占length长度位(注意:uis数组中存放的是二进制的0|1数字)

Package gbinary imports 4 packages (graph) and is imported by 3 packages. Updated 2020-06-04. Refresh now. Tools for package owners.