FAQ
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!|
}
}

<https://twitter.com/search?q=%23golang>

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Dan Kortschak at Mar 9, 2013 at 5:36 am
    Very nice. Thanks for your work.

    On 09/03/2013, at 3:41 PM, "Dave Collins" wrote:

    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!|
    }
    }

    <https://twitter.com/search?q=%23golang>

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com .
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Damian Gryski at Mar 9, 2013 at 7:03 am
    I've also been doing some protocol work, but mine was in C (server) and
    Perl (client). As a result, I wanted something I could inject between them
    to see what was going across the wire rather than havinv to fall back to
    wireshark.

    The result is https://github.com/dgryski/dhd (mostly undocumented, but
    that's what you get with personal utilities sometimes :)

    The short version is:

    terminal1$ nc -l 10000 # listen on port 10000
    terminal2$ dhd -p 10001:localhost:10000 # proxy local port 10001 ->
    localhost:10000
    terminal3$ nc localhost 10001 # connect to local port 10001

    And now you'll get output like:
    2013/03/09 08:00:26 tcp server starting
    00000000: 68 65 6c 6c 6f 2c 20 77 6f 72 6c 64 0a
    hello,.world.|
    <00000000: 68 65 6c 6c 6f 20 62 61 63 6b 0a
    hello.back.|
    I have a couple of small TODOs, like adding connection info and timestamps
    to the output, but this has been sufficient for me to hunt down some pretty
    ugly bugs on a couple of occasions.

    Damian

    Le samedi 9 mars 2013 06:11:11 UTC+1, Dave Collins a écrit :
    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!|
    }
    }

    <https://twitter.com/search?q=%23golang>
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Dan Kortschak at Mar 9, 2013 at 7:19 am
    An idea that sort of (tenuously) follows from this is the capacity to print Go syntax dumps with reasonable line lengths (obviously excluding circular structures). This would be a boon when including, for example, application data that's generated and included in the compilation unit.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Minux at Mar 9, 2013 at 9:03 pm

    On Sat, Mar 9, 2013 at 1:11 PM, Dave Collins wrote:
    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.
    Thank you for this great debugging aid.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 9, '13 at 5:11a
activeMar 9, '13 at 9:03p
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase