Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use external enums (outside message definitions) with protocol buffers?

I need to store enumns inside a PB message that are defined outside the PB message definitions. Is it possible at all & how?

like image 799
Rajat Gupta Avatar asked Dec 18 '11 16:12

Rajat Gupta


People also ask

How does Protobuf define enum?

enum is one of the composite datatypes of Protobuf. It translates to an enum in the languages that we use, for example, Java. Now our message class contains an Enum for payment. Each of them also has a position which is what Protobuf uses while serialization and deserialization.

What are protocol buffers used for?

Protocol Buffers (Protobuf) is a free and open-source cross-platform data format used to serialize structured data. It is useful in developing programs to communicate with each other over a network or for storing data.

Is Protobuf backwards compatible?

The proto-backwards-compatibility plugin is a Maven plugin to run a backwards compatibility check on a set of protobuf IDL files. The plugin can be integrated into various phases of a maven build to check that any changes to a set of . proto files are backwards compatible.

What is protocol buffer in gRPC?

Protocol Buffer, a.k.a. Protobuf Protobuf is the most commonly used IDL (Interface Definition Language) for gRPC. It's where you basically store your data and function contracts in the form of a proto file.


1 Answers

It's possible. Look at this thread for more info. I like the suggestion to define enums in a seperate .proto file. like

enums.proto

enum A
{ 
   FIRST = 1;
   SECOND = 2;
}

enum B { ... }

other.proto

import "enums.proto";

message SOMEMESSAGE
{
  required A myenum = 1;
}
like image 104
jbailey Avatar answered Oct 07 '22 20:10

jbailey