如何将 grpc 编码的数据存储在 Java 字符串中?
How to I store grpc encoded data in a Java String?
我需要在 Java 中发出以下命令:
// 我想将以下内容存储在一个字符串中:
'\x00\x00\x00\x00\x15{“message”:”Hello”}’
我将执行的整个过程如下所示,但我首先需要将上面的字符串存储到 StringArray 或任何有效的方法中。这是grpc编码我需要使用Envoy代理http-grpc bridge.
curl -i -X POST -H "Content-Type:application/grpc+json” http://10.20.1.10:31234/com.test.echo.EchoService/echo -d '\x00\x00\x00\x00\x15{“message”:”Hello”}’
我特别关心如何在字符串中强烈表示 -d 之后的最后一部分,以便我可以发送它。如何将其存储在 Java 中?
更新;我试过:
String content = "x00x00x00x00x15{“message”:”Hello”}";
和
String content = "//x00//x00//x00//x00//x15{“message”:”Hello”}";
但都返回 grpc 13 代码和
Jul 23, 2019 6:41:36 AM io.grpc.netty.shaded.io.grpc.netty.NettyServerStream$TransportState deframeFailed
WARNING: Exception processing message
io.grpc.StatusRuntimeException: INTERNAL: gRPC frame header malformed: reserved bits not zero
at io.grpc.Status.asRuntimeException(Status.java:524)
at io.grpc.internal.MessageDeframer.processHeader(MessageDeframer.java:377)
您似乎根据 the other question.
解决了这一步
顺便说一句,你可以使用 ByteBuffer
byte[] payload = ???;
int payloadSize = payload.length;
ByteBuffer buf = ByteBuffer.allocate(payloadSize + 5);
buf.put((byte) 0);
buf.putInt(payloadSize);
buf.but(payload);
我需要在 Java 中发出以下命令:
// 我想将以下内容存储在一个字符串中:
'\x00\x00\x00\x00\x15{“message”:”Hello”}’
我将执行的整个过程如下所示,但我首先需要将上面的字符串存储到 StringArray 或任何有效的方法中。这是grpc编码我需要使用Envoy代理http-grpc bridge.
curl -i -X POST -H "Content-Type:application/grpc+json” http://10.20.1.10:31234/com.test.echo.EchoService/echo -d '\x00\x00\x00\x00\x15{“message”:”Hello”}’
我特别关心如何在字符串中强烈表示 -d 之后的最后一部分,以便我可以发送它。如何将其存储在 Java 中?
更新;我试过:
String content = "x00x00x00x00x15{“message”:”Hello”}";
和
String content = "//x00//x00//x00//x00//x15{“message”:”Hello”}";
但都返回 grpc 13 代码和
Jul 23, 2019 6:41:36 AM io.grpc.netty.shaded.io.grpc.netty.NettyServerStream$TransportState deframeFailed
WARNING: Exception processing message
io.grpc.StatusRuntimeException: INTERNAL: gRPC frame header malformed: reserved bits not zero
at io.grpc.Status.asRuntimeException(Status.java:524)
at io.grpc.internal.MessageDeframer.processHeader(MessageDeframer.java:377)
您似乎根据 the other question.
解决了这一步顺便说一句,你可以使用 ByteBuffer
byte[] payload = ???;
int payloadSize = payload.length;
ByteBuffer buf = ByteBuffer.allocate(payloadSize + 5);
buf.put((byte) 0);
buf.putInt(payloadSize);
buf.but(payload);