Several years later, here is another answer.
# Check the version
protoc --version
>libprotoc 3.0.0
Raw Decoding
You can use the --decode_raw
option without a schema (.proto file).
Consider this simple example message containing the bytes 0x08 0x01
.
I am assuming a Linux environment with echo
# Use echo to print raw bytes and don't print an extra `\n` newline char at the end
echo -en '\x08\x01' | protoc --decode_raw
# Output below. This means field 1 integer type with a value of 1
1: 1
Decode With A Schema (.proto file)
If you have the proto file then you can get better results than --decode_raw
. You could even send the output from --decode
back into protoc if you wanted to encode it with new values.
Example.proto file contents
syntax = "proto3";
message Test {
int32 FieldOneNumber
}
# Decode the same message as the raw example against this schema
echo -en '\x08\x1' | protoc --decode="Test" --proto_path= ./Example.proto
# Output. Note that the generic field named 1 has been replaced by the proto file name of FieldOne.
FieldOne: 1