4

I'm using google's protocol-buffers for communication in my project, and I'm trying to use their command line tool protoc to manually decode some binary data (in hex format). This is the command I'm using:

echo 08015a325a300a0d313932 | xxd -r -p | protoc --decode=WiFiConfigPayload wifi_config.proto

I get the following error from this command, as well as any other type that I specify for "--decode":

Type not defined: WiFiConfigPayload

This is the main .proto file that I'm using (it was created by espressif, for use with their esp32 chip). There are other .proto files that this one imports, and can be found here if anyone thinks its relevant.

syntax = "proto3";
package espressif;

import "constants.proto";
import "wifi_constants.proto";

message CmdGetStatus {

}

message RespGetStatus {
    Status status = 1;
    WifiStationState sta_state = 2;
    oneof state {
        WifiConnectFailedReason fail_reason = 10;
        WifiConnectedState connected = 11;
    }
}

message CmdSetConfig {
    bytes ssid = 1;
    bytes passphrase = 2;
    bytes bssid = 3;
    int32 channel = 4;
}

message RespSetConfig {
    Status status = 1;
}

message CmdApplyConfig {

}

message RespApplyConfig {
    Status status = 1;
}

enum WiFiConfigMsgType {
    TypeCmdGetStatus = 0;
    TypeRespGetStatus = 1;
    TypeCmdSetConfig = 2;
    TypeRespSetConfig = 3;
    TypeCmdApplyConfig = 4;
    TypeRespApplyConfig = 5;
}

message WiFiConfigPayload {
    WiFiConfigMsgType msg = 1;
    oneof payload {
        CmdGetStatus cmd_get_status = 10;
        RespGetStatus resp_get_status = 11;
        CmdSetConfig cmd_set_config = 12;
        RespSetConfig resp_set_config = 13;
        CmdApplyConfig cmd_apply_config = 14;
        RespApplyConfig resp_apply_config = 15;
    }
}

Any ideas as to why the command is failing to parse WifiConfigPayload type (or any type for that matter) from the .protoc file?

JDune
  • 567
  • 7
  • 10

2 Answers2

11

I just ran in to this issue as well and I think you missed the actual bug. protoc was likely complaining because you didnt reference the message by the package.

protoc --decode=<PackageName>.MessageName

Where PackageName in your case is espressif

echo 08015a325a300a0d313932 | xxd -r -p | protoc --decode=espressif.WiFiConfigPayload wifi_config.proto
J_Catsong
  • 169
  • 1
  • 9
0

I solved the issue myself, soon after posting of course.

The problem is the line "package espressif;", which is included in all of their .proto files. XCode seems to require it for the project to build, but the protoc tool isn't expecting that line.

When I remove this line from this file, and all of its imported .proto files, the parsing is successful.

JDune
  • 567
  • 7
  • 10
  • This isn't really a solution though. The package line is important and if using protoc CLI as part of a testing script, the source files shouldn't be modified. – tvandinther Jan 24 '22 at 11:53