I have a protocol buffer message like this:
    message Person {
    optional string last_name = 1; 
    optional string first_name = 2;
    }
The java generated class looks like this:
 public static final class Person extends
      com.google.protobuf.GeneratedMessage {
    // Use Person.newBuilder() to construct.
    ...... constructor stuffs
    // optional string first_name = 1;
    public static final int FIRST_NAME_FIELD_NUMBER = 1;
    private boolean hasFirstName;
    private java.lang.String firstName_ = "";
    public boole开发者_运维知识库an hasFirstName() { return hasFirstName; }
    public java.lang.String getFirstName() { return firstName_; }
    // optional string last_name = 2;
    public static final int LAST_NAME_FIELD_NUMBER = 2;
    private boolean hasLastName;
    private java.lang.String lastName_ = "";
    public boolean hasLastName() { return hasLastName; }
    public java.lang.String getLastName() { return lastName_; }
  ............
}
When java object is generated it uses camel field name as lastName, firstName through method call getLastName() and getFirstName(). Is there a way to get the camel field name out? I don't want to get the original field name name : last_name, first_name and convert it again to camel field name every time that I want to do getter and setter on my java object.
Copying in an answer (hence wiki, as not my answer) from Kenton Varda on the protobuf list:
No, the camel-case name is not stored anywhere. You will need to construct it yourself. If performance is a concern, just cache the results in a Map.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论