Forcing BitStruct to be Little Endian

45 views
Skip to first unread message

kap

unread,
Nov 16, 2015, 10:51:10 PM11/16/15
to Construct
Below is example where I have a BitStruct embedded in a Struct:

bits = BitStruct(
    'bits',
    Flag('a'),
    Flag('b'),
    Enum(BitField('c', 2),
         A = 0b00,
         B = 0b01,
         C = 0b10,
         D = 0b11,
     ),
    BitField('d', 12),
)

packet = Struct(
    'packet',
    ULInt16('foo'),
    EmbeddedBitStruct(bits),
    ULInt16('bar'),
)

In the example above I'd like to make 'bits' an unsigned, little-endian, 16-bit integer, within the packet. Is there an easy way to cast it to a ULInt16 within 'packet'? Or do I have to reorder the 'bits' BitStruct by hand?

Thanks,
-kap

Arek Bulski

unread,
Sep 26, 2016, 10:39:29 AM9/26/16
to Construct
There are BitsSwapped and ByteSwapped wrappers added.
Reply all
Reply to author
Forward
0 new messages