下面列出了怎么用com.google.protobuf.DescriptorProtos.EnumValueOptions的API类实例代码及写法,或者点击链接到github查看源代码。
private Builder(EnumSerialization enumSerialization, CaseFormat fromFieldNameFormat,
CaseFormat toFieldNameFormat) {
this.serializedNameExtensions = new HashSet<Extension<FieldOptions, String>>();
this.serializedEnumValueExtensions = new HashSet<Extension<EnumValueOptions, String>>();
setEnumSerialization(enumSerialization);
setFieldNameSerializationFormat(fromFieldNameFormat, toFieldNameFormat);
}
private ProtoTypeAdapter(EnumSerialization enumSerialization,
CaseFormat protoFormat,
CaseFormat jsonFormat,
Set<Extension<FieldOptions, String>> serializedNameExtensions,
Set<Extension<EnumValueOptions, String>> serializedEnumValueExtensions) {
this.enumSerialization = enumSerialization;
this.protoFormat = protoFormat;
this.jsonFormat = jsonFormat;
this.serializedNameExtensions = serializedNameExtensions;
this.serializedEnumValueExtensions = serializedEnumValueExtensions;
}
/**
* Retrieves the custom enum value name from the given options, and if not found, returns the
* specified default value.
*/
private String getCustSerializedEnumValue(EnumValueOptions options, String defaultValue) {
for (Extension<EnumValueOptions, String> extension : serializedEnumValueExtensions) {
if (options.hasExtension(extension)) {
return options.getExtension(extension);
}
}
return defaultValue;
}
private EnumValueOptions generateEnumValueOptions(EnumValue value) {
EnumValueOptions.Builder builder = EnumValueOptions.newBuilder();
setOptions(builder, value.getOptionsList(), ENUM_VALUE_OPTION_NAME_PREFIX);
return builder.build();
}
/**
* Get the {@code EnumValueOptions}, defined in {@code descriptor.proto}.
*/
public EnumValueOptions getOptions() { return proto.getOptions(); }
/**
* Adds an enum value proto annotation that, when set, overrides the default <b>enum</b> value
* serialization/deserialization of this adapter. For example, if you add the '
* {@code serialized_value}' annotation and you define an enum in your proto like the one below:
*
* <pre>
* enum MyEnum {
* UNKNOWN = 0;
* CLIENT_APP_ID = 1 [(serialized_value) = "APP_ID"];
* TWO = 2 [(serialized_value) = "2"];
* }
* </pre>
*
* ...the adapter will serialize the value {@code CLIENT_APP_ID} as "{@code APP_ID}" and the
* value {@code TWO} as "{@code 2}". This works for both serialization and deserialization.
* <p>
* Note that you need to set the enum serialization of this adapter to
* {@link EnumSerialization#NAME}, otherwise these annotations will be ignored.
*/
public Builder addSerializedEnumValueExtension(
Extension<EnumValueOptions, String> serializedEnumValueExtension) {
serializedEnumValueExtensions.add(checkNotNull(serializedEnumValueExtension));
return this;
}