8000 readObject and readArray take a ref to the variant (6948, 8484) · enginux/ArduinoJson@8ac2404 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ac2404

Browse files
committed
readObject and readArray take a ref to the variant (6948, 8484)
1 parent 28cf31e commit 8ac2404

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

src/ArduinoJson/MsgPack/MsgPackDeserializer.hpp

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,11 @@ class MsgPackDeserializer {
6363
return skipBytes(code & 0x1f);
6464
}
6565

66-
if ((code & 0xf0) == 0x90) {
67-
if (filter.allowArray())
68-
return readArray(variant.toArray(), code & 0x0F, filter, nestingLimit);
69-
else
70-
return skipArray(code & 0x0F, filter, nestingLimit);
71-
}
66+
if ((code & 0xf0) == 0x90)
67+
return readArray(variant, code & 0x0F, filter, nestingLimit);
7268

73-
if ((code & 0xf0) == 0x80) {
74-
size_t size = code & 0x0F;
75-
if (filter.allowObject())
76-
return readObject(variant.toObject(), size, filter, nestingLimit);
77-
else
78-
return skipObject(size, filter, nestingLimit);
79-
}
69+
if ((code & 0xf0) == 0x80)
70+
return readObject(variant, code & 0x0F, filter, nestingLimit);
8071

8172
switch (code) {
8273
case 0xc0:
@@ -180,28 +171,16 @@ class MsgPackDeserializer {
180171
return skipString<uint32_t>();
181172

182173
case 0xdc:
183-
if (filter.allowArray())
184-
return readArray<uint16_t>(variant.toArray(), filter, nestingLimit);
185-
else
186-
return skipArray<uint16_t>(filter, nestingLimit);
174+
return readArray<uint16_t>(variant, filter, nestingLimit);
187175

188176
case 0xdd:
189-
if (filter.allowArray())
190-
return readArray<uint32_t>(variant.toArray(), filter, nestingLimit);
191-
else
192-
return skipArray<uint32_t>(filter, nestingLimit);
177+
return readArray<uint32_t>(variant, filter, nestingLimit);
193178

194179
case 0xde:
195-
if (filter.allowObject())
196-
return readObject<uint16_t>(variant.toObject(), filter, nestingLimit);
197-
else
198-
return skipObject<uint16_t>(filter, nestingLimit);
180+
return readObject<uint16_t>(variant, filter, nestingLimit);
199181

200182
case 0xdf:
201-
if (filter.allowObject())
202-
return readObject<uint32_t>(variant.toObject(), filter, nestingLimit);
203-
else
204-
return skipObject<uint32_t>(filter, nestingLimit);
183+
return readObject<uint32_t>(variant, filter, nestingLimit);
205184
}
206185

207186
if (!filter.allowValue()) {
@@ -380,12 +359,12 @@ class MsgPackDeserializer {
380359
}
381360

382361
template <typename TSize, typename TFilter>
383-
bool readArray(CollectionData &array, TFilter filter,
362+
bool readArray(VariantData &variant, TFilter filter,
384363
NestingLimit nestingLimit) {
385364
TSize size;
386365
if (!readInteger(size))
387366
return false;
388-
return readArray(array, size, filter, nestingLimit);
367+
return readArray(variant, size, filter, nestingLimit);
389368
}
390369

391370
template <typename TSize, typename TFilter>
@@ -397,13 +376,19 @@ class MsgPackDeserializer {
397376
}
398377

399378
template <typename TFilter>
400-
bool readArray(CollectionData &array, size_t n, TFilter filter,
379+
bool readArray(VariantData &variant, size_t n, TFilter filter,
401380
NestingLimit nestingLimit) {
402381
if (nestingLimit.reached()) {
403382
_error = DeserializationError::TooDeep;
404383
return false;
405384
}
406385

386+
if (!filter.allowArray()) {
387+
return skipArray(n, filter, nestingLimit);
388+
}
389+
390+
CollectionData &array = variant.toArray();
391+
407392
TFilter memberFilter = filter[0U];
408393

409394
for (; n; --n) {
@@ -437,12 +422,12 @@ class MsgPackDeserializer {
437422
}
438423

439424
template <typename TSize, typename TFilter>
440-
bool readObject(CollectionData &object, TFilter filter,
425+
bool readObject(VariantData &variant, TFilter filter,
441426
NestingLimit nestingLimit) {
442427
TSize size;
443428
if (!readInteger(size))
444429
return false;
445-
return readObject(object, size, filter, nestingLimit);
430+
return readObject(variant, size, filter, nestingLimit);
446431
}
447432

448433
template <typename TSize, typename TFilter>
@@ -454,13 +439,19 @@ class MsgPackDeserializer {
454439
}
455440

456441
template <typename TFilter>
457-
bool readObject(CollectionData &object, size_t n, TFilter filter,
442+
bool readObject(VariantData &variant, size_t n, TFilter filter,
458443
NestingLimit nestingLimit) {
459444
if (nestingLimit.reached()) {
460445
_error = DeserializationError::TooDeep;
461446
return false;
462447
}
463448

449+
if (!filter.allowObject()) {
450+
return skipObject(n, filter, nestingLimit);
451+
}
452+
453+
CollectionData &object = variant.toObject();
454+
464455
for (; n; --n) {
465456
if (!readKey())
466457
return false;

0 commit comments

Comments
 (0)
0