简体   繁体   中英

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.

What formatting do I use? I know a lot of things I've been reading mention base64. But

I have a byte stream on the server side of the objects I want in C#. My client is an android device... 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; base64 would probably be the obvious encoding to use since JSON itself cannot handle arbitrary binary data.

On the other hand you don't necessarily have to use 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM