Hello gophers,
I've just updated go-spew (
https://github.com/davecgh/go-spew) to dump byte
arrays and slices like the hexdump -C command does. While doing some protocol
work, I found myself dumping byte slices frequently. They really didn't print
all that nicely, so this is the result.
Assuming the following code:
type foo struct {
n int
b []byte
}
b := []byte{
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
0x21, 0x22, 0x23, 0x34, 0x48, 0x65, 0x6c, 0x6c,
0x6f, 0x20, 0x47, 0x6f, 0x70, 0x68, 0x65, 0x72,
0x73, 0x21,
}
f := foo{123, b}
The spew.Dump(f) output is as follows:
(main.foo) {
n: (int) 123,
b: ([]uint8) {
00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... |
00000010 21 22 23 34 48 65 6c 6c 6f 20 47 6f 70 68 65 72 |!"#4Hello Gopher|
00000020 73 21 |s!|
}
}