douwen1006 2017-03-04 19:33
浏览 112
已采纳

gob编码有什么作用?

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
  • 写回答

1条回答 默认 最新

  • duanchifo2866 2017-03-04 20:19
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题