jprotobuf icon indicating copy to clipboard operation
jprotobuf copied to clipboard

.proto 描述文件动态生成对象,支持嵌套格式吗?

Open chenlihong199128 opened this issue 7 years ago • 11 comments

我尝试了下用“增加由.proto 描述文件动态生成Protobuf操作对象的支持”生成新的java对象,发现简单的.proto文件可以,但是嵌套的.proto文件就会报错,是不支持嵌套格式吗?

chenlihong199128 avatar Nov 14 '17 13:11 chenlihong199128

支持嵌套的

jhunters avatar Dec 18 '17 05:12 jhunters

message Obj { message KeyValue { optional string key = 1; optional string value = 2; } repeated KeyValue http_key_value = 1; }

这种方式能支持吗?

huangdacheng avatar Jan 18 '18 02:01 huangdacheng

支持的

jhunters avatar Jan 18 '18 05:01 jhunters

但是我使用 Map<String, IDLProxyObject> objectMap = ProtobufIDLProxy.create(protoCotent);的 时候 是报错的哦。 Exception in thread "main" java.lang.RuntimeException: Message 'Http' depend on message 'KeyVal' is missed at com.baidu.bjf.remoting.protobuf.ProtobufIDLProxy.create(ProtobufIDLProxy.java:206) at com.baidu.bjf.remoting.protobuf.ProtobufIDLProxy.create(ProtobufIDLProxy.java:197) at com.baidu.bjf.remoting.protobuf.ProtobufIDLProxy.create(ProtobufIDLProxy.java:193)

huangdacheng avatar Jan 18 '18 06:01 huangdacheng

Message 'Http' depend on message 'KeyVal' is missed 他这个有提示的。你上面给的例子是能正常工作的。你帖一下你使用的 proto文件出来吧

jhunters avatar Jan 18 '18 06:01 jhunters

String protoCotent = "package so_rtrs_req_res; " + "option java_package = "com.rtrs.proto"; " + "option java_outer_classname = "ReqRes"; " + " " + "message Http " + "{ " + "message KeyVal " + "{ " + " optional string key = 1; " + " optional string val = 2; " + "} " + " " + " " + " optional string uri = 1; " + " optional uint32 type = 2; " + " repeated KeyVal param_addon = 3; " + " optional string name = 4; " + "} " + " " + " " ; Map<String, IDLProxyObject> objectMap = ProtobufIDLProxy.create(protoCotent);

huangdacheng avatar Jan 18 '18 08:01 huangdacheng

上面的代码用最新的版本1.10.7可以工作的。你使用版本是多少?

jhunters avatar Jan 19 '18 02:01 jhunters

我以为2.1.4是最新版本呢。我用的是2.1.4

huangdacheng avatar Jan 19 '18 02:01 huangdacheng

2.1.4版本的确有这个问题,2.x版本是针对protobuf 3.x的,后面会修复一下

jhunters avatar Jan 19 '18 03:01 jhunters

Ok. Thank you for your nicd share

huangdacheng avatar Jan 19 '18 03:01 huangdacheng

2.1.5已经修复该问题

jhunters avatar Jan 19 '18 05:01 jhunters