用golang 写了个server,java写了个client
通讯使用msgpack 进行打包,发现golang和java pack的包不一致
public class MyMessage { // public fields are serialized. public String name; public double version; } MyMessage src = new MyMessage(); src.name = "msgpack"; src.version = 0.6;
Java bytes :
bytes: [92 a7 6d 73 67 70 61 63 6b cb 3f e3 33 33 33 33 33 33 ]
golang
type UserStruct struct { Name string ID int32 } data, err := msgpack.Marshal(&user) if err == nil { fmt.Println("data:", data) } else { fmt.Println("err:", err) }
golang bytes:
go :[82 a4 6e 61 6d 65 a7 6d 73 67 70 61 63 6b a7 76 65 72 73 69 6f 6e cb 3f e3 33 33 33 33 33 33]
大概可以看出java的pack 省略了 field 的相关信息
有疑问加站长微信联系(非本文作者)