【问题标题】:get camel name out of protocol buffer field从协议缓冲区字段中获取骆驼名称
【发布时间】:2011-06-01 03:13:44
【问题描述】:

我有这样的协议缓冲区消息:

    message Person {

    optional string last_name = 1; 
    optional string first_name = 2;

    }

java生成的类是这样的:

 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 boolean 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_; }
  ............
}

当 java 对象生成时,它通过方法调用 getLastName() 和 getFirstName() 使用骆驼字段名称作为 lastName, firstName。有没有办法让骆驼字段名出来?我不想获取原始字段名称 name : last_name, first_name 并在每次我想做的时候再次将其转换为骆驼字段名称 我的 java 对象上的 getter 和 setter。

【问题讨论】:

  • 我不清楚你在问什么。您能否发布生成的 Java 对象的代码。

标签: java protocol-buffers


【解决方案1】:

复制来自 Kenton Varda 在protobuf list 上的答案(因此是 wiki,而不是我的答案):

不,驼峰式名称没有存储在任何地方。您将需要构建 它自己。如果性能是一个问题,只需将结果缓存在 地图。

【讨论】:

    猜你喜欢
    • 2017-02-12
    • 1970-01-01
    • 2014-03-01
    • 2011-05-10
    • 1970-01-01
    • 1970-01-01
    • 2011-09-18
    • 2014-09-13
    • 2021-12-19
    相关资源
    最近更新 更多