package hex

import "github.com/gobuffalo/packr/v2/file/resolver/encoding/hex"

Package hex implements hexadecimal encoding and decoding.

Index

Variables

var ErrLength = fmt.Errorf("encoding/hex: odd length hex string")

ErrLength reports an attempt to decode an odd-length input using Decode or DecodeString. The stream-based Decoder returns io.ErrUnexpectedEOF instead of ErrLength.

Functions

func Decode

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

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

Decode expects that src contains only hexadecimal characters and that src has even length. If the input is malformed, Decode returns the number of bytes decoded before the error.

func DecodeString

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

DecodeString returns the bytes represented by the hexadecimal string s.

DecodeString expects that src contains only hexadecimal characters and that src has even length. If the input is malformed, DecodeString returns the bytes decoded before the error.

func DecodedLen

func DecodedLen(x int) int

DecodedLen returns the length of a decoding of x source bytes. Specifically, it returns x / 2.

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. Specifically, it returns n * 2.

func NewDecoder

func NewDecoder(r io.Reader) io.Reader

NewDecoder returns an io.Reader that decodes hexadecimal characters from r. NewDecoder expects that r contain only an even number of hexadecimal characters.

func NewEncoder

func NewEncoder(w io.Writer) io.Writer

NewEncoder returns an io.Writer that writes lowercase hexadecimal characters to w.

Types

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

hex.go

Version
v2.8.3 (latest)
Published
Nov 23, 2021
Platform
js/wasm
Imports
3 packages
Last checked
11 hours ago

Tools for package owners.