public String codegen(Descriptors.Descriptor descriptor, Set<String> fieldsToRead) {
    // Generate the code for each message type in the fieldsToRead and the descriptor
    HashMap<String, MessageDecoderMethod> msgDecodeCode = generateMessageDeserializeCode(descriptor, fieldsToRead);
    return generateRecordExtractorCode(descriptor, fieldsToRead, msgDecodeCode);
  }
@Test
    public void testCodeGen()
        throws URISyntaxException, IOException {
        MessageCodeGen messageCodeGen = new MessageCodeGen();

        URL resource = getClass().getClassLoader().getResource("codegen_output/sample_record_extractor.txt");
        String expectedCodeOutput = new String(Files.readAllBytes(Paths.get(resource.toURI())));
        assertEquals(messageCodeGen.codegen(Sample.SampleRecord.getDescriptor(), new HashSet<>()),
            expectedCodeOutput);

        resource = getClass().getClassLoader().getResource("codegen_output/complex_types_record_extractor.txt");
        expectedCodeOutput = new String(Files.readAllBytes(Paths.get(resource.toURI())));
        assertEquals(messageCodeGen.codegen(ComplexTypes.TestMessage.getDescriptor(), new HashSet<>()),
            expectedCodeOutput);

        resource = getClass().getClassLoader().getResource("codegen_output/composite_types_record_extractor.txt");
        expectedCodeOutput = new String(Files.readAllBytes(Paths.get(resource.toURI())));
        assertEquals(messageCodeGen.codegen(CompositeTypes.CompositeMessage.getDescriptor(), new HashSet<>()),
            expectedCodeOutput);

        resource = getClass().getClassLoader()
            .getResource("codegen_output/complex_types_some_fields_record_extractor.txt");
        expectedCodeOutput = new String(Files.readAllBytes(Paths.get(resource.toURI())));
        assertEquals(messageCodeGen.codegen(ComplexTypes.TestMessage.getDescriptor(),
            Set.of(STRING_FIELD, COMPLEX_MAP, REPEATED_NESTED_MESSAGES, REPEATED_BYTES, NULLABLE_DOUBLE_FIELD)),
            expectedCodeOutput);

        resource = getClass().getClassLoader()
            .getResource("codegen_output/complex_types_some_fields_record_extractor.txt");
        expectedCodeOutput = new String(Files.readAllBytes(Paths.get(resource.toURI())));
        assertEquals(messageCodeGen.codegen(ComplexTypes.TestMessage.getDescriptor(),
                Set.of(STRING_FIELD, COMPLEX_MAP, REPEATED_NESTED_MESSAGES, REPEATED_BYTES, NULLABLE_DOUBLE_FIELD,
                    "does_not_exist_in_desc")),
            expectedCodeOutput);
    }