ProtobufUtils { public static StructType buildSchema(Descriptors.Descriptor descriptor) { List<StructField> members = new ArrayList<>(); List<Descriptors.FieldDescriptor> protoFields = descriptor.getFields(); for (Descriptors.FieldDescriptor fieldDescriptor : protoFields) { DataType fieldType = convertType(fieldDescriptor); StructField structField = DataTypes.createStructField(fieldDescriptor.getName(), fieldType, !fieldDescriptor.isRequired()); members.add(structField); LOG.debug("FieldDescriptor[{}] => StructField[{}] ", fieldDescriptor.getFullName(), structField); } if (members.isEmpty()) { throw new RuntimeException("No FieldDescriptors found"); } return DataTypes.createStructType(members.toArray(new StructField[0])); }  static List<Object> buildRowValues(Descriptors.Descriptor dsc, Message msg, StructType schema); static StructType buildSchema(Descriptors.Descriptor descriptor); static Descriptors.Descriptor buildDescriptor(String filePath, String messageName); static Descriptors.Descriptor buildDescriptor(String filePath); static boolean isGzipped(InputStream inputStream);  }
@Test public void buildSchemaSingle() { Descriptors.Descriptor descriptor = ProtobufSingleMessage.SingleExample.getDescriptor(); Assert.assertThat(ProtobufUtils.buildSchema(descriptor), is(SINGLE_SCHEMA)); }