Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in a file format DSL #26

Open
flamewing opened this issue Nov 17, 2021 · 0 comments
Open

Add in a file format DSL #26

flamewing opened this issue Nov 17, 2021 · 0 comments

Comments

@flamewing
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant