Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 source pure

Package hexdump renders bytes in the classic xxd/hexdump -C layout, as a pure, reusable package.

Readme View source

gno.land/p/moul/x/daily/hexdump/v0

Classic xxd -C byte dumpDump, DumpString, Line, Offset, Hex, ASCII, Printable, MaxBytes, BytesPerLine.

1import "gno.land/p/moul/x/daily/hexdump/v0"
2
3out, n := hexdump.DumpString("café")
4// 00000000  63 61 66 c3 a9                                    |caf..|
5// n == 5 — "é" is two bytes

The familiar layout: 8-digit hex offset, 16 bytes as hex in two 8-byte groups, then the ASCII view between pipes with non-printables as .. Short final lines are padded so the ASCII gutter never shifts — that alignment is the whole point of the format, and it has its own test asserting the gutter lands in the same column on a full and a partial line.

Useful on chain for the same reason it is useful off it: when a value is not what you expected, the bytes tell you why. Trailing whitespace, stray NULs, UTF-8 that is not what it claims — all invisible in a rendered string and obvious in a dump.

Dump returns the number of bytes rendered alongside the text, so truncation at MaxBytes (4096) is reported rather than silent.

Live demo: r/moul/x/daily/hexdumpdemo · render it at /r/moul/x/daily/hexdumpdemo/v0.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.

Overview

Package hexdump renders bytes in the classic xxd/hexdump -C layout, as a pure, reusable package.

The format is the familiar one: an 8-digit hex offset, then 16 bytes as hex in two 8-byte groups separated by an extra space, then the same bytes as ASCII between pipes with non-printables shown as ".". Short final lines are padded so the ASCII column stays aligned — the whole point of the layout.

Useful on chain for exactly the reason it is useful off it: when a value is not what you expected, the bytes tell you why. Encoding bugs, stray NULs, UTF-8 that is not what it claims, trailing whitespace — all invisible in a rendered string and obvious in a dump.

A live demo of this package is at r/moul/x/daily/hexdumpdemo(/r/moul/x/daily/hexdumpdemo/v0).

Constants 2

const MaxBytes

1const MaxBytes = 4096
source

MaxBytes bounds a dump so gas stays predictable. Input beyond this is truncated and reported by Dump's second return value.

Functions 7

func ASCII

1func ASCII(chunk []byte) string
source

ASCII renders the printable-ASCII view of chunk: bytes outside 0x20..0x7e become ".". It is NOT padded — Line handles alignment.

func Dump

1func Dump(b []byte) (string, int)
source

Dump renders b in the xxd -C layout. It returns the dump and the number of bytes rendered, which is less than len(b) when the input exceeds MaxBytes.

func DumpString

1func DumpString(s string) (string, int)
source

DumpString is Dump over a string's bytes.

func Hex

1func Hex(b byte) string
source

Hex formats one byte as two lowercase hex digits.

func Line

1func Line(offset int, chunk []byte) string
source

Line renders one line: offset, hex columns, ASCII gutter. chunk must hold at most BytesPerLine bytes; a shorter chunk is padded so columns stay aligned.

func Offset

1func Offset(n int) string
source

Offset formats an 8-digit lowercase hex offset.

func Printable

1func Printable(c byte) bool
source

Printable reports whether c renders as itself rather than as ".".

Imports 1

  • strings stdlib

Source Files 3