protobuf.js icon indicating copy to clipboard operation
protobuf.js copied to clipboard

Descriptor binaries does not match the binaries generated using `protoc`

Open NGuldager opened this issue 1 year ago • 0 comments

protobuf.js version: 7.3.0

I would expect that binaries generated with protobufjs to match the ones generated using protoc

Based on the following .proto file

syntax = "proto3";

package reporting.consumption;

service ConsumptionApi {
  rpc ListConsumption (ListConsumptionRequest) returns (ListConsumptionResponse) {}
}

enum IdentifierType {
    SOME_VALUE = 0;
    SOME_OTHER_VALUE = 1;
}

message Identifier {
    IdentifierType type = 1;
}

message ListConsumptionResponse {
  repeated Consumption consumption = 1;
}

message Consumption {
    float consumption = 1;
}

message ListConsumptionRequest {
    oneof consumption {
        Identifier identifier = 1;
    }
}

I get the following differences in the binaries:

From `protbufjs` From `protoc`
    1: "Identifier"
    2 {
      1: "type"
      3: 1
      4: 1
      5: 14
      6: "IdentifierType"
    }
  }
    1: "Identifier"
    2 {
      1: "type"
      3: 1
      4: 1
      5: 14
      6: ".reporting.consumption.IdentifierType"
      10: "type"
    }

We cannot easily get access to the .proto files where we need to generate client code, so having server side reflection from binaries generated by protobufjs is the ideal solution, except that it fails because protoc expects the binaries to look differently compared to what is returned by protobufjs

NGuldager avatar May 14 '24 07:05 NGuldager