Parse/Decode raw protobuf msg

126 views
Skip to first unread message

Rohan Suri

unread,
Apr 23, 2017, 6:24:56 AM4/23/17
to protostuff
Hello everyone,

I'm trying to find the right protostuff APIs to do what protoc --decode_raw and protoc --decode do.
Essentially handling two cases:
1) When I don't have the proto, and only the raw protobuf msg.
eg protoc --decode_raw < rawmsg.bin

1: "rohan"
2 {
    1: "13"
    2: "08"
    3: "94"
}

2) When I have the .proto(not the generated classes, neither the proto descriptor .desc)
eg protoc --decode some.pkg.name.Person $proto_file_path < rawmsg.bin

name: "rohan"
dob {
     dd: "13"
     mm: "08"
     yy: "94"
}

From a bit digging here and there the hints I've got is

For case 1) Using CodedInputStream write my own parser? parsing bytes by making informed guesses.
But this is just using the protobuff API, does protostuff simply this scenario?

For case 2) I found io.protostuff.parser.ProtoUtil which has the parseProto method, taking a File, which does parse all the messages I have in my .proto
Here after I tried looking for an API like,
parse(byte[], Proto, String) : Message
taking in a byte array and the parsed .proto and name of the message that the byte array is, returning a Message which all the fields, submessages etc filled.
However I couldn't find it.

Thanks.

Reply all
Reply to author
Forward
0 new messages