小编Eri*_*son的帖子

如何从 FileDescriptor 生成 .proto 文件

我正在protobuf.Descriptors.FileDescriptor从 XML 文件生成一个来定义不同机器之间的接口。定义协议并将其FileDescriptor用于后期绑定调用非常方便。现在我也希望能够生成适当的.proto文件,但我只DebugString()在 C++ 实现链接中找到了该方法。

作为一种简单的解决方法,我当然可以.proto此处那样手动生成文件,但这会破坏使用该类的很多便利性FileDescriptor

问题:是否有.proto比手动生成文件更简单的方法?(我也不认为将 C++ 类包装为一个干净的解决方案)

protocol-buffers

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

Spring Boot Protobuf 找不到类 com.google.protobuf.UnknownFieldSet$Parser 的序列化器

我想将 spring boot 与 protobuf 一起使用。简而言之,我编写了具有以下结构的演示代码;

RestController->获取实体->Postgres DB Repo->实体到protobuf对象->返回protobuf对象

pom 原型依赖;

<dependency>
        <groupId>com.google.protobuf</groupId>
        <artifactId>protobuf-java</artifactId>
        <version>3.12.4</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.protobuf-java-format</groupId>
        <artifactId>protobuf-java-format</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>com.google.protobuf</groupId>
        <artifactId>protobuf-java-util</artifactId>
        <version>3.13.0</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

原型文件

syntax = "proto3";

package demo;

option java_package = "demo.model";
option java_outer_classname = "DemoProtos";

message DemoDto {
  int64 id = 1;
  string description = 2;    

}
Run Code Online (Sandbox Code Playgroud)

gen.sh 文件

#!/usr/bin/env bash
    
SRC_DIR=`pwd`
DST_DIR=`pwd`/../src/main/

echo source:            $SRC_DIR
echo destination root:  $DST_DIR


function gen(){
    D=$1
    echo $D
    OUT=$DST_DIR/$D
    mkdir -p $OUT
    sudo protoc -I=$SRC_DIR --${D}_out=$OUT $SRC_DIR/demo.proto
} …
Run Code Online (Sandbox Code Playgroud)

spring protocol-buffers spring-boot protobuf-java

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

连接错误io.netty.handler.codec.http2.Http2Exception:HTTP/2客户端前言字符串丢失或损坏.接收字节的十六进制转储:

使用Grpc双向流,当我尝试运行grpc时,低于错误

Connection Error
io.netty.handler.codec.http2.Http2Exception: HTTP/2 client preface string missing or corrupt. Hex dump for received bytes: at io.netty.handler.codec.http2.Http2Exception.connectionError(Http2Exception.java:82)
    at io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.readClientPrefaceString(Http2ConnectionHandler.java:322)
    at io.netty.handler.codec.http2.Http2ConnectionHandler$PrefaceDecoder.decode(Http2ConnectionHandler.java:263)
    at io.netty.handler.codec.http2.Http2ConnectionHandler.decode(Http2ConnectionHandler.java:445)
    at io.netty.handler.codec.ByteToMessageDecoder.decodeLast(ByteToMessageDecoder.java:382)
    at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:286)
    at io.netty.handler.codec.http2.Http2ConnectionHandler.channelInactive(Http2ConnectionHandler.java:421)
    at io.grpc.netty.NettyServerHandler.channelInactive(NettyServerHandler.java:227)
    at io.netty.channel.ChannelHandlerInvokerUtil.invokeChannelInactiveNow(ChannelHandlerInvokerUtil.java:56)
    at io.netty.channel.DefaultChannelHandlerInvoker.invokeChannelInactive(DefaultChannelHandlerInvoker.java:92)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:135)
    at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:928)
    at io.netty.channel.AbstractChannel$AbstractUnsafe$7.run(AbstractChannel.java:674)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:339)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:356)
    at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Run Code Online (Sandbox Code Playgroud)

可能是什么问题?

grpc grpc-java

4
推荐指数
2
解决办法
4460
查看次数

Maven 和 java:如何从测试目录中的 protobuf 文件生成代码?

我的问题与this问题非常相似,但是针对maven和java。

我正在测试 grpc,并想将一个简单的 helloworld.proto 放入 test/proto 文件夹中。

但是该文件不会生成 java 文件(与 /src/main/proto 中的 proto 文件不同)。

所以我的问题是如何在测试文件夹中生成 proto 代码?

java protocol-buffers maven grpc grpc-java

4
推荐指数
1
解决办法
1万
查看次数

设置 gRPC ServerInterceptors 的执行顺序

在 io.grpc.internal.AbstractServerImplBuilder 中,您可以将 ServerInterceptor 的实现添加到最终列表中

final List<ServerInterceptor> interceptors = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)

然后在构建器的默认服务器实现中 - io.grpc.internal.ServerImpl 它在 foreach 循环中调用它们

/** Never returns {@code null}. */
private <ReqT, RespT> ServerStreamListener startCall(ServerStream stream, String fullMethodName,
    ServerMethodDefinition<ReqT, RespT> methodDef, Metadata headers,
    Context.CancellableContext context, StatsTraceContext statsTraceCtx, Tag tag) {
  // TODO(ejona86): should we update fullMethodName to have the canonical path of the method?
  statsTraceCtx.serverCallStarted(
      new ServerCallInfoImpl<>(
          methodDef.getMethodDescriptor(), // notify with original method descriptor
          stream.getAttributes(),
          stream.getAuthority()));
  ServerCallHandler<ReqT, RespT> handler = methodDef.getServerCallHandler();
  for (ServerInterceptor interceptor : interceptors) { …
Run Code Online (Sandbox Code Playgroud)

java spring grpc grpc-java

3
推荐指数
1
解决办法
2569
查看次数