StructIO.jl
StructIO.jl copied to clipboard
Enable packing and unpacking structures with user-specified gaps between fields
Following the discussion in #34, I implemented the suggested syntax for packing to/unpacking from a binary buffer while skipping some parts of it. The usage may be illustrated by this fragment from runtests.jl:
@io struct RawData
A::UInt32
dummy_1::UInt8
dummy_2::UInt16
B::UInt16
dummy_3::UInt32
C::UInt128
dummy_4::UInt16
dummy_5::UInt64
D::UInt8
end align_packed
@io struct GappedStruct
A::UInt32
_::3
B::UInt16
_::4
C::UInt128
_::2
_::8
_D::UInt8
end align_packed
A,B,C,D = 1,2,3,4
gapped_struct = GappedStruct(A, B, C, D)
raw_data = RawData(A, 0xBE, 0xBEEF, B, 0xDEADBEEF, C, 0xBEEF, 0xDEADBEEFDEADBEEF, D);
unpacked_raw_data = RawData(A, 0, 0, B, 0, C, 0, 0, D);
buf = IOBuffer()
pack(buf, raw_data)
seekstart(buf)
@test unpack(buf, GappedStruct) == gapped_struct
buf = IOBuffer(zeros(UInt8, packed_sizeof(GappedStruct)), read=true, write=true)
pack(buf, gapped_struct)
seekstart(buf)
@test unpack(buf, GappedStruct) == gapped_struct
seekstart(buf)
@test unpack(buf, RawData) == unpacked_raw_data
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 95.75%. Comparing base (1b79251) to head (4d73132).
:warning: Report is 8 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #35 +/- ##
==========================================
+ Coverage 94.53% 95.75% +1.22%
==========================================
Files 1 1
Lines 128 165 +37
==========================================
+ Hits 121 158 +37
Misses 7 7
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.