简体   繁体   English

我可以在JSON对象中以字符串类型发送协议缓冲区吗?

[英]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.

相关问题 如何发送json字符串以查看为json对象? - How can I send a json string to view as a json object? 如何通过POST或JSON发送多个String? 我可以通过另一个JSON对象发送JSON数组吗? - How can I send more than one String through a POST or JSON? Can I send a JSON array through another JSON object? 我可以将json解析为字符串或其他具体类型作为对象吗? - Can I parse json either into a string or another concrete type as object? 协议buffer3和json - Protocol buffer3 and json 我可以在json响应中发送java对象吗? - Can i send java object in a json response 如何从JSON类型的字符串创建对象的Dictionary Type - How can I create Dictionary Type of Object from JSON type of string 将Web API Blob读入一个字符串,我可以将它作为json对象的一部分发送到服务器,然后转回一个文件 - reading a web api blob into a string that I can send as part of a json object to the server and turn back into a file 如何将DOM对象作为JSON对象发送 - How can I send a DOM object as a JSON object 我如何使用angular将逗号分隔的字符串转换为json对象类型 - How can i convert a comma seperated string to json object type using angular 将JSON对象作为字符串而非数组发送 - Send JSON object as string not array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM