Skip to content
New issue

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

SRPC Http客户端与服务端参数不一致问题 #397

Open
rayinengineer opened this issue Jul 12, 2024 · 2 comments
Open

SRPC Http客户端与服务端参数不一致问题 #397

rayinengineer opened this issue Jul 12, 2024 · 2 comments

Comments

@rayinengineer
Copy link

rayinengineer commented Jul 12, 2024

假设客户端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字段;

@Barenboim
Copy link
Contributor

你好,你直接用SRPCServer和SRPCClient的话,是什么结果呢?理论上应该和Http的一样吧?

@holmes1412
Copy link
Contributor

holmes1412 commented Jul 12, 2024

你好,这个建议非常有用!而且你定位很细致~

srpc现在可以设置util::JsonOptions,它在serialize()期间指导如何将protobuffer转化成json
设置的入口在文档里有:docs-07-srpc-http.md
SRPCMessage具体设置的地方是:

util::JsonOptions options;

而你提到的util::JsonParseOptions,它在deserialize()期间指导如何将json转化成protobuffer,因此和上述功能是对称的,也是原先一直缺少的一环。

如果你感兴趣,可以仿照上面的入口,帮我们把这部分代码加上。或者我明天把这个加上也可以~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants