@Override public String toString() { return "SimpleRecordField[fieldName=" + fieldName + ", type=" + fieldType.name() + "]"; } }
public ComplexRecordField(final String fieldName, final Repetition repetition, final List<RecordField> subFields) { Objects.requireNonNull(fieldName); Objects.requireNonNull(repetition); Objects.requireNonNull(subFields); if (subFields.isEmpty()) { throw new IllegalArgumentException("Cannot have a RecordField of type " + fieldType.name() + " without any sub-fields"); } this.fieldName = fieldName; this.repetition = repetition; this.subFields = subFields; }
private void writeField(final RecordField field, final DataOutputStream dos) throws IOException { dos.writeInt(4); // A field is made up of 4 "elements": Field Name, Field Type, Field Repetition, Sub-Fields. // For each of the elements, we write a String indicating the Element Name, a String indicating the Element Type, and // finally the Element data itself. dos.writeUTF(FIELD_NAME); dos.writeUTF(STRING_TYPE); dos.writeUTF(field.getFieldName()); dos.writeUTF(FIELD_TYPE); dos.writeUTF(STRING_TYPE); dos.writeUTF(field.getFieldType().name()); dos.writeUTF(REPETITION); dos.writeUTF(STRING_TYPE); dos.writeUTF(field.getRepetition().name()); dos.writeUTF(SUBFIELDS); dos.writeUTF(SUBFIELD_TYPE); final List<RecordField> subFields = field.getSubFields(); dos.writeInt(subFields.size()); // SubField is encoded as number of Sub-Fields followed by the fields themselves. for (final RecordField subField : subFields) { writeField(subField, dos); } }
if (FieldType.COMPLEX.name().equals(fieldTypeName)) { return new ComplexRecordField(fieldName, repetition, subFields); } else if (FieldType.UNION.name().equals(fieldTypeName)) { return new UnionRecordField(fieldName, repetition, subFields); } else if (FieldType.MAP.name().equals(fieldTypeName)) { if (subFields.size() != 2) { throw new IOException("Found a Map that did not have a 'Key' field and a 'Value' field but instead had " + subFields.size() + " fields: " + subFields);