Run Format

Package hex

import "encoding/hex"

Overview ▾

Package hex implements hexadecimal encoding and decoding.


ErrLength results from decoding an odd length slice.

var ErrLength = errors.New("encoding/hex: odd length hex string")

func Decode

Decode decodes src into DecodedLen(len(src)) bytes, returning the actual number of bytes written to dst.

If Decode encounters invalid input, it returns an error describing the failure.

func Decode(dst, src []byte) (int, error)

func DecodeString

DecodeString returns the bytes represented by the hexadecimal string s.

func DecodeString(s string) ([]byte, error)

func DecodedLen

func DecodedLen(x int) int

func Dump

Dump returns a string that contains a hex dump of the given data. The format of the hex dump matches the output of `hexdump -C` on the command line.

func Dump(data []byte) string

func Dumper

Dumper returns a WriteCloser that writes a hex dump of all written data to w. The format of the dump matches the output of `hexdump -C` on the command line.

func Dumper(w io.Writer) io.WriteCloser

func Encode

Encode encodes src into EncodedLen(len(src)) bytes of dst. As a convenience, it returns the number of bytes written to dst, but this value is always EncodedLen(len(src)). Encode implements hexadecimal encoding.

func Encode(dst, src []byte) int

func EncodeToString

EncodeToString returns the hexadecimal encoding of src.

func EncodeToString(src []byte) string

func EncodedLen

EncodedLen returns the length of an encoding of n source bytes.

func EncodedLen(n int) int

type InvalidByteError

InvalidByteError values describe errors resulting from an invalid byte in a hex string.

type InvalidByteError byte

func (InvalidByteError) Error

func (e InvalidByteError) Error() string