I am playing with google api for educational purpose to learn protobuf connection. But i am getting 400 Bad Request
when i sending post request. I hope so my protobuf message have problem and don't understand how to i write 0: 0
message in proto file. I am using PHP Protobuf
library to serialization data.
This is readable/decoded grpc post request data:
0: 0
0: 0
}
1: 0x80c2:0x3a2f
2: this is test
3: 5
7 {
9: nG86YfStD4Of9QPB_L_QDg:28441478
15: 20089
}
8 {
1 {
1: 5
}
}
9 {
1: 0
2: 1
}
11: 1
12: 1
14: 0
16 {
I created this proto messages by following above grpc request data:
syntax = "proto3";
enum firstZero {
COUNT = 0;
}
message submit {
string pid = 1;
string rtext = 2;
int32 str = 3;
.unknown_auto_data unknown = 7;
.unknown_auto_data_eight unknown_one = 8;
.unknown_auto_data_nine unknown_two = 9;
int32 unknown_int = 11;
int32 unknown_int_one = 12;
int32 unknown_int_two = 14;
string unknown_string = 16;
}
message unknown_auto_data {
string auto_data = 9;
int32 auto_int = 15;
}
message unknown_auto_data_eight {
.unknown_repeated_one unknown_re_one = 1;
}
message unknown_repeated_one {
int32 unknown_rep = 1;
}
message unknown_auto_data_nine {
int32 unknown_it = 1;
int32 unknown_itt = 2;
}
Is my proto messages are correct? or How will i write it?
Also my request model data in php:
class RequestModel {
public $jsonData = [
"pid" => "0x80c2:0x3a2f",
"rtext" => "Awesome, This is test.",
"str" => "5"
];
public function getData() {
return json_encode($this->jsonData);
}
}
Is there (online/software/method) any tools to decode grpc/protobuf request/response to readable data like above json like data?
\x01\x00\x00\x05\xc0\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\xcdVM\x88\x1be\x18\xced\xdb\xed:E\xba.......
To convert binary protobuf data to a readable form, use
protoc --decode_raw
. The output will not have any field names, as those are not part of the wire format. Here is an example from https://github.com/pawitp/protobuf-decoder, which also provides an online-service to do the same thing.If you have the .proto file for your data, use
protoc --decode
instead.Where addresses.proto looks like this:
You can also use
protoc
to encode from the textual representation to the binary variant: