0

I have been working on a web application using React-Redux and gRPC. The server sends the frontend gRPC messages which the frontend receives with the enums in the form of integers. How can I turn these integer values to their corresponding string values?

I have tried the methods in the protoc generated _pb.js files (.toObject(), get<Enum>(), etc.)

message Example {
    ExampleType type = 2;
}

enum ExampleType {
    UNKNOWN_TYPE = 0;
    TEST_TYPE = 1;
    OTHER_TYPE = 2;
}

I expect the following shape of the message.toObject() JSON object:

{ type: string } 

However, I receive the following:

{ type: integer }
Salman Zafar
  • 3,844
  • 5
  • 20
  • 43

1 Answers1

2

I am afraid you cannot get a string value for that. web protobuf does that for a reason. If it allows string enum, there will be more code needed to specify those enum names, which is not good for code size.

Bo Yang
  • 36
  • 1