Define dictionary in protocol buffer

前端 未结 2 1027
再見小時候
再見小時候 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:20

    In proto3, it's:

    extend google.protobuf.EnumValueOptions {
      string name = 12345;
    }
    
    enum UnitType {
      KM_PER_HOUR = 0 [(name) = "km/h"];
      MI_PER_HOUR = 1 [(name) = "mph"];
    }
    

    and to access it in Java:

    UnitType.KM_PER_HOUR.getValueDescriptor().getOptions().getExtension(MyOuterClass.name);
    

提交回复
热议问题