private static void walkSchemaLevel(
        final SchemaConsumer consumer,
        final List<Token> fields,
        final List<Token> groups,
        final List<Token> varData)
    {
        Generators.forEachField(fields, (token, ignored) -> consumer.onBlockField(token));

        for (int i = 0; i < groups.size(); i++)
        {
            final Token token = groups.get(i);
            if (token.signal() != Signal.BEGIN_GROUP)
            {
                throw new IllegalStateException("tokens must begin with BEGIN_GROUP: token=" + token);
            }

            ++i;
            final int groupHeaderTokenCount = groups.get(i).componentTokenCount();
            i += groupHeaderTokenCount;

            final ArrayList<Token> groupFields = new ArrayList<>();
            i = collectFields(groups, i, groupFields);
            final ArrayList<Token> groupGroups = new ArrayList<>();
            i = collectGroups(groups, i, groupGroups);
            final ArrayList<Token> groupVarData = new ArrayList<>();
            i = collectVarData(groups, i, groupVarData);

            consumer.onEnterRepeatingGroup(token, groupFields, groupGroups, groupVarData);
        }

        for (int i = 0; i < varData.size(); )
        {
            final Token token = varData.get(i);
            if (token.signal() != Signal.BEGIN_VAR_DATA)
            {
                throw new IllegalStateException("tokens must begin with BEGIN_VAR_DATA: token=" + token);
            }
            i += token.componentTokenCount();

            consumer.onVarData(token);
        }
    }
Encodes the state machine as a graphviz dot diagram.
@param sb the string builder to append to.
@param indent the indentation to use.
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/common/FieldPrecedenceModel.java