The Go Programming Language

Package hex

import "encoding/hex"

Package hex implements hexadecimal encoding and decoding.

Package files

hex.go

func Decode

func Decode(dst, src []byte) (int, os.Error)

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 OddLengthInputError or an InvalidHexCharError.

func DecodeString

func DecodeString(s string) ([]byte, os.Error)

DecodeString returns the bytes represented by the hexadecimal string s.

func DecodedLen

func DecodedLen(x int) int

func Dump

func Dump(data []byte) string

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 Dumper

func Dumper(w io.Writer) io.WriteCloser

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 Encode

func Encode(dst, src []byte) int

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 EncodeToString

func EncodeToString(src []byte) string

EncodeToString returns the hexadecimal encoding of src.

func EncodedLen

func EncodedLen(n int) int

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

type InvalidHexCharError

InvalidHexCharError results from finding an invalid character in a hex string.

type InvalidHexCharError byte

func (InvalidHexCharError) String

func (e InvalidHexCharError) String() string

type OddLengthInputError

OddLengthInputError results from decoding an odd length slice.

type OddLengthInputError struct{}

func (OddLengthInputError) String

func (OddLengthInputError) String() string

release.r60.3. Except as noted, this content is licensed under a Creative Commons Attribution 3.0 License.