gpt4 book ai didi

java - 从 Protocol Buffer 字段中获取 Camel 名称

转载 作者:搜寻专家 更新时间:2023-11-01 03:13:42 26 4
gpt4 key购买 nike

我有一个这样的 Protocol Buffer 消息:

    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() 使用 Camel 字段名称作为 lastName, firstName。有没有办法得到 Camel 字段名称?我不想获取原始字段名称 name : last_name, first_name 并在每次我想做的时候再次将其转换为 Camel 字段名称我的 java 对象上的 getter 和 setter。

最佳答案

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

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.

关于java - 从 Protocol Buffer 字段中获取 Camel 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4555611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com