在protobuf中导入和使用不同的软件包文件? [英] Import and usage of different package files in protobuf?

查看:79
本文介绍了在protobuf中导入和使用不同的软件包文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我导入了另一个与包名称不同的原型.要使用来自其他软件包的消息,请使用软件包名称访问该消息.

I have imported an other proto which having different package name than mine. For usage of messages from other package, have accessed that message with package name.

例如:

other.proto

other.proto

package muthu.other;

message Other{
   required float val = 1;
}

myproto.proto

myproto.proto

package muthu.test;

import "other.proto";

message MyProto{
  required string str = 1;
  optional muthu.other.Other.val = 2;
}

是否有一种方法可以直接使用 muthu.other 包中的 val ,例如 optional val = 2; ,而不是使用 muthu.other.Other.val 吗?

Is there a way to use val of muthu.other package directly like optional val = 2; instead of using muthu.other.Other.val ?

找不到与此有关的任何帮助文档.帮帮我.

Couldn't find any help document regarding this. Help me out.

推荐答案

如果程序包名称相同,则可以从字段声明中省略程序包名称,否则没有其他方法.如果您可以通过指定"package muthu.other"将muthu.test包含在同一个程序包中,则允许使用该程序.

If the package name is same then you can omit the package name from the field declaration but otherwise there is no other way. if you can include muthu.test in the same package by specifying "package muthu.other" then it is allowed.

来自protobuf的Google文档:

From Google documentation of protobuf:

您可以在.proto文件中添加可选的包说明符,以防止协议消息类型之间的名称冲突.

You can add an optional package specifier to a .proto file to prevent name clashes between protocol message types.

package foo.bar;
message Open { ... }

然后,您可以在定义消息类型的字段时使用包说明符:

You can then use the package specifier when defining fields of your message type:

message Foo {
  ...
  required foo.bar.Open open = 1;
  ...
}

这篇关于在protobuf中导入和使用不同的软件包文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆