mdcomp icon indicating copy to clipboard operation
mdcomp copied to clipboard

Add in a file format DSL

Open flamewing opened this issue 2 years ago • 0 comments

Maybe it would be a good idea to have an embedded DSL for describing file formats, and have the internal code be mostly generated automatically. Something like (straw syntax):

auto ComperXFormat = LZSS::SingleStream()
        | 0_desc << LZSS::CopySymbol<uint16_t>
        | 1_desc << LZSS::HandleDictionary<uint8_t, uint8_t>(ComperProcessDictionaryParameters)
        ;
auto KosinskiFormat = LZSS::SingleStream()
        | 1_desc << LZSS::CopySymbol<uint8_t>
        | 00_desc << LZSS::HandleDictionary<LZSS::DescriptorBits<2>, uint8_t>(KosinskiProcessInlineDictionaryParameters)
        | 01_desc << LZSS::HandleDictionary<uint8_t, uint8_t>(KosinskiProcessDictionaryParameters)
        ;

The functions ComperProcessDictionaryParameters, KosinskiProcessInlineDictionaryParameters, and KosinskiProcessDictionaryParameters have prototypes of the form

void ComperProcessDictionaryParameters(LZSS::Context<ComperXAdaptor>& context, uint8_t byte1, uint8_t byte2);
void KosinskiProcessInlineDictionaryParameters(LZSS::Context<KosinskiAdaptor>& context, uint64_t packed_bits, uint8_t byte);
void KosinskiProcessDictionaryParameters(LZSS::Context<KosinskiAdaptor>& context, uint8_t byte1, uint8_t byte2);

The context variable can be used to read additional bytes, if needed, or process the parameters it receives, before doing the copy. It would be ideal to also have a LZSS::DictionaryCopy function that can handle the copy automatically, and which can be called by those. There is also a LZSS::Context::set_done function that signals the decoder that compression has ended.

I still need to think how to make this work for both compression or decompression.

flamewing avatar Nov 17 '21 18:11 flamewing