@@ -250,6 +250,7 @@ std::size_t decodeData(
250
250
std::shared_ptr<std::vector<Token>> tokens,
251
251
std::size_t tokenIndex,
252
252
const std::size_t numTokens,
253
+ std::uint64_t actingVersion,
253
254
TokenListener& listener)
254
255
{
255
256
while (tokenIndex < numTokens)
@@ -260,6 +261,8 @@ std::size_t decodeData(
260
261
break ;
261
262
}
262
263
264
+ const bool isPresent = token.tokenVersion () <= static_cast <std::int32_t >(actingVersion);
265
+
263
266
Token& lengthToken = tokens->at (tokenIndex + 2 );
264
267
Token& dataToken = tokens->at (tokenIndex + 3 );
265
268
@@ -269,9 +272,14 @@ std::size_t decodeData(
269
272
}
270
273
271
274
// TODO: is length always unsigned according to spec?
272
- std::uint64_t dataLength = lengthToken.encoding ().getAsUInt (buffer + bufferIndex + lengthToken.offset ());
275
+ std::uint64_t dataLength = isPresent ?
276
+ lengthToken.encoding ().getAsUInt (buffer + bufferIndex + lengthToken.offset ())
277
+ : 0 ;
273
278
274
- bufferIndex += dataToken.offset ();
279
+ if (isPresent)
280
+ {
281
+ bufferIndex += dataToken.offset ();
282
+ }
275
283
276
284
if ((bufferIndex + dataLength) > length)
277
285
{
@@ -306,6 +314,8 @@ std::pair<size_t, size_t> decodeGroups(
306
314
break ;
307
315
}
308
316
317
+ const bool isPresent = token.tokenVersion () <= static_cast <std::int32_t >(actingVersion);
318
+
309
319
Token& dimensionsTypeComposite = tokens->at (tokenIndex + 1 );
310
320
std::size_t dimensionsLength = static_cast <std::size_t >(dimensionsTypeComposite.encodedLength ());
311
321
@@ -317,10 +327,17 @@ std::pair<size_t, size_t> decodeGroups(
317
327
Token& blockLengthToken = tokens->at (tokenIndex + 2 );
318
328
Token& numInGroupToken = tokens->at (tokenIndex + 3 );
319
329
320
- std::uint64_t blockLength = blockLengthToken.encoding ().getAsUInt (buffer + bufferIndex + blockLengthToken.offset ());
321
- std::uint64_t numInGroup = numInGroupToken.encoding ().getAsUInt (buffer + bufferIndex + numInGroupToken.offset ());
330
+ std::uint64_t blockLength = isPresent ?
331
+ blockLengthToken.encoding ().getAsUInt (buffer + bufferIndex + blockLengthToken.offset ())
332
+ : 0 ;
333
+ std::uint64_t numInGroup = isPresent ?
334
+ numInGroupToken.encoding ().getAsUInt (buffer + bufferIndex + numInGroupToken.offset ())
335
+ : 0 ;
322
336
323
- bufferIndex += dimensionsLength;
337
+ if (isPresent)
338
+ {
339
+ bufferIndex += dimensionsLength;
340
+ }
324
341
325
342
size_t beginFieldsIndex = tokenIndex + dimensionsTypeComposite.componentTokenCount () + 1 ;
326
343
@@ -342,7 +359,8 @@ std::pair<size_t, size_t> decodeGroups(
342
359
std::pair<size_t , size_t > groupsResult =
343
360
decodeGroups (buffer, bufferIndex, length, actingVersion, tokens, afterFieldsIndex, numTokens, listener);
344
361
345
- bufferIndex = decodeData (buffer, groupsResult.first , length, tokens, groupsResult.second , numTokens, listener);
362
+ bufferIndex =
363
+ decodeData (buffer, groupsResult.first , length, tokens, groupsResult.second , numTokens, actingVersion, listener);
346
364
347
365
listener.onEndGroup (token, i, numInGroup);
348
366
}
@@ -381,7 +399,7 @@ std::size_t decode(
381
399
decodeGroups (buffer, bufferIndex, length, actingVersion, msgTokens, tokenIndex, numTokens, listener);
382
400
383
401
bufferIndex =
384
- decodeData (buffer, groupResult.first , length, msgTokens, groupResult.second , numTokens, listener);
402
+ decodeData (buffer, groupResult.first , length, msgTokens, groupResult.second , numTokens, actingVersion, listener);
385
403
386
404
listener.onEndMessage (msgTokens->at (numTokens - 1 ));
387
405
0 commit comments