Documentation ¶
Index ¶
- Constants
- Variables
- func BytesBCC(bytes []byte) byte
- func GB18030StrToUTF8(str string) (string, error)
- func GBKStrToUTF8(str string) (string, error)
- func UTF8StrToGB18030(str string) (string, error)
- func UTF8StrToGBK(str string) (string, error)
- type AsciiEncoder
- type BcdEncoder
- func (b *BcdEncoder) AssignLenDecode(src []byte, length int) ([]byte, error)
- func (b *BcdEncoder) BcdToInt(data []byte) (int, error)
- func (b *BcdEncoder) BcdToUint32(data []byte) (uint32, error)
- func (b *BcdEncoder) BcdToUint64(data []byte) (uint64, error)
- func (b *BcdEncoder) Decode(src []byte) (dst []byte, err error)
- func (b *BcdEncoder) Encode(src []byte) (dst []byte, err error)
- func (b *BcdEncoder) IntToBcd(v int) ([]byte, error)
- func (b *BcdEncoder) Uint64ToBcd(v uint64) ([]byte, error)
- func (b *BcdEncoder) UintToBcd(v uint) ([]byte, error)
- type BinaryEncoder
- type Charset
- type Encoder
- type GBKEncoder
- type HexEncoder
Constants ¶
const ( UTF8 = Charset("UTF-8") GB18030 = Charset("GB18030") GBK = Charset("GBK") )
Variables ¶
var EncodeGroup = new(encodeGroup)
EncodeGroup 对外统一开放一个解码组
Functions ¶
func GB18030StrToUTF8 ¶
GB18030StrToUTF8 GBK 字符串转UTF
func UTF8StrToGB18030 ¶
UTF8StrToGB18030 UTF 字符串转 GB18030
Types ¶
type AsciiEncoder ¶
type AsciiEncoder struct{}
func (AsciiEncoder) AssignLenDecode ¶
AssignLenDecode 指定长度 ASCII 解码
type BcdEncoder ¶
type BcdEncoder struct{}
BcdEncoder bcd 编码一般只针对数字
func (*BcdEncoder) AssignLenDecode ¶
func (b *BcdEncoder) AssignLenDecode(src []byte, length int) ([]byte, error)
AssignLenDecode 指定长度解析
func (*BcdEncoder) BcdToInt ¶
func (b *BcdEncoder) BcdToInt(data []byte) (int, error)
BcdToInt bcd 转int
func (*BcdEncoder) BcdToUint32 ¶
func (b *BcdEncoder) BcdToUint32(data []byte) (uint32, error)
BcdToUint32 bcd转 unit32
func (*BcdEncoder) BcdToUint64 ¶
func (b *BcdEncoder) BcdToUint64(data []byte) (uint64, error)
BcdToUint64 bcd转 unit64
func (*BcdEncoder) Decode ¶
func (b *BcdEncoder) Decode(src []byte) (dst []byte, err error)
Decode 解码
func (*BcdEncoder) Encode ¶
func (b *BcdEncoder) Encode(src []byte) (dst []byte, err error)
Encode 编码
func (*BcdEncoder) IntToBcd ¶
func (b *BcdEncoder) IntToBcd(v int) ([]byte, error)
IntToBcd int 转bcd
func (*BcdEncoder) Uint64ToBcd ¶
func (b *BcdEncoder) Uint64ToBcd(v uint64) ([]byte, error)
Uint64ToBcd 64位无符号正数转bcd
type BinaryEncoder ¶
type BinaryEncoder struct{}
func (*BinaryEncoder) ByteToBinStr ¶
func (e *BinaryEncoder) ByteToBinStr(b byte) string
ByteToBinStr 将byte 以8个bit位的形式展示
func (*BinaryEncoder) BytesToBinStr ¶
func (e *BinaryEncoder) BytesToBinStr(bs []byte) string
BytesToBinStr 将byte数组转成8个bit位一组的字符串
func (*BinaryEncoder) BytesToBinStrWithSplit ¶
func (e *BinaryEncoder) BytesToBinStrWithSplit(bs []byte, split string) string
BytesToBinStrWithSplit 将byte数组转8个bit一组的字符串并且带分割符
type GBKEncoder ¶
type GBKEncoder struct{}
GBKEncoder GBK 编码器, go 语言默认使用UTF-8编码,国内很多协议使用的编码规范为 GBK,或 GB18030
type HexEncoder ¶
type HexEncoder struct{}
HexEncoder hex 编码器
func (*HexEncoder) BytesToHex ¶
func (e *HexEncoder) BytesToHex(data []byte) string
BytesToHex 字节数组转hex []byte{0x55, 0xAA} 被转成 55AA
func (*HexEncoder) Decode ¶
func (h *HexEncoder) Decode(src []byte) (dst []byte, err error)
Decode 解码 AABBCC 转成字节数组 []byte{0xAA, 0xBB, 0xCC}
func (*HexEncoder) Encode ¶
func (h *HexEncoder) Encode(src []byte) (dst []byte, err error)
Encode 编码 []byte{0x55, 0xAA} 被转成 55AA
func (*HexEncoder) HexToBytes ¶
func (e *HexEncoder) HexToBytes(hexStr string) ([]byte, error)
HexToBytes 将hex 字符串转成 byte数组 AABBCC 转成字节数组 []byte{0xAA, 0xBB, 0xCC}