encoding

package
v0.0.0-...-a7cdbd9 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UTF8    = Charset("UTF-8")
	GB18030 = Charset("GB18030")
	GBK     = Charset("GBK")
)

Variables

View Source
var EncodeGroup = new(encodeGroup)

EncodeGroup 对外统一开放一个解码组

Functions

func BytesBCC

func BytesBCC(bytes []byte) byte

BytesBCC 计算 BCC

func GB18030StrToUTF8

func GB18030StrToUTF8(str string) (string, error)

GB18030StrToUTF8 GBK 字符串转UTF

func GBKStrToUTF8

func GBKStrToUTF8(str string) (string, error)

GBKStrToUTF8 GBK 字符串转UTF

func UTF8StrToGB18030

func UTF8StrToGB18030(str string) (string, error)

UTF8StrToGB18030 UTF 字符串转 GB18030

func UTF8StrToGBK

func UTF8StrToGBK(str string) (string, error)

UTF8StrToGBK UTF 字符串转 GBK

Types

type AsciiEncoder

type AsciiEncoder struct{}

func (AsciiEncoder) AssignLenDecode

func (a AsciiEncoder) AssignLenDecode(data []byte, length int) ([]byte, int, error)

AssignLenDecode 指定长度 ASCII 解码

func (AsciiEncoder) Decode

func (a AsciiEncoder) Decode(data []byte) ([]byte, error)

Decode 指定长度 ASCII 解码

func (AsciiEncoder) Encode

func (a AsciiEncoder) Encode(data []byte) ([]byte, error)

Encode 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

func (*BcdEncoder) UintToBcd

func (b *BcdEncoder) UintToBcd(v uint) ([]byte, error)

UintToBcd 无符号正数转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 Charset

type Charset string

type Encoder

type Encoder interface {
	// Encode 编码
	Encode([]byte) ([]byte, error)

	// Decode 解码
	Decode([]byte) (data []byte, err error)
}

type GBKEncoder

type GBKEncoder struct{}

GBKEncoder GBK 编码器, go 语言默认使用UTF-8编码,国内很多协议使用的编码规范为 GBK,或 GB18030

func (*GBKEncoder) Decode

func (g *GBKEncoder) Decode(src []byte) (data []byte, err error)

Decode 解码 gbk 转到 utf-8

func (*GBKEncoder) Encode

func (g *GBKEncoder) Encode(src []byte) ([]byte, error)

Encode 编码 utf-8 转到 gbk

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) HexBCC

func (e *HexEncoder) HexBCC(hexStr string) string

HexBCC 计算BCC校验码

func (*HexEncoder) HexToBytes

func (e *HexEncoder) HexToBytes(hexStr string) ([]byte, error)

HexToBytes 将hex 字符串转成 byte数组 AABBCC 转成字节数组 []byte{0xAA, 0xBB, 0xCC}

Jump to

Keyboard shortcuts

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