我需要在 Java 中发出以下命令:
//我想将以下内容存储在字符串中:
'\x00\x00\x00\x00\x15{“message”:”Hello”}’
我将执行的整个事情如下,但我首先需要将上面的字符串存储到 StringArray 或其他有效的东西中。这是 grpc 编码我需要使用 Envoy 代理 http-grpc 桥。
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 - 如何在 Java 字符串中存储 grpc 编码数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57154467/