diff options
| author | Shulhan <ms@kilabit.info> | 2023-03-22 14:02:15 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-03-22 22:37:51 +0700 |
| commit | bffd1f6ec0f6b63ed3f6b38c2bfddc6277ba86b8 (patch) | |
| tree | 146071bbff464b0c47cecf6757fdc7a5f1fc49f3 /lib/bytes/bytes_example_test.go | |
| parent | 3bd5fad4c0a972dd279ecfbf77de31838764f609 (diff) | |
| download | pakakeh.go-bffd1f6ec0f6b63ed3f6b38c2bfddc6277ba86b8.tar.xz | |
lib/bytes: add function DumpPrettyTable
The DumpPrettyTable write each byte in slice data as hexadecimal, ASCII
character, and integer with 8 columns width.
Diffstat (limited to 'lib/bytes/bytes_example_test.go')
| -rw-r--r-- | lib/bytes/bytes_example_test.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/bytes/bytes_example_test.go b/lib/bytes/bytes_example_test.go index da8dcce2..ee87776c 100644 --- a/lib/bytes/bytes_example_test.go +++ b/lib/bytes/bytes_example_test.go @@ -5,6 +5,7 @@ package bytes import ( + "bytes" "fmt" "math" @@ -397,6 +398,22 @@ func ExampleWordIndexes() { // [] } +func ExampleDumpPrettyTable() { + var ( + data = []byte{1, 2, 3, 'H', 'e', 'l', 'l', 'o', 254, 255} + bb bytes.Buffer + ) + + DumpPrettyTable(&bb, `DumpPrettyTable`, data) + fmt.Println(bb.String()) + // Output: + // DumpPrettyTable + // | 0 1 2 3 4 5 6 7| 0 1 2 3 4 5 6 7| 0 1 2 3 4 5 6 7| + // | 8 9 A B C D E F| 8 9 A B C D E F| 8 9 A B C D E F| + // 0x00| 01 02 03 48 65 6c 6c 6f| . . . H e l l o| 1 2 3 72 101 108 108 111|00 + // 0x08| fe ff | . . | 254 255 |08 +} + func ExampleWriteUint16() { data := []byte("Hello, world!") |
