This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients mark.dickinson, martin.panter, meador.inge, palaviv, rhettinger, serhiy.storchaka
Date 2017-03-25.21:32:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1490477545.48.0.763742890768.issue29903@psf.upfronthosting.co.za>
In-reply-to
Content
For the native alignment case (prefix code @), perhaps you can already use the “ctypes” module, which supports structures with more complicated embedded fields.

For the the unaligned modes (prefixes =, <, > and !), I am a little sympathetic. In the past, I wanted to make various structures that extended from a common base structure:

HSF_VOL_DESC = Struct("< B 5s B")

# Python 3's "Struct.format" is a byte string!
NSR_DESC = Struct(HSF_VOL_DESC.format.decode() + "B")

But I think if Issue 21071 was fixed (change Struct.format to text string, or perhaps add a new attribute), I would be happy enough writing

NSR_DESC = Struct(HSF_VOL_DESC.format_str + "B")

Transforming Aviv’s examples:

s3 = Struct(s1.format_str + s2.format_str[1:])
s3 = Struct(s1.format_str + "B")  # if s2 is not needed on its own
ver2 = Struct(ver1.format_str + "I")
version_a = Struct(start.format_str + union_b.format_str[1:])
History
Date User Action Args
2017-03-25 21:32:25martin.pantersetrecipients: + martin.panter, rhettinger, mark.dickinson, meador.inge, serhiy.storchaka, palaviv
2017-03-25 21:32:25martin.pantersetmessageid: <1490477545.48.0.763742890768.issue29903@psf.upfronthosting.co.za>
2017-03-25 21:32:25martin.panterlinkissue29903 messages
2017-03-25 21:32:25martin.pantercreate