[英]Can I send a Protocol Buffer in a JSON object as a String type?
I've been looking at this, and I want to wrap the binary data of a protocol buffers in a string with JSON. 我一直在研究,我想用JSON将协议缓冲区的二进制数据包装在字符串中。
What formatting do I use? 我使用什么格式? I know a lot of things I've been reading mention base64.
我知道我读过的很多东西都提到了base64。 But
但
I have a byte stream on the server side of the objects I want in C#. 我在C#中要对象的服务器端有字节流。 My client is an android device... Java.
我的客户端是android设备... Java。
Language specific doesn't matter to me though. 特定语言对我来说并不重要。
You should be able to wrap the serialized protocol buffer in JSON the same way you would with any other binary data; 您应该能够像使用任何其他二进制数据一样,将序列化的协议缓冲区包装在JSON中。 base64 would probably be the obvious encoding to use since JSON itself cannot handle arbitrary binary data.
由于JSON本身无法处理任意二进制数据,因此base64可能是显而易见的编码。
On the other hand you don't necessarily have to use JSON; 另一方面,您不一定必须使用JSON。 you could consider just passing the serialized protocol buffer over the wire directly.
您可以考虑将串行化协议缓冲区直接通过网络传递。 Another approach would be to use the RPC framework gRPC , which uses protocol buffers natively and would handle all the encoding and decoding for you.
另一种方法是使用RPC框架gRPC ,该框架本身使用协议缓冲区,并将为您处理所有编码和解码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.