We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
假设客户端SRPCHttpClient的proto中定义了message、name两个字段,服务端的proto中只定义了name字段,此时客户端调用的时候,服务端会报RPCStatusReqDeserializeError;在我们的场景中,客户端多给一些参数期望是允许的,服务端这些参数可以不管;我看了下源码,在int SRPCMessage::deserialize(ProtobufIDLMessage *pb_msg)方法中原先的代码 if (JsonToBinaryStream(resolver, GetTypeUrl(pb_msg), &input_stream, &output_stream).ok()) { ret = pb_msg->ParseFromString(binary_output) ? 0 : -1; }
修改 util::JsonParseOptions options; options.ignore_unknown_fields = true;
if (JsonToBinaryStream(resolver, GetTypeUrl(pb_msg), &input_stream, &output_stream,options).ok()) { ret = pb_msg->ParseFromString(binary_output) ? 0 : -1; }
后续是否可以做成可配置,让调用方自己决定是否需要忽略未知的json字段;
The text was updated successfully, but these errors were encountered:
你好,你直接用SRPCServer和SRPCClient的话,是什么结果呢?理论上应该和Http的一样吧?
Sorry, something went wrong.
你好,这个建议非常有用!而且你定位很细致~
srpc现在可以设置util::JsonOptions,它在serialize()期间指导如何将protobuffer转化成json。 设置的入口在文档里有:docs-07-srpc-http.md SRPCMessage具体设置的地方是:
util::JsonOptions
srpc/src/message/rpc_message_srpc.cc
Line 466 in abeac13
而你提到的util::JsonParseOptions,它在deserialize()期间指导如何将json转化成protobuffer,因此和上述功能是对称的,也是原先一直缺少的一环。
util::JsonParseOptions
如果你感兴趣,可以仿照上面的入口,帮我们把这部分代码加上。或者我明天把这个加上也可以~
No branches or pull requests
假设客户端SRPCHttpClient的proto中定义了message、name两个字段,服务端的proto中只定义了name字段,此时客户端调用的时候,服务端会报RPCStatusReqDeserializeError;在我们的场景中,客户端多给一些参数期望是允许的,服务端这些参数可以不管;我看了下源码,在int SRPCMessage::deserialize(ProtobufIDLMessage *pb_msg)方法中原先的代码
if (JsonToBinaryStream(resolver, GetTypeUrl(pb_msg),
&input_stream, &output_stream).ok())
{
ret = pb_msg->ParseFromString(binary_output) ? 0 : -1;
}
修改
util::JsonParseOptions options;
options.ignore_unknown_fields = true;
if (JsonToBinaryStream(resolver, GetTypeUrl(pb_msg),
&input_stream, &output_stream,options).ok())
{
ret = pb_msg->ParseFromString(binary_output) ? 0 : -1;
}
后续是否可以做成可配置,让调用方自己决定是否需要忽略未知的json字段;
The text was updated successfully, but these errors were encountered: