2

Does gob encoding/decoding do anything ? In the example below , data looks the same before and after decoding. I am confused, please advise

data = "ABC"
    buf := new(bytes.Buffer)

    //glob encoding
    enc := gob.NewEncoder(buf)
    enc.Encode(data)
    fmt.Println("Encoded:", data)  //Encoded: ABC

    //glob decoding
    d := gob.NewDecoder(buf)
    d.Decode(data)
    fmt.Println("Decoded: ", data) //Decoded:  ABC
irom
  • 3,316
  • 14
  • 54
  • 86
  • 2
    It encodes into `buf`, that's why you created the encoder with `buf` as the `io.Writer` – JimB Mar 04 '17 at 19:37

1 Answers1

4

Your comparison is wrong - comparing the data being encoded (data) to the result after being decoded (d.Decode(data)), will obviously lead you to the same result (if everything is working as expected).

The encoding itself will be presented in the underline bytes buffer (try to print the buffer itself - fmt.Println(buf.Bytes())).

Read more on the gob package

Shmulik Klein
  • 3,754
  • 19
  • 34