repositorypackage
0.0.0-20201207135334-b59baa2c678e
Repository: https://github.com/sea-project/stdlib-bytes.git
Documentation: pkg.go.dev
# README
关于类型转换的工具类
目录
序号 | 名称 | 描述 |
---|---|---|
1 | bytes.go | 关于bytes转换的常用方法 |
ToHex | ToHex返回以“0x”为前缀的b的十六进制表示。对于空片,返回值是“0x0” | |
ToHexArray | ToHexArray创建一个基于[]字节的十六进制字符串数组 | |
FromHex | FromHex返回由十六进制字符串 | |
Bytes2Hex | Bytes2Hex返回十六进制编码 | |
Hex2Bytes | Hex2Bytes返回十六进制字符串所代表的字节 | |
Hex2BytesFixed | Hex2BytesFixed返回指定长度的字节 | |
CopyBytes | CopyBytes返回所提供字节的精确副本 | |
Int2bytes | int类型 转 bytes类型 | |
Bytes2int | bytes转int类型 | |
Int82bytes | int8类型转为 Bytes | |
Bytes2int8 | bytes转int8类型 | |
int162bytes | int16转bytes | |
Bytes2int16 | bytes转int16 | |
Int322bytes | int32转bytes | |
Bytes2int32 | bytes转int32 | |
Int642bytes | int64转Bytes | |
Bytes2int64 | bytes转int64 | |
Uint2bytes | uint转bytes | |
Bytes2uint | bytes转uint | |
Uint82bytes | uint8转bytes | |
Bytes2uint8 | bytes转uint8 | |
Uint162bytes | uint16转bytes | |
Bytes2uint16 | bytes转uint16 | |
Uint322bytes | uint32转bytes | |
Bytes2uint32 | bytes转uint32 | |
Uint642bytes | uint64转bytes | |
Bytes2uint64 | bytes转uint64 | |
Bool2bytes | bool转bytes | |
Bytes2bool | bytes转bool | |
Error2bytes | error转bytes | |
Bytes2error | bytes转error | |
Rune2bytes | rune转bytes | |
Bytes2rune | bytes 转rune | |
Float642bytes | float64转bytes | |
Bytes2float64 | bytes转float | |
Float322bytes | float32转bytes | |
Bytes2float32 | bytes转float32 | |
getData | 根据开始和大小从数据中返回一个切片,并以零填充。此功能是溢出安全的 | |
RightPadBytes | 右padbytes 0 -pad片向右直到长度l。如如果L长度小于切片长度则直接输出,如果L长度大于数组长度则右边补0至L长度 | |
LeftPadBytes | left - padbytes向左切片至长度l。如果L长度小于切片长度则直接输出,如果L长度大于数组长度则左边补0至L长度 | |
2 | types.go | 关于hash、sign、address等转换的常用方法 |
Bytes | Bytes获取基础散列的字节表示 | |
Big | Big将散列转换为大整数 | |
Hex | 十六进制将散列转换为十六进制字符串 | |
TerminalString | TerminalString实现日志。在日志记录期间格式化控制台输出的字符串 | |
String | String实现了stringer接口,并且在对文件进行完整日志记录时也被日志记录器使用 | |
Format | 实现了fmt格式。格式化程序,强制按原样格式化字节片,而不需要通过用于日志记录的stringer接口 | |
BytesToHash | 将byte数组转换为hash | |
BigToHash | BigToHash将b的字节表示设置为hash | |
HexToHash | 将十六进制的字符串表示为hash | |
BytesToAddress | byte转address | |
StringToAddress | String转Address返回字节 | |
BigToAddress | Big转Address返回字节值为b的地址 | |
HexToAddress | 十六进制字符串转地址 | |
IsHexAddress | 验证字符串是否可以表示有效的十六进制编码的地址 | |
Bytes | 字节获取底层地址的字符串表示形式 | |
Big | Big将地址转换为一个大整数 | |
Hash | 哈希通过左填充0将地址转换为哈希 | |
Hex | 十六进制返回地址的十六进制字符串表示形式 | |
BytesToSign | bytes转sign | |
HexToSign | 十六进制字符串转为sign |
单元测试
序号 | 名称 | 说明 |
---|---|---|
1 | bytes_test.go | 对bytes常用方法进行功能测试 |
Test_ToHex | 测试byte数组转换为以0x十六进制字符串 | |
Test_Bytes2Hex | 测试byte数组转换为十六进制字符串 | |
Test_Hex2BytesFixed | Hex2BytesFixed返回指定长度的字节 | |
Test_RightPadBytes | 右padbytes 0 -pad片向右直到长度L | |
Test_LeftPadBytes | left - padbytes向左切片至长度L | |
2 | types_test.go | 对hash、sign、address常用方法进行功能测试 |
Test_BytesToHash | 测试bytes 转 Hash | |
Test_HexToHash | 测试十六进制字符串转hash | |
Test_BytesToAddress | 测试 byte转address | |
Test_StringToAddress | 测试string转address | |
Test_BigToAddress | 测试big.int转地址 | |
Test_IsHexAddress | 测试是否为有效的十六进制地址.int转地址 | |
Test_BytesToSign | 测试bytes转 sign | |
Test_HexToSign | 测试十六进制转sign |