Search in sources :

Example 1 with Type

use of org.apache.kafka.common.protocol.types.Type in project kafka by apache.

the class Protocol method schemaToBnfHtml.

private static void schemaToBnfHtml(Schema schema, StringBuilder b, int indentSize) {
    final String indentStr = indentString(indentSize);
    final Map<String, Type> subTypes = new LinkedHashMap<>();
    // Top level fields
    for (Field field : schema.fields()) {
        if (field.type instanceof ArrayOf) {
            b.append("[");
            b.append(field.name);
            b.append("] ");
            Type innerType = ((ArrayOf) field.type).type();
            if (!subTypes.containsKey(field.name))
                subTypes.put(field.name, innerType);
        } else {
            b.append(field.name);
            b.append(" ");
            if (!subTypes.containsKey(field.name))
                subTypes.put(field.name, field.type);
        }
    }
    b.append("\n");
    // Sub Types/Schemas
    for (Map.Entry<String, Type> entry : subTypes.entrySet()) {
        if (entry.getValue() instanceof Schema) {
            // Complex Schema Type
            b.append(indentStr);
            b.append(entry.getKey());
            b.append(" => ");
            schemaToBnfHtml((Schema) entry.getValue(), b, indentSize + 2);
        } else {
            // Standard Field Type
            b.append(indentStr);
            b.append(entry.getKey());
            b.append(" => ");
            b.append(entry.getValue());
            b.append("\n");
        }
    }
}
Also used : Field(org.apache.kafka.common.protocol.types.Field) ArrayOf(org.apache.kafka.common.protocol.types.ArrayOf) Type(org.apache.kafka.common.protocol.types.Type) Schema(org.apache.kafka.common.protocol.types.Schema) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ArrayOf (org.apache.kafka.common.protocol.types.ArrayOf)1 Field (org.apache.kafka.common.protocol.types.Field)1 Schema (org.apache.kafka.common.protocol.types.Schema)1 Type (org.apache.kafka.common.protocol.types.Type)1