【问题标题】:Use already compiled Protobuf-classes in new .proto-files在新的 .proto 文件中使用已编译的 Protobuf 类
【发布时间】:2011-10-29 12:56:52
【问题描述】:

我已经导入了一个包含 protobuf 生成的类的库。

我想将此类的对象作为其他 protobuf 消息的一部分发送。但是protoc(显然?)抱怨缺少定义:

无法解析对类型“ExistingProtobufLibraryClass”的引用。

我当然可以复制来自库源的现有 .proto 源,但是我怀疑 protoc 会生成此类的 两个 版本,这将很烦人。

有什么办法解决这个问题吗?

【问题讨论】:

  • 你玩过 protoc/.proto 中的各种“导入”选项吗?
  • 是的..我可以导入已经编译的类的 proto-def 并且它可以工作。如果我只能告诉 protoc not 为其生成代码就足够了。

标签: java protocol-buffers


【解决方案1】:

您需要导入现有的 proto 类。

import "somepath/existing_protobuf_library_class.proto"

protoc 不会生成额外的代码,生成的 Java 代码只会导入假定的其他类。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-23
    • 2019-12-13
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多