我对 protoc 的使用感到非常困惑,并且在互联网上找不到有关其使用的示例:-
protoc -IPATH=path_to_proto_file_directory path_to_proto_file --decode=MESSAGE_TYPE < ./request.protobuf
那么这里的 message_type 是什么,有人可以写一个完整的正确示例吗
我对 protoc 的使用感到非常困惑,并且在互联网上找不到有关其使用的示例:-
protoc -IPATH=path_to_proto_file_directory path_to_proto_file --decode=MESSAGE_TYPE < ./request.protobuf
那么这里的 message_type 是什么,有人可以写一个完整的正确示例吗
syntax = "proto3";
package response;
// protoc --gofast_out=. response.proto
message Response {
int64 UID
....
}
use protoc:
protoc --decode=response.Response response.proto < response.bin
protoc --decode=[package].[Message type] proto.file < protobuf.response
or use:
protoc --decode_raw < protobuf.response
without proto file.
几年后,这是另一个答案。
# Check the version
protoc --version
>libprotoc 3.0.0
您可以使用--decode_raw
没有架构(.proto 文件)的选项。考虑这个包含字节的简单示例消息0x08 0x01
。我假设一个带有 echo 的 Linux 环境
# 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
如果你有 proto 文件,那么你可以获得比--decode_raw
. --decode
如果您想使用新值对其进行编码,您甚至可以将输出从回发送到 protoc。
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