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 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置