下面列出了com.google.protobuf.Descriptors.FieldDescriptor#getIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressWarnings("unchecked")
MessageWriter(Descriptor descriptor, GroupType schema) {
List<FieldDescriptor> fields = descriptor.getFields();
fieldWriters = (FieldWriter[]) Array.newInstance(FieldWriter.class, fields.size());
for (FieldDescriptor fieldDescriptor: fields) {
String name = fieldDescriptor.getName();
Type type = schema.getType(name);
FieldWriter writer = createWriter(fieldDescriptor, type);
if(writeSpecsCompliant && fieldDescriptor.isRepeated() && !fieldDescriptor.isMapField()) {
writer = new ArrayWriter(writer);
}
else if (!writeSpecsCompliant && fieldDescriptor.isRepeated()) {
// the old schemas style used to write maps as repeated fields instead of wrapping them in a LIST
writer = new RepeatedWriter(writer);
}
writer.setFieldName(name);
writer.setIndex(schema.getFieldIndex(name));
fieldWriters[fieldDescriptor.getIndex()] = writer;
}
}
/** Get the FieldAccessor for a particular field. */
private FieldAccessor getField(final FieldDescriptor field) {
if (field.getContainingType() != descriptor) {
throw new IllegalArgumentException(
"FieldDescriptor does not match message type.");
} else if (field.isExtension()) {
// If this type had extensions, it would subclass ExtendableMessage,
// which overrides the reflection interface to handle extensions.
throw new IllegalArgumentException(
"This type does not have extensions.");
}
return fields[field.getIndex()];
}
/** Get the FieldAccessor for a particular field. */
private FieldAccessor getField(final FieldDescriptor field) {
if (field.getContainingType() != descriptor) {
throw new IllegalArgumentException(
"FieldDescriptor does not match message type.");
} else if (field.isExtension()) {
// If this type had extensions, it would subclass ExtendableMessage,
// which overrides the reflection interface to handle extensions.
throw new IllegalArgumentException(
"This type does not have extensions.");
}
return fields[field.getIndex()];
}
/** Get the FieldAccessor for a particular field. */
private FieldAccessor getField(final FieldDescriptor field) {
if (field.getContainingType() != descriptor) {
throw new IllegalArgumentException(
"FieldDescriptor does not match message type.");
} else if (field.isExtension()) {
// If this type had extensions, it would subclass ExtendableMessage,
// which overrides the reflection interface to handle extensions.
throw new IllegalArgumentException(
"This type does not have extensions.");
}
return fields[field.getIndex()];
}
/** validates mapping between protobuffer fields and parquet fields.*/
private void validatedMapping(Descriptor descriptor, GroupType parquetSchema) {
List<FieldDescriptor> allFields = descriptor.getFields();
for (FieldDescriptor fieldDescriptor: allFields) {
String fieldName = fieldDescriptor.getName();
int fieldIndex = fieldDescriptor.getIndex();
int parquetIndex = parquetSchema.getFieldIndex(fieldName);
if (fieldIndex != parquetIndex) {
String message = "FieldIndex mismatch name=" + fieldName + ": " + fieldIndex + " != " + parquetIndex;
throw new IncompatibleSchemaModificationException(message);
}
}
}
/** Get the FieldAccessor for a particular field. */
private FieldAccessor getField(final FieldDescriptor field) {
if (field.getContainingType() != descriptor) {
throw new IllegalArgumentException(
"FieldDescriptor does not match message type.");
} else if (field.isExtension()) {
// If this type had extensions, it would subclass ExtendableMessage,
// which overrides the reflection interface to handle extensions.
throw new IllegalArgumentException(
"This type does not have extensions.");
}
return fields[field.getIndex()];
}
/** Get the FieldAccessor for a particular field. */
private FieldAccessor getField(final FieldDescriptor field) {
if (field.getContainingType() != descriptor) {
throw new IllegalArgumentException(
"FieldDescriptor does not match message type.");
} else if (field.isExtension()) {
// If this type had extensions, it would subclass ExtendableMessage,
// which overrides the reflection interface to handle extensions.
throw new IllegalArgumentException(
"This type does not have extensions.");
}
return fields[field.getIndex()];
}