hxx

package module
v0.0.0-...-a67255a Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: MIT Imports: 6 Imported by: 0

README

hxx

golang hex dumps made easy.

hxx is library for turning values into memory images that can be printed as hex dumps (or binary, octal or dec dumps).

Objects for dumping are wrapped in a Dump object using NewDump. Dump objects can then be printed using standard formatting functions such as fmt.Printf.

Example:


	input0 := `Lorem Ipsum.`
	fmt.Printf("%v\n", hxx.NewDump(input0))

	// Output:
	// 0: 4c 6f 72 65 6d 20 49 70 73 75 6d 2e              Lorem Ipsum.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Fill = '.'

Functions

This section is empty.

Types

type Dump

type Dump []byte

Dump at memory layout representation of an object

func NewDump

func NewDump(o interface{}) Dump

NewDump return a dump object. o may be any primitive type or pointer to any other object type.

func (Dump) Chars

func (d Dump) Chars(fill rune, latin1 bool) string

Chars produce a string that represents the dump as a string of characters, one character per byte. fill is used for characters that do not have a graphic representation. latin1 determines if high characters should be used to represent bytes.

func (Dump) Format

func (d Dump) Format(f fmt.State, c rune)

Format support for "fmt" package Printf functions.

supported formatter verbs: ``` s output bytes as ASCII characters, one character per byte. ASCII control characters or characters outside the 7 bit

range are displayed as '.'.

x print dump as compact string of hex digits, width supported. b represent bytes in the dump with eight binary digits. o represent bytes in the dump with three octal digits. d represent bytes in the dump with three decimal digits. x represent bytes in the dump with two hex digits. ```

supported formatter flags: ``` # include latin1 characters in the output - remove ascii display from hexdump 0 zero-fill bytes ```

The format precision for `%b`, `%o`, `%d` and `%x` specifies the number of bytes output per line.

func (Dump) Hex

func (d Dump) Hex(w int) string

Hex print w hex digits from d and fill with zeros to w

func (Dump) Stringify

func (d Dump) Stringify(c, littlendian, latin1, zerofill bool, bcount, group, base int) (s string)

Stringify produce a hex-dump string from a dump object, d. Each line will being with an address followed by each byte. if c is true, the ascii representation of the preceding bytes will follow. latin1 will allow latin1 characters in the output string. littledian will output grouped bytes in little-endian order. bcount controls the number of bytes output on each line of the hex-dump. if zerofill is true, each byte will be filled in with leading zeros.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL