Repository navigation
Add compiled writes - #179
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #179 +/- ##
======================================
Coverage 0.00% 0.00%
======================================
Files 22 22
Lines 3294 3533 +239
======================================
- Misses 3294 3533 +239
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will improve performance by 55.98%1 warning
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
3c5b7d6 to
a1c811b
Compare
|
ah, write support is basically just writing the bytes of the structure to a file handle? |
a1c811b to
6ddc32c
Compare
It's the same, compiled writes only change how Basically, instead of running this slow loop in dissect.cstruct/dissect/cstruct/types/structure.py Lines 299 to 355 in e200c0b The compiler will now generate a In [2]: from dissect.cstruct import cstruct
In [3]: cs = cstruct("""
...: struct test {
...: uint8 a;
...: uint8 b;
...: };
...: """)
In [4]: cs.test(a=1, b=2).dumps()
Out[4]: b'\x01\x02'
In [5]: print(cs.test._write.__source__)
def _write(cls, stream, data, *, endian):
if cls is not _cls0: return _struct_write(cls, stream, data, endian=endian)
try:
buf = _pack0[endian](data.a, data.b)
except _struct_error:
buf = _pack0[endian](_or_default(data.a, _type0), _or_default(data.b, _type0))
stream.write(buf)
return 2We've been doing the same for |
Depends on #178.
Adds write support to the compiler. Also add a bunch more tests.