Playground
gnomod.toml
module = "gno.land/r/nym-moultest123/x/daily/hexdumpdemo/v0" gno = "0.9" [addpkg] creator = "g1ml9grtwnpzqn3hre5ve5vjdlmv2srrmpmc0dsv" height = 186411 max_deposit = "5000000ugnot"
hexdumpdemo.gno
// Package hexdumpdemo is a small gnoweb demo of the xxd-style byte dump
// provided by the [p/moul/x/daily/hexdump](/p/nym-moultest123/x/daily/hexdump/v0)
// library: it shows what a rendered string hides.
//
// It contains no formatting logic of its own. Stateless, so Render is
// deterministic — which is precisely what the library is for.
package hexdumpdemo
import (
"strconv"
"strings"
"gno.land/p/nym-moultest123/x/daily/hexdump/v0"
)
// Render renders the demo for gnoweb.
func Render(path string) string {
var b strings.Builder
b.WriteString("# Hexdump\n\n")
b.WriteString("Bytes in the classic `xxd -C` layout, demoing the ")
b.WriteString("[`p/moul/x/daily/hexdump`](/p/nym-moultest123/x/daily/hexdump/v0) library.\n\n")
b.WriteString("## A plain string\n\n")
dump("Hello, gno.land!", &b)
b.WriteString("\n## Alignment on a partial line\n\n")
b.WriteString("The last line is short, so the hex columns are padded and the ASCII ")
b.WriteString("gutter stays put — that alignment is the whole point of the layout.\n\n")
dump("0123456789abcdefhi", &b)
b.WriteString("\n## What a rendered string hides\n\n")
b.WriteString("These two look identical in any UI:\n\n")
b.WriteString("- `\"hi\"`\n- `\"hi \"` — one trailing space\n\n")
dump("hi", &b)
b.WriteString("\n")
dump("hi ", &b)
b.WriteString("\n## Multi-byte UTF-8\n\n")
b.WriteString("`\"café\"` is 5 bytes, not 4: `é` is `c3 a9`. Non-printables render as `.`.\n\n")
dump("café", &b)
b.WriteString("\n## Control characters\n\n")
b.WriteString("A NUL, a newline and a tab are invisible in text and obvious here.\n\n")
out, n := hexdump.Dump([]byte{0x00, 0x0a, 0x09, 'o', 'k'})
b.WriteString("```\n" + out + "```\n\n")
b.WriteString("_" + strconv.Itoa(n) + " bytes._\n")
return b.String()
}
func dump(s string, b *strings.Builder) {
out, n := hexdump.DumpString(s)
b.WriteString("```\n" + out + "```\n")
b.WriteString("\n_`" + s + "` → " + strconv.Itoa(n) + " bytes._\n")
}
render_example_test.gno
package hexdumpdemo
// ExampleRender pins the realm's Render output as a testable example.
func ExampleRender() {
print(Render(""))
// Output:
// # Hexdump
//
// Bytes in the classic `xxd -C` layout, demoing the [`p/moul/x/daily/hexdump`](/p/nym-moultest123/x/daily/hexdump/v0) library.
//
// ## A plain string
//
// ```
// 00000000 48 65 6c 6c 6f 2c 20 67 6e 6f 2e 6c 61 6e 64 21 |Hello, gno.land!|
// ```
//
// _`Hello, gno.land!` → 16 bytes._
//
// ## Alignment on a partial line
//
// The last line is short, so the hex columns are padded and the ASCII gutter stays put — that alignment is the whole point of the layout.
//
// ```
// 00000000 30 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 |0123456789abcdef|
// 00000010 68 69 |hi|
// ```
//
// _`0123456789abcdefhi` → 18 bytes._
//
// ## What a rendered string hides
//
// These two look identical in any UI:
//
// - `"hi"`
// - `"hi "` — one trailing space
//
// ```
// 00000000 68 69 |hi|
// ```
//
// _`hi` → 2 bytes._
//
// ```
// 00000000 68 69 20 |hi |
// ```
//
// _`hi ` → 3 bytes._
//
// ## Multi-byte UTF-8
//
// `"café"` is 5 bytes, not 4: `é` is `c3 a9`. Non-printables render as `.`.
//
// ```
// 00000000 63 61 66 c3 a9 |caf..|
// ```
//
// _`café` → 5 bytes._
//
// ## Control characters
//
// A NUL, a newline and a tab are invisible in text and obvious here.
//
// ```
// 00000000 00 0a 09 6f 6b |...ok|
// ```
//
// _5 bytes._
}