Skip to content
Discussion options

You must be logged in to vote

You're right, action syntax should only be used in edge cases when nothing else is applicable.

Adding a new byteorder without breaking previous versions is a bit tricky: I pushed a dev branch with a poc for an Inherit byteorder that uses the defined endian from the parent context.

For instance,

# Outer(BE) -> Middle(LE, explicit) -> Inner(Inherit)
# Inner will use Middle's LE
@struct(order=Inherit)
class Inner:
    v: uint32_t

@struct(order=LittleEndian)
class Middle:
    v: Inner

@struct(order=BigEndian)
class Outer:
    v: Middle

data = bytes.fromhex("11223344")
obj = unpack(Outer, data)
assert obj.v.v.v == 0x44332211
assert pack(obj) == data

The <endian> + <type> works too with this…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
7 replies
@MatrixEditor
Comment options

Answer selected by DenisD3D
@DenisD3D
Comment options

@MatrixEditor
Comment options

@MatrixEditor
Comment options

@DenisD3D
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants