0

I'm trying to convert the proto file into binary for an HTTP request payload, however, I'm receiving an error from protoc compiler tool, returning type not defined. I was not able to find any documentation on the type definitions used alongside --encode=.

I've tried specifying different types in the --encode, but the information I was finding was irrelevant. Other things I've tried specifying the proto message from the .proto file ``` message DeviceAuthRequest { }

protoc --encode=projname.auth TEST.proto > TEST.bin
Type not defined: projname.auth 
protoc --encode=DeviceAuthRequest TEST.proto > TEST.bin

What the the actual types for the --encode and --decode? I have a source code and compiled code in C#. Looking for a way of crafting payload with modified data in the proto file.

Dmitriy
  • 97
  • 3
  • 15
  • I'm confused... You say you have the C#... Can't you just load (deaerialize) the data using the C# generated code, change the data *as objects*, and serialize it again? – Marc Gravell Oct 17 '19 at 21:52
  • Rather than modifying generated C# code, I'd prefer to use protoc files as I will need to make frequent changes to params across multiple .proto files. `protoc --encode=[package].[message] test.proto > test.bin` I was able to execute the protoc without message type errors however, upon execution, the protoc cli would just hang without generating binary file. – Dmitriy Oct 17 '19 at 22:10
  • but you're only trying to change the *data* right? you wouldn't need to *modify* the generated files *at all*; you'd just write about 3 lines that deserializes, mutates, and serializes; am I misundertanding the question? – Marc Gravell Oct 18 '19 at 12:37
  • That's correct, it's a matter of modifying the actual data, to ensure properly formatted payloads are sent to the API accordingly to the proto files. All I have access it to the API accepting protobuf messages and not the client-side application sending the messages, so I will be generating my own data and mutating it accordingly. – Dmitriy Oct 18 '19 at 18:14
  • I'm trying the following which still gives me parsing errors, not entirely sure what I've gotten wrong with a format. Receiving the following:input:1:12: Expected identifier, got: ""5eb94f9c-ee3e-476a-ada9-4a84cf72ff28"". Failed to parse input.` `protoc --encode packagetest.demo demo.proto < demo.txt > demo.bin` `DemoIds: {"5eb94f9c-ee3e-476a-ada9-4a84cf72ff28"} SentTimeUtc: "2019-10-18T17:15:00Z" ContextId: 123123123` proto demo file ```message demo { repeated UserGuid DemoIds = 1; google.protobufTimestamp SentTimeUtc = 2; int32 ContextId = 3}``` – Dmitriy Oct 19 '19 at 00:32

1 Answers1

0

I do not know which proto schema you are referring to, but the syntax should look like (an example for generating the carrier identifiers under Android with protoc version 3.6.1):

cat carrier_list.textpb | protoc --encode=carrierIdentification.CarrierList -I/home/osboxes/Documents/ carrierId.proto > test.pb

I do not see any input in your example. protoc reads the input from standard in so you have to pipe in some data, e.g. by using the cat command. I also do not see any includes. You have to pass the includes with -I where the proto files are searched. This is also missing in your examples. Use an absolute path here, if you face any problems.

The carrierId.proto file looks like

syntax = "proto2";

package carrierIdentification;

option java_package = "com.android.internal.telephony";
option java_outer_classname = "CarrierIdProto";

// A complete list of carriers
message CarrierList {
  // A collection of carriers. one entry for one carrier.
  repeated CarrierId carrier_id = 1;
  // Version number of current carrier list
  optional int32 version = 2;
};

So, when rerencing the proto file your have to use the .(dot).carrierIdentification.CarrierList.

k_o_
  • 5,143
  • 1
  • 34
  • 43