Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decoding binary data using 'protoc --decode' fails with error "Type not defined"

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?

like image 496
JDune Avatar asked Oct 23 '25 15:10

JDune


1 Answers

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
like image 182
johnny_catsong Avatar answered Oct 26 '25 05:10

johnny_catsong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!