@@ -42,6 +42,11 @@ class ListField(_Field[List[_TL]]):
42
42
43
43
"""
44
44
45
+ @property
46
+ def length (self ) -> 'int' :
47
+ """Field size."""
48
+ return self ._length
49
+
45
50
@property
46
51
def optional (self ) -> 'bool' :
47
52
"""Field is optional."""
@@ -121,7 +126,7 @@ def unpack(self, buffer: 'bytes | IO[bytes]', packet: 'dict[str, Any]') -> 'byte
121
126
Unpacked field value.
122
127
123
128
"""
124
- length = self .length
129
+ length = self ._length
125
130
if isinstance (buffer , bytes ):
126
131
file = io .BytesIO (buffer ) # type: IO[bytes]
127
132
else :
@@ -134,7 +139,7 @@ def unpack(self, buffer: 'bytes | IO[bytes]', packet: 'dict[str, Any]') -> 'byte
134
139
is_schema = isinstance (self ._item_type , SchemaField )
135
140
136
141
temp = [] # type: list[_TL]
137
- while length :
142
+ while length > 0 :
138
143
field = self ._item_type (packet )
139
144
140
145
if is_schema :
@@ -195,6 +200,11 @@ def eool(self) -> 'int | StdlibEnum | AenumEnum':
195
200
"""EOOL option."""
196
201
return self ._eool
197
202
203
+ @property
204
+ def option_padding (self ) -> 'int' :
205
+ """Length option padding data."""
206
+ return self ._option_padding
207
+
198
208
def __init__ (self , length : 'int | Callable[[dict[str, Any]], int]' = lambda _ : - 1 ,
199
209
base_schema : 'Optional[Type[Schema]]' = None ,
200
210
type_name : 'str' = 'type' ,
@@ -204,6 +214,7 @@ def __init__(self, length: 'int | Callable[[dict[str, Any]], int]' = lambda _: -
204
214
super ().__init__ (length , None , callback )
205
215
self ._name = '<option>'
206
216
self ._eool = eool
217
+ self ._option_padding = 0
207
218
208
219
if base_schema is None :
209
220
raise FieldValueError ('Field <option> has no base schema.' )
@@ -229,12 +240,12 @@ def unpack(self, buffer: 'bytes | IO[bytes]', packet: 'dict[str, Any]') -> 'list
229
240
230
241
Important:
231
242
If the option list ended before the specified size limit,
232
- inject ``__option_padding__` ` as the remaining length to
243
+ set :attr:`self.option_padding <OptionField.option_padding> ` as the remaining length to
233
244
the ``packet`` argument such that the next fields can be
234
245
aware of such informations.
235
246
236
247
"""
237
- length = self .length
248
+ length = self ._length
238
249
if isinstance (buffer , bytes ):
239
250
file = io .BytesIO (buffer ) # type: IO[bytes]
240
251
else :
@@ -246,7 +257,7 @@ def unpack(self, buffer: 'bytes | IO[bytes]', packet: 'dict[str, Any]') -> 'list
246
257
new_packet [self .name ] = OrderedMultiDict ()
247
258
248
259
temp = [] # type: list[Schema]
249
- while length :
260
+ while length > 0 :
250
261
# unpack option type using base schema
251
262
meta = self ._base_schema .unpack (file , length , packet ) # type: ignore[call-arg,misc,var-annotated]
252
263
code = cast ('int' , meta [self ._type_name ])
@@ -265,6 +276,7 @@ def unpack(self, buffer: 'bytes | IO[bytes]', packet: 'dict[str, Any]') -> 'list
265
276
266
277
# check for EOOL
267
278
if code == self ._eool :
268
- packet ['__option_padding__' ] = length
269
279
break
280
+
281
+ self ._option_padding = length
270
282
return temp
0 commit comments