Convert to JSON from protobuf scheme and protobuf binary without generating the models?

41 views
Skip to first unread message

Nghia Tran

unread,
Mar 29, 2020, 12:19:11 PM3/29/20
to Protocol Buffers
Hi,

From what I understanding, given a Protobuf Scheme and the Protobuf Binary file, we can convert the binary to JSON by following:

1. Generate the models from the scheme by 
protoc --swift_out=. BookInfo_scheme.proto

2. Init models from the binary file
let decodedInfo = try BookInfo(serializedData: binaryData)) // swift

3. Serialize to JSON 
let jsonData: Data = try info.jsonUTF8Data() //swift

4. Convert Data to JSON String

Question: How can I achieve it without generating those Models? 

I did a research that Charles Proxy could do it by given protobuf binary and protobuf descriptor. Thus the solution is possible, but I couldn't find any documentation on how to implement it in C++ or Java or Swift.

Thanks in advance.

Nghia Tran

unread,
Apr 8, 2020, 8:44:11 AM4/8/20
to Protocol Buffers
Btw, I found the answer. We can use Reflection C++ to do it. Thanks all
Reply all
Reply to author
Forward
0 new messages