const BytesPerLine
BytesPerLine is the classic 16.
Package hexdump renders bytes in the classic xxd/hexdump -C layout, as a pure, reusable package.
gno.land/p/moul/x/daily/hexdump/v0Classic xxd -C byte dump — Dump, 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.
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).
ASCII renders the printable-ASCII view of chunk: bytes outside 0x20..0x7e become ".". It is NOT padded — Line handles alignment.
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.
DumpString is Dump over a string's bytes.
Hex formats one byte as two lowercase hex digits.
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.
Offset formats an 8-digit lowercase hex offset.
Printable reports whether c renders as itself rather than as ".".