Define dictionary in protocol buffer

前端 未结 2 1044
再見小時候
再見小時候 2021-01-05 23:48

I\'m new to both protocol buffers and C++, so this may be a basic question, but I haven\'t had any luck finding answers. Basically, I want the functionality of a dictionary

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-06 00:27

    You could use custom options to associate a string with each enum member: https://developers.google.com/protocol-buffers/docs/proto#options

    It would look like this in the .proto:

    extend google.protobuf.FieldOptions {
      optional string name = 12345;
    }
    
    enum UnitType {
        KmPerHour = 1 [(name) = "km/h"];
        MiPerHour = 2 [(name) = "mph"];
    }
    

    Beware, though, that some third-party protobuf libraries don't understand these options.

提交回复
热议问题