public void generate() throws IOException
    {
        // Add the Marshalling from the big or little endian
        // template kept inside the jar.
        //
        // The MessageHeader structure along with its en/decoding is
        // also in the templated SbeMarshalling.go
        //
        // final Token token = ir.messages().iterator().next().get(0);
        if (ir.byteOrder() == ByteOrder.LITTLE_ENDIAN)
        {
            generateFileFromTemplate("SbeMarshalling", "SbeMarshallingLittleEndian");
        }
        else
        {
            generateFileFromTemplate("SbeMarshalling", "SbeMarshallingBigEndian");
        }

        generateMessageHeaderStub();
        generateTypeStubs();

        for (final List<Token> tokens : ir.messages())
        {
            final Token msgToken = tokens.get(0);
            final String typeName = formatTypeName(msgToken.name());

            try (Writer out = outputManager.createOutput(typeName))
            {
                final StringBuilder sb = new StringBuilder();

                imports.push(new TreeSet<>());
                imports.peek().add("io");

                generateTypeDeclaration(sb, typeName);
                generateTypeBody(sb, typeName, tokens.subList(1, tokens.size() - 1));

                generateMessageCode(sb, typeName, tokens);

                final List<Token> messageBody = tokens.subList(1, tokens.size() - 1);
                int i = 0;

                final List<Token> fields = new ArrayList<>();
                i = collectFields(messageBody, i, fields);

                final List<Token> groups = new ArrayList<>();
                i = collectGroups(messageBody, i, groups);

                final List<Token> varData = new ArrayList<>();
                collectVarData(messageBody, i, varData);

                generateFields(sb, typeName, fields);
                generateGroups(sb, groups, typeName);
                generateGroupProperties(sb, groups, typeName);
                generateVarData(sb, typeName, varData);

                out.append(generateFileHeader(ir.namespaces()));
                out.append(sb);
                imports.pop();
            }
        }
    }
@Test
    @SuppressWarnings("MethodLength")
    void shouldUseUpperCaseTypeNamesWhenReferencingBitSet() throws Exception
    {
        try (InputStream in = Tests.getLocalResource("message-with-lower-case-bitset.xml"))
        {
            final ParserOptions options = ParserOptions.builder().stopOnError(true).build();
            final MessageSchema schema = parse(in, options);
            final IrGenerator irg = new IrGenerator();
            final Ir ir = irg.generate(schema);
            final StringWriterOutputManager outputManager = new StringWriterOutputManager();
            outputManager.setPackageName(ir.applicableNamespace());

            final GolangGenerator generator = new GolangGenerator(ir, outputManager);
            generator.generate();

            final String eventTypeSource = outputManager.getSource("test973.EventType").toString();
            assertEquals("// Generated SBE (Simple Binary Encoding) message codec\n" +
                "\n" +
                "package test973\n" +
                "\n" +
                "import (\n" +
                "\t\"io\"\n" +
                ")\n" +
                "\n" +
                "type EventType [8]bool\n" +
                "type EventTypeChoiceValue uint8\n" +
                "type EventTypeChoiceValues struct {\n" +
                "\tA     EventTypeChoiceValue\n" +
                "\tBb    EventTypeChoiceValue\n" +
                "\tCcc   EventTypeChoiceValue\n" +
                "\tD     EventTypeChoiceValue\n" +
                "\tEeEee EventTypeChoiceValue\n" +
                "}\n" +
                "\n" +
                "var EventTypeChoice = EventTypeChoiceValues{0, 1, 2, 3, 4}\n" +
                "\n" +
                "func (e *EventType) Encode(_m *SbeGoMarshaller, _w io.Writer) error {\n" +
                "\tvar wireval uint8 = 0\n" +
                "\tfor k, v := range e {\n" +
                "\t\tif v {\n" +
                "\t\t\twireval |= (1 << uint(k))\n" +
                "\t\t}\n" +
                "\t}\n" +
                "\treturn _m.WriteUint8(_w, wireval)\n" +
                "}\n" +
                "\n" +
                "func (e *EventType) Decode(_m *SbeGoMarshaller, _r io.Reader, actingVersion uint16) error {\n" +
                "\tvar wireval uint8\n" +
                "\n" +
                "\tif err := _m.ReadUint8(_r, &wireval); err != nil {\n" +
                "\t\treturn err\n" +
                "\t}\n" +
                "\n" +
                "\tvar idx uint\n" +
                "\tfor idx = 0; idx < 8; idx++ {\n" +
                "\t\te[idx] = (wireval & (1 << idx)) > 0\n" +
                "\t}\n" +
                "\treturn nil\n" +
                "}\n" +
                "\n" +
                "func (EventType) EncodedLength() int64 {\n" +
                "\treturn 1\n" +
                "}\n" +
                "\n" +
                "func (*EventType) ASinceVersion() uint16 {\n" +
                "\treturn 0\n" +
                "}\n" +
                "\n" +
                "func (e *EventType) AInActingVersion(actingVersion uint16) bool {\n" +
                "\treturn actingVersion >= e.ASinceVersion()\n" +
                "}\n" +
                "\n" +
                "func (*EventType) ADeprecated() uint16 {\n" +
                "\treturn 0\n" +
                "}\n" +
                "\n" +
                "func (*EventType) BbSinceVersion() uint16 {\n" +
                "\treturn 0\n" +
                "}\n" +
                "\n" +
                "func (e *EventType) BbInActingVersion(actingVersion uint16) bool {\n" +
                "\treturn actingVersion >= e.BbSinceVersion()\n" +
                "}\n" +
                "\n" +
                "func (*EventType) BbDeprecated() uint16 {\n" +
                "\treturn 0\n" +
                "}\n" +
                "\n" +
                "func (*EventType) CccSinceVersion() uint16 {\n" +
                "\treturn 0\n" +
                "}\n" +
                "\n" +
                "func (e *EventType) CccInActingVersion(actingVersion uint16) bool {\n" +
                "\treturn actingVersion >= e.CccSinceVersion()\n" +
                "}\n" +
                "\n" +
                "func (*EventType) CccDeprecated() uint16 {\n" +
                "\treturn 0\n" +
                "}\n" +
                "\n" +
                "func (*EventType) DSinceVersion() uint16 {\n" +
                "\treturn 0\n" +
                "}\n" +
                "\n" +
                "func (e *EventType) DInActingVersion(actingVersion uint16) bool {\n" +
                "\treturn actingVersion >= e.DSinceVersion()\n" +
                "}\n" +
                "\n" +
                "func (*EventType) DDeprecated() uint16 {\n" +
                "\treturn 0\n" +
                "}\n" +
                "\n" +
                "func (*EventType) EeEeeSinceVersion() uint16 {\n" +
                "\treturn 0\n" +
                "}\n" +
                "\n" +
                "func (e *EventType) EeEeeInActingVersion(actingVersion uint16) bool {\n" +
                "\treturn actingVersion >= e.EeEeeSinceVersion()\n" +
                "}\n" +
                "\n" +
                "func (*EventType) EeEeeDeprecated() uint16 {\n" +
                "\treturn 0\n" +
                "}\n", eventTypeSource);

            final String messageSource = outputManager.getSource("test973.SomeMessage").toString();
            assertEquals("// Generated SBE (Simple Binary Encoding) message codec\n" +
                "\n" +
                "package test973\n" +
                "\n" +
                "import (\n" +
                "\t\"io\"\n" +
                "\t\"io/ioutil\"\n" +
                ")\n" +
                "\n" +
                "type SomeMessage struct {\n" +
                "\tMyEvent EventType\n" +
                "}\n" +
                "\n" +
                "func (s *SomeMessage) Encode(_m *SbeGoMarshaller, _w io.Writer, doRangeCheck bool) error {\n" +
                "\tif doRangeCheck {\n" +
                "\t\tif err := s.RangeCheck(s.SbeSchemaVersion(), s.SbeSchemaVersion()); err != nil {\n" +
                "\t\t\treturn err\n" +
                "\t\t}\n" +
                "\t}\n" +
                "\tif err := s.MyEvent.Encode(_m, _w); err != nil {\n" +
                "\t\treturn err\n" +
                "\t}\n" +
                "\treturn nil\n" +
                "}\n" +
                "\n" +
                "func (s *SomeMessage) Decode(_m *SbeGoMarshaller, _r io.Reader, actingVersion uint16, " +
                "blockLength uint16, doRangeCheck bool) error {\n" +
                "\tif s.MyEventInActingVersion(actingVersion) {\n" +
                "\t\tif err := s.MyEvent.Decode(_m, _r, actingVersion); err != nil {\n" +
                "\t\t\treturn err\n" +
                "\t\t}\n" +
                "\t}\n" +
                "\tif actingVersion > s.SbeSchemaVersion() && blockLength > s.SbeBlockLength() {\n" +
                "\t\tio.CopyN(ioutil.Discard, _r, int64(blockLength-s.SbeBlockLength()))\n" +
                "\t}\n" +
                "\tif doRangeCheck {\n" +
                "\t\tif err := s.RangeCheck(actingVersion, s.SbeSchemaVersion()); err != nil {\n" +
                "\t\t\treturn err\n" +
                "\t\t}\n" +
                "\t}\n" +
                "\treturn nil\n" +
                "}\n" +
                "\n" +
                "func (s *SomeMessage) RangeCheck(actingVersion uint16, schemaVersion uint16) error {\n" +
                "\treturn nil\n" +
                "}\n" +
                "\n" +
                "func SomeMessageInit(s *SomeMessage) {\n" +
                "\treturn\n" +
                "}\n" +
                "\n" +
                "func (*SomeMessage) SbeBlockLength() (blockLength uint16) {\n" +
                "\treturn 1\n" +
                "}\n" +
                "\n" +
                "func (*SomeMessage) SbeTemplateId() (templateId uint16) {\n" +
                "\treturn 1\n" +
                "}\n" +
                "\n" +
                "func (*SomeMessage) SbeSchemaId() (schemaId uint16) {\n" +
                "\treturn 973\n" +
                "}\n" +
                "\n" +
                "func (*SomeMessage) SbeSchemaVersion() (schemaVersion uint16) {\n" +
                "\treturn 0\n" +
                "}\n" +
                "\n" +
                "func (*SomeMessage) SbeSemanticType() (semanticType []byte) {\n" +
                "\treturn []byte(\"\")\n" +
                "}\n" +
                "\n" +
                "func (*SomeMessage) SbeSemanticVersion() (semanticVersion string) {\n" +
                "\treturn \"1.0\"\n" +
                "}\n" +
                "\n" +
                "func (*SomeMessage) MyEventId() uint16 {\n" +
                "\treturn 1\n" +
                "}\n" +
                "\n" +
                "func (*SomeMessage) MyEventSinceVersion() uint16 {\n" +
                "\treturn 0\n" +
                "}\n" +
                "\n" +
                "func (s *SomeMessage) MyEventInActingVersion(actingVersion uint16) bool {\n" +
                "\treturn actingVersion >= s.MyEventSinceVersion()\n" +
                "}\n" +
                "\n" +
                "func (*SomeMessage) MyEventDeprecated() uint16 {\n" +
                "\treturn 0\n" +
                "}\n" +
                "\n" +
                "func (*SomeMessage) MyEventMetaAttribute(meta int) string {\n" +
                "\tswitch meta {\n" +
                "\tcase 1:\n" +
                "\t\treturn \"\"\n" +
                "\tcase 2:\n" +
                "\t\treturn \"\"\n" +
                "\tcase 3:\n" +
                "\t\treturn \"\"\n" +
                "\tcase 4:\n" +
                "\t\treturn \"required\"\n" +
                "\t}\n" +
                "\treturn \"\"\n" +
                "}\n", messageSource);
        }
    }