@@ -259,32 +259,31 @@ function Field.COMPOSITE(fields)
259
259
-- a COMPOSITE before parsing. So if a field is OPTIONAL, return two
260
260
-- two lengths, the required and the optional (includes the
261
261
-- required).
262
- local requiredLength = 0
263
- local optionalLength = 0
264
- for _ , field in ipairs (fields ) do
265
- if not field .optional then
266
- requiredLength = requiredLength + field :len ()
262
+ local requiredLen = 0
263
+ local optionalLen = 0
264
+ for _ , field in ipairs (self . fields ) do
265
+ if field .optional then
266
+ optionalLen = field :len ()
267
267
else
268
- optionalLength = requiredLength + field :len ()
268
+ requiredLen = requiredLen + field :len ()
269
269
end
270
270
end
271
- return requiredLength , optionalLength
271
+ return requiredLen , requiredLen + optionalLen
272
272
end ,
273
273
value = function (self , tvb , off )
274
274
wsdh :trace (' Getting value of field ' .. self .name )
275
275
-- Note that field_len is only the required fields. If there is an
276
276
-- OPTIONAL field at the end of the COMPOSITE, it cannot be handled
277
277
-- and the returned value will not include it.
278
278
local fieldLen , optionalLen = self :len ()
279
- if off + optionalLen <= tvb :len () then
279
+ if off + optionalLen <= tvb :len () then
280
280
fieldLen = optionalLen
281
281
end
282
-
283
282
return tvb (off , fieldLen ):string (), tvb (off , fieldLen )
284
283
end ,
285
284
getOffset = function (self , abbr1 )
286
285
local offset = 0 ;
287
- for _ , field in ipairs (fields ) do
286
+ for _ , field in ipairs (self . fields ) do
288
287
if field .abbr == abbr1 then
289
288
return offset
290
289
else
@@ -302,7 +301,7 @@ function Field.COMPOSITE(fields)
302
301
end
303
302
304
303
local addedBytes = 0
305
- for _ , field in ipairs (fields ) do
304
+ for _ , field in ipairs (self . fields ) do
306
305
local fieldLen = field :add_to (subTree , tvb , off + addedBytes )
307
306
if fieldLen == 0 and not field .optional then
308
307
return 0
0 commit comments