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.
gbinary.go gbinary_be.go gbinary_bit.go gbinary_func.go gbinary_le.go
整形二进制解包,注意第二个及其后参数为字长确定的整形变量的指针地址,以便确定解析的[]byte长度, 例如:int8/16/32/64、uint8/16/32/64、float32/64等等
将二进制解析为bool类型,识别标准是判断二进制中数值是否都为0,或者为空。
将二进制解析为int类型,根据[]byte的长度进行自动转换. 注意内部使用的是uint*,使用int会造成位丢失。
将二进制解析为uint类型,根据[]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.
将变量转换为二进制[]byte,并指定固定的[]byte长度返回,长度单位为字节(byte); 如果转换的二进制长度超过指定长度,那么进行截断处理
自动识别int类型长度,转换为[]byte
自动识别uint类型长度,转换为[]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.
解析为int
解析为uint
将bits转换为[]byte,从左至右进行编码,不足1 byte按0往末尾补充
整形二进制解包,注意第二个及其后参数为字长确定的整形变量的指针地址,以便确定解析的[]byte长度, 例如:int8/16/32/64、uint8/16/32/64、float32/64等等
将二进制解析为bool类型,识别标准是判断二进制中数值是否都为0,或者为空。
将二进制解析为int类型,根据[]byte的长度进行自动转换. 注意内部使用的是uint*,使用int会造成位丢失。
将二进制解析为uint类型,根据[]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.
将变量转换为二进制[]byte,并指定固定的[]byte长度返回,长度单位为字节(byte); 如果转换的二进制长度超过指定长度,那么进行截断处理
自动识别int类型长度,转换为[]byte
自动识别uint类型长度,转换为[]byte
当b位数不够时,进行高位补0。 注意这里为了不影响原有输入参数,是采用的值复制设计。
二进制位(0|1)
解析[]byte为字位数组[]uint8
默认编码
将ui按位合并到bits数组中,并占length长度位(注意:uis数组中存放的是二进制的0|1数字)
Package gbinary imports 4 packages (graph) and is imported by 3 packages. Updated 2021-01-23. Refresh now. Tools for package owners.