Can golang protocol buffers with gRPC be cross compiled and used on different OS platforms?

huangapple go评论80阅读模式
英文:

Can golang protocol buffers with gRPC be cross compiled and used on different OS platforms?

问题

这个问题是关于在不同的操作系统平台上编译和使用golang协议缓冲区(使用gRPC)的,我还没有见过类似的问题。在Windows上编译一个.proto文件,然后在Linux上使用生成的文件,这种做法可行吗?反之亦然?

我在Windows和Linux上编译了同一个.proto文件,使用diff命令显示了不同的结果。一个区别是Windows编译版本有时会在请求结构体的字段中重复出现json,例如:Field1Name *type`protobuf ,bytes,1,opt,name=my_name,json=myName" json:"my_name,omitempty"` ,而Linux版本是:Field1Name *type`protobuf ,bytes,1,opt,name=my_name" json:"my_name,omitempty"` 。这种情况经常发生,有时所有字段都有这个问题,有时只有一部分字段有问题,有时对于给定的请求结构体没有任何字段有问题。

另一个区别是底部的fileDescriptor在两个版本中完全不同。Windows版本比Linux版本多大约40行。

英文:

This question is specifically about compiling and using golang protocol buffers (with gRPC) on different OS platforms and I haven't seen any like it. Is it possible to compile a .proto file on Windows, and then use the generated file on Linux? Or vice versa?

I compiled the same .proto file on both Windows and Linux and diff showed different results. One difference is that the Windows compiled version sometimes repeats json in fields of request structs like this: Field1Name *type`protobuf ,bytes,1,opt,name=my_name,json=myName" json:"my_name,omitempty"` whereas the Linux version is: Field1Name *type`protobuf ,bytes,1,opt,name=my_name" json:"my_name,omitempty"` . This happens a lot, sometimes all the fields have this issue, sometimes only some of them, and sometimes none of them for a given request struct.

The other difference is that the fileDescriptor at the bottom is completely different for the two versions. The Windows version is longer by about 40 lines.

答案1

得分: 1

如果您使用相同版本的基于Go的工具来编译proto文件,您应该会得到相同的输出。我建议您再次确认两者是否是相同的版本。

英文:

If you're using the same version of the same Go-based tool to compile the proto, you should get the same output. I would double-check that both are identical versions.

huangapple
  • 本文由 发表于 2017年8月10日 23:51:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/45618300.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定