标签: protoc

如何导入gRPC空和Google API注释原型

我正在尝试使用Google Cloud Endpoints制作基于gRPC的api,该api可以对传入的REST请求进行转码。我正在遵循他们的示例代码,但是我没有任何有关如何正确地导入和使用注解.proto或empty.proto进行编译的文档。

谢谢!

protocol-buffers google-cloud-endpoints google-cloud-platform grpc protoc

7
推荐指数
3
解决办法
9072
查看次数

如何在客户端使用Java读取gRPC中的元数据

我正在使用Java和Protoc 3.0编译器,我的proto文件在下面提到. https://github.com/openconfig/public/blob/master/release/models/rpc/openconfig-rpc-api.yang

syntax = "proto3";

package Telemetry;

// Interface exported by Agent
service OpenConfigTelemetry {
    // Request an inline subscription for data at the specified path.
    // The device should send telemetry data back on the same
    // connection as the subscription request.
    rpc telemetrySubscribe(SubscriptionRequest)                     returns (stream OpenConfigData) {}

    // Terminates and removes an exisiting telemetry subscription
    rpc cancelTelemetrySubscription(CancelSubscriptionRequest)      returns (CancelSubscriptionReply) {}

    // Get the list of current telemetry subscriptions from the
    // target. This command returns a list …
Run Code Online (Sandbox Code Playgroud)

java protocol-buffers grpc protoc grpc-java

7
推荐指数
2
解决办法
3171
查看次数

Mac OS 上的 Protobuf dart 生成找不到 protoc-gen-dart

我已经用自制软件安装了 protoc,并尝试用 proto 文件生成 dart 代码。当我尝试一个简单的案例时,protoc --dart_out=. test.proto 它给了我: protoc-gen-dart: program not found or is not executable --dart_out: protoc-gen-dart: Plugin failed with status code 1. 但是protoc-gen-dart在我的道路上......

我也尝试指定路径,protoc --dart_out=. --plugin=protoc-gen-dart=~/.pub-cache/bin/protoc-gen-dart ./test.proto但同样的错误......

任何人都知道我该如何解决这个问题?

编辑:

echo | ~/.pub-cache/bin/protoc-gen-dart
Unhandled exception:
InvalidProtocolBufferException: CodedBufferReader encountered a malformed varint.
#0      CodedBufferReader._readRawVarint32 (file:///Users/jaumard/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.5/lib/src/protobuf/coded_buffer_reader.dart:180:5)
#1      CodedBufferReader.readInt32 (file:///Users/jaumard/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.5/lib/src/protobuf/coded_buffer_reader.dart:109:22)
#2      CodedBufferReader.readBytes (file:///Users/jaumard/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.5/lib/src/protobuf/coded_buffer_reader.dart:126:18)
#3      CodedBufferReader.readString (file:///Users/jaumard/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.5/lib/src/protobuf/coded_buffer_reader.dart:132:39)
#4      _mergeFromCodedBufferReader (file:///Users/jaumard/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.5/lib/src/protobuf/coded_buffer.dart:158:47)
#5      GeneratedMessage.mergeFromBuffer (file:///Users/jaumard/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.5/lib/src/protobuf/generated_message.dart:159:5)
#6      new GeneratedMessage.fromBuffer (file:///Users/jaumard/.pub-cache/hosted/pub.dartlang.org/protobuf-0.10.5/lib/src/protobuf/generated_message.dart:31:5)
#7      new CodeGeneratorRequest.fromBuffer (package:protoc_plugin/src/plugin.pb.dart:88:15)
#8      CodeGenerator.generate.<anonymous closure> (file:///Users/jaumard/.pub-cache/hosted/pub.dartlang.org/protoc_plugin-0.10.5/lib/code_generator.dart:66:25)
#9      _RootZone.runUnary …
Run Code Online (Sandbox Code Playgroud)

protocol-buffers dart protoc

7
推荐指数
1
解决办法
3435
查看次数

协议缓冲区错误版本

我正在尝试安装Caffe库,但由于我的系统中安装了错误的protobuf版本,因此我遇到了编译问题.

In file included from .build_release/src/caffe/proto/caffe.pb.cc:5:0:
.build_release/src/caffe/proto/caffe.pb.h:17:2: error: #error This file was generated by an older version of protoc which is
 #error This file was generated by an older version of protoc which is
  ^
.build_release/src/caffe/proto/caffe.pb.h:18:2: error: #error incompatible with your Protocol Buffer headers. Please
 #error incompatible with your Protocol Buffer headers.  Please
  ^
.build_release/src/caffe/proto/caffe.pb.h:19:2: error: #error regenerate this file with a newer version of protoc.
 #error regenerate this file with a newer version of protoc.
Run Code Online (Sandbox Code Playgroud)

我在论坛中遵循了许多提议的方法,我认为在这篇文章中讨论了最类似的问题.

在caffe.pb.h中,控件是: …

c++ protocol-buffers protoc

6
推荐指数
1
解决办法
4927
查看次数

从 Maven 依赖项导入 .proto 文件?

这是我的 protoc jar 插件 -

<plugin>
            <groupId>com.github.os72</groupId>
            <artifactId>protoc-jar-maven-plugin</artifactId>
            <version>${protoc-maven-plugin.version}</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>

                    <configuration>
                        <protocVersion>${protobuf.version}</protocVersion>

                        <includeStdTypes>true</includeStdTypes>
                        <includeDirectories>
                            <include>src/main/resources</include>
                        </includeDirectories>
                        <inputDirectories>
                            <include>src/main/resources</include>
                        </inputDirectories>

                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

我想包含一些来自 nexus 上可用的 Maven 存储库的导入语句 - 其中包含一堆 proto 文件及其 java 编译版本。它是一个包含原始文件的 jar。

如何将这些 proto 文件(打包在 jar 中)包含在 protoc 路径中,以便可以将 proto 文件导入到我当前的工作目录中?

问题是,当我 mavenize 我的项目时,导入始终失败 - 找不到 .proto 文件。

我的 proto 命令用作协议的一部分,看起来像 - protoc-jar: 执行: [C:\protocjar3624070738032398618\bin\protoc.exe, -IC:\protocjar3624070738032398618\include, -IC:myproject\src\main\resources , --java_out=C:\myproject\target\ generated-sources, C:\myproject\somedummy.proto]

该命令无法访问我正在导入的 jar 的 com.custom.proto 包,并且我不确定要添加到上述配置中的 inputDirectories 设置中才能将此包包含在 protoc 命令中。

PS 我可以使用此设置 …

protocol-buffers protoc

6
推荐指数
1
解决办法
1655
查看次数

“ google / protobuf / struct.proto”是通过GRPC发送动态JSON的最佳方法吗?

我编写了一个简单的GRPC服务器和一个客户端来调用服务器(都在Go中)。请告诉我是否使用golang / protobuf / struct是使用GRPC发送动态JSON的最佳方法。在下面的示例中,我之前是将Details创建为map [string] interface {}并将其序列化。然后,我在protoMessage中将其作为字节发送,并在服务器端反序列化该消息。

这是最好/最有效的方法,还是我应该在原型文件中将Details定义为结构?

下面是User.proto文件

syntax = "proto3";
package messages;
import "google/protobuf/struct.proto";

service UserService {
    rpc SendJson (SendJsonRequest) returns (SendJsonResponse) {}
}

message SendJsonRequest {
    string UserID = 1;
    google.protobuf.Struct Details = 2;
}

message SendJsonResponse {
    string Response = 1;
}
Run Code Online (Sandbox Code Playgroud)

下面是client.go文件包的主要导入文件(“上下文”“标志” pb“ grpc-test / messages / pb”“ log”

    "google.golang.org/grpc"
)

func main() {
    var serverAddr = flag.String("server_addr", "localhost:5001", "The server address in the format of host:port")
    opts := []grpc.DialOption{grpc.WithInsecure()}
    conn, err := grpc.Dial(*serverAddr, …
Run Code Online (Sandbox Code Playgroud)

json go protocol-buffers grpc protoc

6
推荐指数
3
解决办法
4789
查看次数

如何用扩展名替换 cmake 文件名列表

我正在尝试使用 cmake 根据某些定义构建一个 C++ 库protobuf。我添加了一个自定义命令来将其编译proto为 C++,但输出部分存在一些问题。protoc我需要指定哪些是完成其工作后的预期输出文件。为此,我想在我的PROTO_SOURCE文件 glob中将proto扩展名替换为.pb.cc.pb.h

我基本上需要这样的东西但是对于cmake。

我正在手动构建此命令,因为我没有可用的 protobuf cmake 支持。

project(messages)

set(PROTO_PATH "${CMAKE_CURRENT_SOURCE_DIR}/proto_definitions")
file(GLOB PROTO_FILES "${PROTO_PATH}/*.proto")
#set(PROTO_SOURCES ???) # This needs to contain '*.pb.cc' and '*.pb.h'

add_custom_command(COMMAND protoc --cpp_out=${CMAKE_CURRENT_SOURCE_DIR}/compiled_proto ${PROTO_FILES}
               WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
               DEPENDS ${PROTO_FILES}
               OUTPUT ${PROTO_SOURCES})

add_library(${PROJECT_NAME} STATIC ${PROTO_SOURCES})
Run Code Online (Sandbox Code Playgroud)

cmake protocol-buffers protoc

6
推荐指数
1
解决办法
4629
查看次数

谷歌使用 protoc 解码托管协议缓冲区数据存储/firestore 导出

我想我真的很接近或者我不明白我在做什么......

我们在项目中使用 Firestore,我正在编写一个自定义脚本来导出所有数据。但可以选择通过 gcloud CLI 导出它。这很棒,但是返回的数据位于协议缓冲区和二进制文件中。

我通过 gcloud CLI 导出数据,如下所示

gcloud beta firestore export gs://[BUCKET_NAME]
Run Code Online (Sandbox Code Playgroud)

它采用您的默认项目并导出您提供的存储桶名称中的数据。桶内的结果是这样的:

- timestamp folder
  - timestamp.overall_export_metadata file
  - all_namespaces folder
    - all_kinds folder
      - all_namespaces_all_kinds.export_metadata file
      - output-0 file
      - output-1 file
      - ... > up until output-250 file
Run Code Online (Sandbox Code Playgroud)

我下载了https://github.com/googleapis/googleapis proto 文件并尝试使用以下命令解码输出

protoc --decode google.firestore.v1beta1.Document ./google/firestore/v1beta1/document.proto < output-0 (or any other number for that matter)

resulted in: 

Failed to parse input.
Run Code Online (Sandbox Code Playgroud)

有效的命令如下:

protoc --decode google.firestore.admin.v1beta1.ExportDocumentsMetadata ./google/firestore/admin/v1beta1/firestore_admin.proto < all_namespaces_all_kinds.export_metadata

resulted in:

start_time {
  nanos: 629329010 …
Run Code Online (Sandbox Code Playgroud)

protocol-buffers firebase google-cloud-platform protoc google-cloud-firestore

6
推荐指数
0
解决办法
1007
查看次数

有没有办法让生成的枚举在 Protobuf v3 中实现自定义接口?

我想让 Proto3 中生成的枚举实现一个自定义的预先存在的接口,如下所示:

public enum GeneratedProtoEnum
      implements CustomInterface, com.google.protobuf.ProtocolMessageEnum {

    // ...
}
Run Code Online (Sandbox Code Playgroud)

(默认情况下,枚举仅实现com.google.protobuf.ProtocolMessageEnum)。

对于消息,可以通过message_implements:插入点实现类似的功能。

但是enum-s没有这样的选择。

在 Protobuf 中是否有传统的方法来实现这一点?或者,可能是一种非常规的方式?

java protocol-buffers protoc protocol-buffers-3

5
推荐指数
0
解决办法
139
查看次数

如何让 protoc 编译带有依赖项的 proto?

我需要修复 grpc 服务,所以我想了解编译它们的逻辑。

在下面的示例中,我不明白为什么 protoc 不编译address.proto,因为它是由person.proto.

没有构建错误,所以我认为这不是导入/命名问题。不幸的是,只person_pb2.py生成了一个...

// file: address.proto

syntax="proto3";

message Address {
    string city = 1;
    string road = 3;
    int32 roadNumber = 4;
}
Run Code Online (Sandbox Code Playgroud)
// file: person.proto

syntax="proto3";

import "address.proto";

message Person {
  string name = 1;
  Address home = 3;
  Address work = 4;
}
Run Code Online (Sandbox Code Playgroud)

构建命令:

python -m grpc_tools.protoc --proto_path ../protos --python_out=. person.proto
Run Code Online (Sandbox Code Playgroud)

protocol-buffers protoc

5
推荐指数
1
解决办法
3377
查看次数