bitstruct icon indicating copy to clipboard operation
bitstruct copied to clipboard

Interface of the C implementation

Open avalentino opened this issue 4 years ago • 3 comments

In order to have a drop-in replacement of the pure Python implementation please consider to expose the CompiledFormat and CompiledFormatDict classes also in the C implementation.

Also please note that the C implementation seems to be not mentioned in the HTML documentation (e.g. https://bitstruct.readthedocs.io). It would be nice to have a short note abut the C implementation also in the HTML documentation (analogously to what done on the README.rst).

avalentino avatar Jun 26 '21 09:06 avalentino

Why do you need them? I mean, they are normally instantiated by the compile() function, and are not really meant to be instantiated directly by the user.

The documentation has been updated.

The raised exceptions are different in the C and Python implementation as well. Feel free to make them use the same exceptions in a PR.

eerimoq avatar Jun 26 '21 09:06 eerimoq

In my case I have a simple class

class BitStruct(bitstruct.CompiledFormat):
    def __init__(self, format: str):
        super().__init__(format)
        self._format: str = format

    @property
    def format(self) -> str:
        return self._format

that is used to mimic the behaviour of the struct package form the stdlib.

avalentino avatar Jun 26 '21 09:06 avalentino

Ok, feel free to submit a PR that exposes those classes. Possibly add a format property/attribute as well to them.

eerimoq avatar Jun 26 '21 10:06 eerimoq