package module
Version: v0.0.0-...-c6586a6 Latest Latest

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

Go to latest
Published: Apr 17, 2019 License: BSD-3-Clause Imports: 2 Imported by: 4



Package hex implements hexadecimal encoding and decoding. It's taken almost verbatim from golang/encoding/hex, however it allows using a different set of encoding characters than the standard 0-F.



This section is empty.


View Source
var DefaultEncoding = NewEncoding("0123456789abcdef")

DefaultEncoding behaves just like golang/encoding/hex.

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

ErrLength results from decoding an odd length slice.


func DecodedLen

func DecodedLen(x int) int

func EncodedLen

func EncodedLen(n int) int

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


type Encoding

type Encoding struct {
	// contains filtered or unexported fields

An Encoding that uses a specific table of encoding characters.

func NewEncoding

func NewEncoding(hextable string) *Encoding

NewEncoding constructs an Encoding using the given hextable.

func (*Encoding) Decode

func (e *Encoding) Decode(dst, src []byte) (int, 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 error describing the failure.

func (*Encoding) DecodeString

func (e *Encoding) DecodeString(s string) ([]byte, error)

DecodeString returns the bytes represented by the hexadecimal string s.

func (*Encoding) Encode

func (e *Encoding) 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 (*Encoding) EncodeToString

func (e *Encoding) EncodeToString(src []byte) string

EncodeToString returns the hexadecimal encoding of src.

type InvalidByteError

type InvalidByteError byte

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

func (InvalidByteError) Error

func (e InvalidByteError) Error() string

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL