企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# package hex `import "encoding/hex"` hex包实现了16进制字符表示的编解码。 ## Index * [Variables](#pkg-variables) * [type InvalidByteError](#InvalidByteError) * [func (e InvalidByteError) Error() string](#InvalidByteError.Error) * [func DecodedLen(x int) int](#DecodedLen) * [func Decode(dst, src []byte) (int, error)](#Decode) * [func DecodeString(s string) ([]byte, error)](#DecodeString) * [func EncodedLen(n int) int](#EncodedLen) * [func Encode(dst, src []byte) int](#Encode) * [func EncodeToString(src []byte) string](#EncodeToString) * [func Dump(data []byte) string](#Dump) * [func Dumper(w io.Writer) io.WriteCloser](#Dumper) ## Variables ``` var ErrLength = errors.New("encoding/hex: odd length hex string") ``` 解码一个长度为奇数的切片时,将返回此错误。 ## type [InvalidByteError](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L37 "View Source") ``` type InvalidByteError byte ``` 描述一个hex编码字符串中的非法字符。 ### func (InvalidByteError) [Error](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L39 "View Source") ``` func (e InvalidByteError) Error() string ``` ## func [DecodedLen](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L43 "View Source") ``` func DecodedLen(x int) int ``` 长度x的编码数据解码后的明文数据的长度 ## func [Decode](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L49 "View Source") ``` func Decode(dst, src []byte) (int, error) ``` 将src解码为DecodedLen(len(src))字节,返回实际写入dst的字节数;如遇到非法字符,返回描述错误的error。 ## func [DecodeString](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L91 "View Source") ``` func DecodeString(s string) ([]byte, error) ``` 返回hex编码的字符串s代表的数据。 ## func [EncodedLen](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L18 "View Source") ``` func EncodedLen(n int) int ``` 长度x的明文数据编码后的编码数据的长度。 ## func [Encode](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L24 "View Source") ``` func Encode(dst, src []byte) int ``` 将src的数据解码为EncodedLen(len(src))字节,返回实际写入dst的字节数:EncodedLen(len(src))。 ## func [EncodeToString](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L84 "View Source") ``` func EncodeToString(src []byte) string ``` 将数据src编码为字符串s。 ## func [Dump](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L103 "View Source") ``` func Dump(data []byte) string ``` 返回给定数据的hex dump格式的字符串,这个字符串与控制台下`hexdump -C`对该数据的输出是一致的。 ## func [Dumper](https://github.com/golang/go/blob/master/src/encoding/hex/hex.go#L114 "View Source") ``` func Dumper(w io.Writer) io.WriteCloser ``` 返回一个io.WriteCloser接口,将写入的数据的hex dump格式写入w,具体格式为'hexdump -C'。