File: transition28.rst

package info (click to toggle)
construct 2.10.68%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 1,812 kB
  • sloc: python: 11,793; makefile: 135
file content (228 lines) | stat: -rw-r--r-- 4,444 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
=================
Transition to 2.8
=================

Overall
=======

All fields and complex constructs are now nameless, you need to use / operator to name them. Look at Struct Sequence Range for how to use + >> [] operators to construct larger instances.



Integers and floats
-------------------

{U,S}{L,B,N}Int{8,16,24,32,64} was made Int{8,16,24,32,64}{u,s}{l,b,n}

Byte, Short, Int, Long were made aliases to Int{8,16,32,64}ub

{B,L,N}Float{32,64} was made Float{32,64}{b,l,n}

Single, Double were made aliases to Float{32,64}b

VarInt was added

Bit, Nibble, Octet remain

All above were made singletons



Fields
------

Field was made Bytes (operates on b-strings)

BytesInteger was added (operates on integers)

BitField was made BitsInteger (operates on integers)

GreedyBytes was added

Flag was made a singleton

Enum takes the `default` keyword argument (no underscores)

Enum was fixed, the context value is a string label (not integer).

FlagsEnum remains



Strings
-------

String remains

PascalString argument `length_field=UBInt8` was made `lengthfield` and explicit

CString dropped `char_field`

GreedyString dropped `char_field`

All above use optional `encoding` argument or use global encoding (see ``setglobalstringencoding()``)



Structures and Sequences
------------------------

Struct uses syntax like ``Struct("num"/Int32ub, "text"/CString())`` and ``"num"/Int32ub + "text"/CString()``

Sequence uses syntax like ``Byte >> Int16ul`` and ``Sequence(Byte, Int16ul)``

On Python 3.6 you can also use syntax like ``Struct(num=Int32ub, text=CString())`` and ``Sequence(num=Int32ub, text=CString())``


Ranges and Arrays
-----------------

Array uses syntax like ``Byte[10]`` and ``Array(10, Byte)``

Range uses syntax like ``Byte[5:]`` and ``Byte[:5]`` and ``Range(min=5, max=2**64, Byte)``

GreedyRange uses syntax like ``Byte[:]`` and ``GreedyRange(Byte)``

PrefixedArray takes explicit `lengthfield` before subcon

OpenRange and GreedyRange were dropped

OptionalGreedyRange was renamed to GreedyRange

RepeatUntil takes 3-argument (last element, list, context) lambda



Lazy collections
----------------

LazyStruct LazyRange LazySequence were added

OnDemand returns a parameterless lambda that returns the parsed object

OnDemandPointer was dropped

LazyBound remains



Padding and Alignment
---------------------

Aligned takes explicit `modulus` before the subcon

Padded was added, also takes explicit `modulus` before the subcon

Padding remains

Padding and Padded dropped `strict` parameter



Optional
--------

If dropped `elsevalue` and always returns None

IfThenElse parameters renamed to `thensubcon` and `elsesubcon`

Switch remains

Optional remains

Union takes explicit `parsefrom` so parsing seeks stream by selected subcon size, or does not seek by default

Select remains



Miscellaneous and others
------------------------

Value was made Computed

Embed was made Embedded

Alias was removed

Magic was made Const

Const has reordered parameters, like ``Const(b"\\x00")`` and ``Const(0, Int8ub)``.

Pass remains

Terminator was renamed Terminated

OneOf and NoneOf remain

Filter added

LengthValueAdapter was made Prefixed, and gained `includelength` option

Hex added

HexDumpAdapter was made HexDump

HexDump builds from hexdumped data, not from raw bytes

SlicingAdapter and IndexingAdapter were made Slicing and Indexing

ExprAdapter ExprSymmetricAdapter ExprValidator were added or remain

SeqOfOne was replaced by FocusedSeq

Numpy added

NamedTuple added

Check added

Error added

Default added

Rebuild added

StopIf added



Stream manipulation
-------------------

Bitwise was reimplemented using Restreamed

Bytewise was added

Restreamed and Rebuffered were redesigned

Anchor was made Tell and a singleton

Seek was added

Pointer remains, size cannot be computed

Peek dropped `perform_build` parameter, never builds



Tunneling
---------

RawCopy was added, returns both parsed object and raw bytes consumed

Prefixed was added, allows to put greedy fields inside structs and sequences

ByteSwapped and BitsSwapped were added

Checksum was added

Compressed was added


Exceptions
-----------

FocusedError OverwriteError were removed

FieldError was replaced with StreamError (raised when stream returns less than requested amount) and FormatFieldError (raised by FormatField class, for example if building Float from non-float value and struct.pack complaining).