英文:
Consistent Cross Platform Proto3 Serialization / Deserialization
问题
我有一个基于golang的GRPC服务,使用proto3定义。
对于一个简单的响应,只有一个bool字段,如果值为false
,整个消息将被序列化为空(零长度)数据负载(作为我的怀疑,将false
视为默认值)。
与此同时,使用相同的.proto
定义构建的节点的GRPC客户端将该值解释为undefined
(而true
的情况非常一致)。
调试服务器构建响应的方式,我注意到stream.ContentSubtype()
返回一个空字符串,因此在s.getCodec
中它会回退到encoding/proto.Name
,即proto
。然后在这里进一步进行编码。
func marshalAppend(buf []byte, m Message, deterministic bool) ([]byte, error) {
if m == nil {
return nil, ErrNil
}
mi := MessageV2(m)
nbuf, err := protoV2.MarshalOptions{
Deterministic: deterministic,
AllowPartial: true,
}.MarshalAppend(buf, mi)
这看起来确实是protoV2
的实现。
所以我不知道真正的问题是什么:
-
stream.ContentSubtype()
是否应该在通信层面上进行控制,由谁负责(客户端/服务器)? -
在从
.proto
定义生成客户端/服务器源代码时,是否应该遵循任何其他的控制步骤/操作?.proto
本身是否足够泛化元数据以输出一致的源代码? -
proto3
是否应该使用protoV2
实现进行成功编码? -
还有什么其他原因可能导致这种不一致的值处理?
英文:
I have a golang based GRPC service defined with proto3
syntax = "proto3";
For a simple Response of a single bool filed if the value is false
the whole message is serialized just as an empty (zero length) data payload. (as my suspect, treating false
as a default one)
Same time a node's GRPC client built from the very same .proto
definition interprets the value as an undefined
. (while true
one is pretty consistent)
Debugging the way server builds the response
data, err := encode(s.getCodec(stream.ContentSubtype()), msg)
I've noticed, stream.ContentSubtype()
returns an empty string so that within s.getCodec
it is falls back to encoding/proto.Name
which is just proto
. And it leads further encoding something over here
func marshalAppend(buf []byte, m Message, deterministic bool) ([]byte, error) {
if m == nil {
return nil, ErrNil
}
mi := MessageV2(m)
nbuf, err := protoV2.MarshalOptions{
Deterministic: deterministic,
AllowPartial: true,
}.MarshalAppend(buf, mi)
Which looks like really protoV2
implementation.
So I don't know what is really the right question here
-
Should
stream.ContentSubtype()
be somehow controlled on a communication level and who's to be responsible for this (Client/Server) -
Should any additional control steps/actions be followed while generating client/server source codes from the
.proto
definition. Doesn't.proto
it self generalize the meta enough to output consistent sources? -
Should/Cloud
proto3
be really encoded successfully withprotoV2
implementation? -
What else could cause such inconsistent values treatment?
答案1
得分: 0
原来这不是配置错误,而是特定实现的问题。
六天前,在 porto-gen-ts v0.8.5 中修复了这个问题。
感谢 @Brits 的查找。
英文:
Turned out this was nothing with misconfiguration but a matter of specific implementation.
Six days ago it was fixed within porto-gen-ts v0.8.5
Thanks @Brits for a lookup
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论