Pavel Boldin added the comment:
We have raw data packages from some tools. These packages contains bitfields,
arrays, simple data and so on.
We want to parse them into Python objects (structures) for analysis and
storage. I tried to use ctypes, but now I wrote myself implementation of raw
Pavel Boldin added the comment:
OK. So, it seems just like ctypes work, but don't for my needs.
Thing that bothers me anyway is the strange code, where size contains either
size (when bitsize==0) or bitsize in upper 16 bits and bitoffset in lower 16
Pavel Boldin added the comment:
Yes. Thanks. But here is another error:
import ctypes
class X(ctypes.Structure):
_pack_ = 1
_fields_ = [
('a', ctypes.c_ubyte, 4),
('b', ctypes.c_ubyte, 4),
('c', ctypes.c_ushort, 4),
New submission from Pavel Boldin :
ctypes seems to work incorrectly with _swappedbytes_ specified.
I.e. it misses some values from buffer:
class X(ctypes.Structure):
_swappedbytes_ = 1
_pack_ = 1
_fields_ = [
('a', ctypes.c_ubyte, 4),
('b'