filter.cpp 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2024, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. #include <sstream>
  7. #include "Allocators.hpp"
  8. using namespace ArduinoJson::detail;
  9. TEST_CASE("deserializeMsgPack() filter") {
  10. SpyingAllocator spy;
  11. JsonDocument doc(&spy);
  12. DeserializationError error;
  13. JsonDocument filter;
  14. DeserializationOption::Filter filterOpt(filter);
  15. SECTION("root is fixmap") {
  16. SECTION("filter = {include:true,ignore:false)") {
  17. filter["include"] = true;
  18. filter["ignore"] = false;
  19. SECTION("input truncated after ignored key") {
  20. error = deserializeMsgPack(doc, "\x82\xA6ignore", 8, filterOpt);
  21. CHECK(error == DeserializationError::IncompleteInput);
  22. CHECK(doc.as<std::string>() == "{}");
  23. CHECK(spy.log() == AllocatorLog{
  24. Allocate(sizeofStringBuffer()),
  25. Deallocate(sizeofStringBuffer()),
  26. });
  27. }
  28. SECTION("input truncated after inside skipped uint 8") {
  29. error = deserializeMsgPack(doc, "\x82\xA6ignore\xCC\x2A\xA7include\x2A",
  30. 9, filterOpt);
  31. CHECK(error == DeserializationError::IncompleteInput);
  32. CHECK(doc.as<std::string>() == "{}");
  33. CHECK(spy.log() == AllocatorLog{
  34. Allocate(sizeofStringBuffer()),
  35. Deallocate(sizeofStringBuffer()),
  36. });
  37. }
  38. SECTION("input truncated after before skipped string size") {
  39. error = deserializeMsgPack(doc, "\x82\xA6ignore\xd9", 9, filterOpt);
  40. CHECK(error == DeserializationError::IncompleteInput);
  41. CHECK(doc.as<std::string>() == "{}");
  42. CHECK(spy.log() == AllocatorLog{
  43. Allocate(sizeofStringBuffer()),
  44. Deallocate(sizeofStringBuffer()),
  45. });
  46. }
  47. SECTION("input truncated after before skipped ext size") {
  48. error = deserializeMsgPack(doc, "\x82\xA6ignore\xC7", 9, filterOpt);
  49. CHECK(error == DeserializationError::IncompleteInput);
  50. CHECK(doc.as<std::string>() == "{}");
  51. CHECK(spy.log() == AllocatorLog{
  52. Allocate(sizeofStringBuffer()),
  53. Deallocate(sizeofStringBuffer()),
  54. });
  55. }
  56. SECTION("skip nil") {
  57. error = deserializeMsgPack(doc, "\x82\xA6ignore\xC0\xA7include\x2A",
  58. filterOpt);
  59. CHECK(error == DeserializationError::Ok);
  60. CHECK(doc.as<std::string>() == "{\"include\":42}");
  61. CHECK(spy.log() ==
  62. AllocatorLog{
  63. Allocate(sizeofStringBuffer()),
  64. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  65. Allocate(sizeofPool()),
  66. Reallocate(sizeofPool(), sizeofObject(1)),
  67. });
  68. }
  69. SECTION("reject 0xc1") {
  70. error = deserializeMsgPack(doc, "\x82\xA6ignore\xC1\xA7include\x2A",
  71. filterOpt);
  72. CHECK(error == DeserializationError::InvalidInput);
  73. CHECK(spy.log() == AllocatorLog{
  74. Allocate(sizeofStringBuffer()),
  75. Deallocate(sizeofStringBuffer()),
  76. });
  77. }
  78. SECTION("skip false") {
  79. error = deserializeMsgPack(doc, "\x82\xA6ignore\xC2\xA7include\x2A",
  80. filterOpt);
  81. CHECK(error == DeserializationError::Ok);
  82. CHECK(doc.as<std::string>() == "{\"include\":42}");
  83. CHECK(spy.log() ==
  84. AllocatorLog{
  85. Allocate(sizeofStringBuffer()),
  86. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  87. Allocate(sizeofPool()),
  88. Reallocate(sizeofPool(), sizeofObject(1)),
  89. });
  90. }
  91. SECTION("skip true") {
  92. error = deserializeMsgPack(doc, "\x82\xA6ignore\xC3\xA7include\x2A",
  93. filterOpt);
  94. CHECK(error == DeserializationError::Ok);
  95. CHECK(doc.as<std::string>() == "{\"include\":42}");
  96. CHECK(spy.log() ==
  97. AllocatorLog{
  98. Allocate(sizeofStringBuffer()),
  99. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  100. Allocate(sizeofPool()),
  101. Reallocate(sizeofPool(), sizeofObject(1)),
  102. });
  103. }
  104. SECTION("skip positive fixint") {
  105. error = deserializeMsgPack(doc, "\x82\xA6ignore\x2A\xA7include\x2A",
  106. filterOpt);
  107. CHECK(error == DeserializationError::Ok);
  108. CHECK(doc.as<std::string>() == "{\"include\":42}");
  109. CHECK(spy.log() ==
  110. AllocatorLog{
  111. Allocate(sizeofStringBuffer()),
  112. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  113. Allocate(sizeofPool()),
  114. Reallocate(sizeofPool(), sizeofObject(1)),
  115. });
  116. }
  117. SECTION("skip negative fixint") {
  118. error = deserializeMsgPack(doc, "\x82\xA6ignore\xFF\xA7include\x2A",
  119. filterOpt);
  120. CHECK(error == DeserializationError::Ok);
  121. CHECK(doc.as<std::string>() == "{\"include\":42}");
  122. CHECK(spy.log() ==
  123. AllocatorLog{
  124. Allocate(sizeofStringBuffer()),
  125. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  126. Allocate(sizeofPool()),
  127. Reallocate(sizeofPool(), sizeofObject(1)),
  128. });
  129. }
  130. SECTION("skip uint 8") {
  131. error = deserializeMsgPack(doc, "\x82\xA6ignore\xCC\x2A\xA7include\x2A",
  132. filterOpt);
  133. CHECK(error == DeserializationError::Ok);
  134. CHECK(doc.as<std::string>() == "{\"include\":42}");
  135. CHECK(spy.log() ==
  136. AllocatorLog{
  137. Allocate(sizeofStringBuffer()),
  138. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  139. Allocate(sizeofPool()),
  140. Reallocate(sizeofPool(), sizeofObject(1)),
  141. });
  142. }
  143. SECTION("skip int 8") {
  144. error = deserializeMsgPack(doc, "\x82\xA6ignore\xD0\x2A\xA7include\x2A",
  145. filterOpt);
  146. CHECK(error == DeserializationError::Ok);
  147. CHECK(doc.as<std::string>() == "{\"include\":42}");
  148. CHECK(spy.log() ==
  149. AllocatorLog{
  150. Allocate(sizeofStringBuffer()),
  151. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  152. Allocate(sizeofPool()),
  153. Reallocate(sizeofPool(), sizeofObject(1)),
  154. });
  155. }
  156. SECTION("skip uint 16") {
  157. error = deserializeMsgPack(
  158. doc, "\x82\xA6ignore\xcd\x30\x39\xA7include\x2A", filterOpt);
  159. CHECK(error == DeserializationError::Ok);
  160. CHECK(doc.as<std::string>() == "{\"include\":42}");
  161. CHECK(spy.log() ==
  162. AllocatorLog{
  163. Allocate(sizeofStringBuffer()),
  164. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  165. Allocate(sizeofPool()),
  166. Reallocate(sizeofPool(), sizeofObject(1)),
  167. });
  168. }
  169. SECTION("skip int 16") {
  170. error = deserializeMsgPack(
  171. doc, "\x82\xA6ignore\xD1\xCF\xC7\xA7include\x2A", filterOpt);
  172. CHECK(error == DeserializationError::Ok);
  173. CHECK(doc.as<std::string>() == "{\"include\":42}");
  174. CHECK(spy.log() ==
  175. AllocatorLog{
  176. Allocate(sizeofStringBuffer()),
  177. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  178. Allocate(sizeofPool()),
  179. Reallocate(sizeofPool(), sizeofObject(1)),
  180. });
  181. }
  182. SECTION("skip uint 32") {
  183. error = deserializeMsgPack(
  184. doc, "\x82\xA6ignore\xCE\x12\x34\x56\x78\xA7include\x2A",
  185. filterOpt);
  186. CHECK(error == DeserializationError::Ok);
  187. CHECK(doc.as<std::string>() == "{\"include\":42}");
  188. CHECK(spy.log() ==
  189. AllocatorLog{
  190. Allocate(sizeofStringBuffer()),
  191. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  192. Allocate(sizeofPool()),
  193. Reallocate(sizeofPool(), sizeofObject(1)),
  194. });
  195. }
  196. SECTION("skip int 32") {
  197. error = deserializeMsgPack(
  198. doc, "\x82\xA6ignore\xD2\xB6\x69\xFD\x2E\xA7include\x2A",
  199. filterOpt);
  200. CHECK(error == DeserializationError::Ok);
  201. CHECK(doc.as<std::string>() == "{\"include\":42}");
  202. CHECK(spy.log() ==
  203. AllocatorLog{
  204. Allocate(sizeofStringBuffer()),
  205. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  206. Allocate(sizeofPool()),
  207. Reallocate(sizeofPool(), sizeofObject(1)),
  208. });
  209. }
  210. SECTION("skip uint 64") {
  211. error = deserializeMsgPack(
  212. doc,
  213. "\x82\xA6ignore\xCF\x12\x34\x56\x78\x9A\xBC\xDE\xF0\xA7include\x2A",
  214. filterOpt);
  215. CHECK(error == DeserializationError::Ok);
  216. CHECK(doc.as<std::string>() == "{\"include\":42}");
  217. CHECK(spy.log() ==
  218. AllocatorLog{
  219. Allocate(sizeofStringBuffer()),
  220. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  221. Allocate(sizeofPool()),
  222. Reallocate(sizeofPool(), sizeofObject(1)),
  223. });
  224. }
  225. SECTION("skip int 64") {
  226. error = deserializeMsgPack(
  227. doc,
  228. "\x82\xA6ignore\xD3\x12\x34\x56\x78\x9A\xBC\xDE\xF0\xA7include\x2A",
  229. filterOpt);
  230. CHECK(error == DeserializationError::Ok);
  231. CHECK(doc.as<std::string>() == "{\"include\":42}");
  232. CHECK(spy.log() ==
  233. AllocatorLog{
  234. Allocate(sizeofStringBuffer()),
  235. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  236. Allocate(sizeofPool()),
  237. Reallocate(sizeofPool(), sizeofObject(1)),
  238. });
  239. }
  240. SECTION("skip float 32") {
  241. error = deserializeMsgPack(
  242. doc, "\x82\xA6ignore\xCA\x40\x48\xF5\xC3\xA7include\x2A",
  243. filterOpt);
  244. CHECK(error == DeserializationError::Ok);
  245. CHECK(doc.as<std::string>() == "{\"include\":42}");
  246. CHECK(spy.log() ==
  247. AllocatorLog{
  248. Allocate(sizeofStringBuffer()),
  249. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  250. Allocate(sizeofPool()),
  251. Reallocate(sizeofPool(), sizeofObject(1)),
  252. });
  253. }
  254. SECTION("skip float 64") {
  255. error = deserializeMsgPack(
  256. doc,
  257. "\x82\xA6ignore\xCB\x40\x09\x21\xCA\xC0\x83\x12\x6F\xA7include\x2A",
  258. filterOpt);
  259. CHECK(error == DeserializationError::Ok);
  260. CHECK(doc.as<std::string>() == "{\"include\":42}");
  261. CHECK(spy.log() ==
  262. AllocatorLog{
  263. Allocate(sizeofStringBuffer()),
  264. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  265. Allocate(sizeofPool()),
  266. Reallocate(sizeofPool(), sizeofObject(1)),
  267. });
  268. }
  269. SECTION("skip fixstr") {
  270. error = deserializeMsgPack(
  271. doc, "\x82\xA6ignore\xABhello world\xA7include\x2A", filterOpt);
  272. CHECK(error == DeserializationError::Ok);
  273. CHECK(doc.as<std::string>() == "{\"include\":42}");
  274. CHECK(spy.log() ==
  275. AllocatorLog{
  276. Allocate(sizeofStringBuffer()),
  277. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  278. Allocate(sizeofPool()),
  279. Reallocate(sizeofPool(), sizeofObject(1)),
  280. });
  281. }
  282. SECTION("skip str 8") {
  283. error = deserializeMsgPack(
  284. doc, "\x82\xA6ignore\xd9\x05hello\xA7include\x2A", filterOpt);
  285. CHECK(error == DeserializationError::Ok);
  286. CHECK(doc.as<std::string>() == "{\"include\":42}");
  287. CHECK(spy.log() ==
  288. AllocatorLog{
  289. Allocate(sizeofStringBuffer()),
  290. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  291. Allocate(sizeofPool()),
  292. Reallocate(sizeofPool(), sizeofObject(1)),
  293. });
  294. }
  295. SECTION("skip str 16") {
  296. error = deserializeMsgPack(
  297. doc, "\x82\xA6ignore\xda\x00\x05hello\xA7include\x2A", filterOpt);
  298. CHECK(error == DeserializationError::Ok);
  299. CHECK(doc.as<std::string>() == "{\"include\":42}");
  300. CHECK(spy.log() ==
  301. AllocatorLog{
  302. Allocate(sizeofStringBuffer()),
  303. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  304. Allocate(sizeofPool()),
  305. Reallocate(sizeofPool(), sizeofObject(1)),
  306. });
  307. }
  308. SECTION("skip str 32") {
  309. error = deserializeMsgPack(
  310. doc, "\x82\xA6ignore\xdb\x00\x00\x00\x05hello\xA7include\x2A",
  311. filterOpt);
  312. CHECK(error == DeserializationError::Ok);
  313. CHECK(doc.as<std::string>() == "{\"include\":42}");
  314. CHECK(spy.log() ==
  315. AllocatorLog{
  316. Allocate(sizeofStringBuffer()),
  317. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  318. Allocate(sizeofPool()),
  319. Reallocate(sizeofPool(), sizeofObject(1)),
  320. });
  321. }
  322. SECTION("skip bin 8") {
  323. error = deserializeMsgPack(
  324. doc, "\x82\xA6ignore\xC4\x05hello\xA7include\x2A", filterOpt);
  325. CHECK(error == DeserializationError::Ok);
  326. CHECK(doc.as<std::string>() == "{\"include\":42}");
  327. CHECK(spy.log() ==
  328. AllocatorLog{
  329. Allocate(sizeofStringBuffer()),
  330. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  331. Allocate(sizeofPool()),
  332. Reallocate(sizeofPool(), sizeofObject(1)),
  333. });
  334. }
  335. SECTION("skip bin 16") {
  336. error = deserializeMsgPack(
  337. doc, "\x82\xA6ignore\xC5\x00\x05hello\xA7include\x2A", filterOpt);
  338. CHECK(error == DeserializationError::Ok);
  339. CHECK(doc.as<std::string>() == "{\"include\":42}");
  340. CHECK(spy.log() ==
  341. AllocatorLog{
  342. Allocate(sizeofStringBuffer()),
  343. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  344. Allocate(sizeofPool()),
  345. Reallocate(sizeofPool(), sizeofObject(1)),
  346. });
  347. }
  348. SECTION("skip bin 32") {
  349. error = deserializeMsgPack(
  350. doc, "\x82\xA6ignore\xC6\x00\x00\x00\x05hello\xA7include\x2A",
  351. filterOpt);
  352. CHECK(error == DeserializationError::Ok);
  353. CHECK(doc.as<std::string>() == "{\"include\":42}");
  354. CHECK(spy.log() ==
  355. AllocatorLog{
  356. Allocate(sizeofStringBuffer()),
  357. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  358. Allocate(sizeofPool()),
  359. Reallocate(sizeofPool(), sizeofObject(1)),
  360. });
  361. }
  362. SECTION("skip fixarray") {
  363. error = deserializeMsgPack(
  364. doc, "\x82\xA6ignore\x92\x01\x02\xA7include\x2A", filterOpt);
  365. CHECK(error == DeserializationError::Ok);
  366. CHECK(doc.as<std::string>() == "{\"include\":42}");
  367. CHECK(spy.log() ==
  368. AllocatorLog{
  369. Allocate(sizeofStringBuffer()),
  370. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  371. Allocate(sizeofPool()),
  372. Reallocate(sizeofPool(), sizeofObject(1)),
  373. });
  374. }
  375. SECTION("skip array 16") {
  376. error = deserializeMsgPack(
  377. doc, "\x82\xA6ignore\xDC\x00\x02\xA5hello\xA5world\xA7include\x2A",
  378. filterOpt);
  379. CHECK(error == DeserializationError::Ok);
  380. CHECK(doc.as<std::string>() == "{\"include\":42}");
  381. CHECK(spy.log() ==
  382. AllocatorLog{
  383. Allocate(sizeofStringBuffer()),
  384. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  385. Allocate(sizeofPool()),
  386. Reallocate(sizeofPool(), sizeofObject(1)),
  387. });
  388. }
  389. SECTION("skip array 32") {
  390. error = deserializeMsgPack(
  391. doc,
  392. "\x82\xA6ignore"
  393. "\xDD\x00\x00\x00\x02\xCA\x00\x00\x00\x00\xCA\x40\x48\xF5\xC3"
  394. "\xA7include\x2A",
  395. filterOpt);
  396. CHECK(error == DeserializationError::Ok);
  397. CHECK(doc.as<std::string>() == "{\"include\":42}");
  398. CHECK(spy.log() ==
  399. AllocatorLog{
  400. Allocate(sizeofStringBuffer()),
  401. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  402. Allocate(sizeofPool()),
  403. Reallocate(sizeofPool(), sizeofObject(1)),
  404. });
  405. }
  406. SECTION("skip fixmap") {
  407. error = deserializeMsgPack(
  408. doc, "\x82\xA6ignore\x82\xA3one\x01\xA3two\x02\xA7include\x2A",
  409. filterOpt);
  410. CHECK(error == DeserializationError::Ok);
  411. CHECK(doc.as<std::string>() == "{\"include\":42}");
  412. CHECK(spy.log() ==
  413. AllocatorLog{
  414. Allocate(sizeofStringBuffer()),
  415. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  416. Allocate(sizeofPool()),
  417. Reallocate(sizeofPool(), sizeofObject(1)),
  418. });
  419. }
  420. SECTION("skip map 16") {
  421. error = deserializeMsgPack(doc,
  422. "\x82\xA6ignore"
  423. "\xDE\x00\x02\xA1H\xA5hello\xA1W\xA5world"
  424. "\xA7include\x2A",
  425. filterOpt);
  426. CHECK(error == DeserializationError::Ok);
  427. CHECK(doc.as<std::string>() == "{\"include\":42}");
  428. CHECK(spy.log() ==
  429. AllocatorLog{
  430. Allocate(sizeofStringBuffer()),
  431. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  432. Allocate(sizeofPool()),
  433. Reallocate(sizeofPool(), sizeofObject(1)),
  434. });
  435. }
  436. SECTION("skip map 32") {
  437. error = deserializeMsgPack(doc,
  438. "\x82\xA6ignore"
  439. "\xDF\x00\x00\x00\x02"
  440. "\xA4zero\xCA\x00\x00\x00\x00"
  441. "\xA2pi\xCA\x40\x48\xF5\xC3"
  442. "\xA7include\x2A",
  443. filterOpt);
  444. CHECK(error == DeserializationError::Ok);
  445. CHECK(doc.as<std::string>() == "{\"include\":42}");
  446. CHECK(spy.log() ==
  447. AllocatorLog{
  448. Allocate(sizeofStringBuffer()),
  449. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  450. Allocate(sizeofPool()),
  451. Reallocate(sizeofPool(), sizeofObject(1)),
  452. });
  453. }
  454. SECTION("skip fixext 1") {
  455. error = deserializeMsgPack(doc,
  456. "\x82\xA6ignore"
  457. "\xd4\x01\x02"
  458. "\xA7include\x2A",
  459. filterOpt);
  460. CHECK(error == DeserializationError::Ok);
  461. CHECK(doc.as<std::string>() == "{\"include\":42}");
  462. CHECK(spy.log() ==
  463. AllocatorLog{
  464. Allocate(sizeofStringBuffer()),
  465. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  466. Allocate(sizeofPool()),
  467. Reallocate(sizeofPool(), sizeofObject(1)),
  468. });
  469. }
  470. SECTION("skip fixext 2") {
  471. error = deserializeMsgPack(doc,
  472. "\x82\xA6ignore"
  473. "\xd5\x01\x02\x03"
  474. "\xA7include\x2A",
  475. filterOpt);
  476. CHECK(error == DeserializationError::Ok);
  477. CHECK(doc.as<std::string>() == "{\"include\":42}");
  478. CHECK(spy.log() ==
  479. AllocatorLog{
  480. Allocate(sizeofStringBuffer()),
  481. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  482. Allocate(sizeofPool()),
  483. Reallocate(sizeofPool(), sizeofObject(1)),
  484. });
  485. }
  486. SECTION("skip fixext 4") {
  487. error = deserializeMsgPack(doc,
  488. "\x82\xA6ignore"
  489. "\xd6\x01\x02\x03\x04\x05"
  490. "\xA7include\x2A",
  491. filterOpt);
  492. CHECK(error == DeserializationError::Ok);
  493. CHECK(doc.as<std::string>() == "{\"include\":42}");
  494. CHECK(spy.log() ==
  495. AllocatorLog{
  496. Allocate(sizeofStringBuffer()),
  497. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  498. Allocate(sizeofPool()),
  499. Reallocate(sizeofPool(), sizeofObject(1)),
  500. });
  501. }
  502. SECTION("skip fixext 8") {
  503. error = deserializeMsgPack(doc,
  504. "\x82\xA6ignore"
  505. "\xd7\x01\x02\x03\x04\x05\x06\x07\x08\x09"
  506. "\xA7include\x2A",
  507. filterOpt);
  508. CHECK(error == DeserializationError::Ok);
  509. CHECK(doc.as<std::string>() == "{\"include\":42}");
  510. CHECK(spy.log() ==
  511. AllocatorLog{
  512. Allocate(sizeofStringBuffer()),
  513. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  514. Allocate(sizeofPool()),
  515. Reallocate(sizeofPool(), sizeofObject(1)),
  516. });
  517. }
  518. SECTION("skip fixext 16") {
  519. error =
  520. deserializeMsgPack(doc,
  521. "\x82\xA6ignore"
  522. "\xd8\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A"
  523. "\x0B\x0C\x0D\x0E\x0F\x10\x11"
  524. "\xA7include\x2A",
  525. filterOpt);
  526. CHECK(error == DeserializationError::Ok);
  527. CHECK(doc.as<std::string>() == "{\"include\":42}");
  528. CHECK(spy.log() ==
  529. AllocatorLog{
  530. Allocate(sizeofStringBuffer()),
  531. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  532. Allocate(sizeofPool()),
  533. Reallocate(sizeofPool(), sizeofObject(1)),
  534. });
  535. }
  536. SECTION("skip ext 8") {
  537. error = deserializeMsgPack(doc,
  538. "\x82\xA6ignore"
  539. "\xc7\x02\x00\x01\x02"
  540. "\xA7include\x2A",
  541. filterOpt);
  542. CHECK(error == DeserializationError::Ok);
  543. CHECK(doc.as<std::string>() == "{\"include\":42}");
  544. CHECK(spy.log() ==
  545. AllocatorLog{
  546. Allocate(sizeofStringBuffer()),
  547. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  548. Allocate(sizeofPool()),
  549. Reallocate(sizeofPool(), sizeofObject(1)),
  550. });
  551. }
  552. SECTION("skip ext 16") {
  553. error = deserializeMsgPack(doc,
  554. "\x82\xA6ignore"
  555. "\xc8\x00\x02\x00\x01\x02"
  556. "\xA7include\x2A",
  557. filterOpt);
  558. CHECK(error == DeserializationError::Ok);
  559. CHECK(doc.as<std::string>() == "{\"include\":42}");
  560. CHECK(spy.log() ==
  561. AllocatorLog{
  562. Allocate(sizeofStringBuffer()),
  563. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  564. Allocate(sizeofPool()),
  565. Reallocate(sizeofPool(), sizeofObject(1)),
  566. });
  567. }
  568. SECTION("skip ext 32") {
  569. error = deserializeMsgPack(doc,
  570. "\x82\xA6ignore"
  571. "\xc9\x00\x00\x00\x02\x00\x01\x02"
  572. "\xA7include\x2A",
  573. filterOpt);
  574. CHECK(error == DeserializationError::Ok);
  575. CHECK(doc.as<std::string>() == "{\"include\":42}");
  576. CHECK(spy.log() ==
  577. AllocatorLog{
  578. Allocate(sizeofStringBuffer()),
  579. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  580. Allocate(sizeofPool()),
  581. Reallocate(sizeofPool(), sizeofObject(1)),
  582. });
  583. }
  584. }
  585. SECTION("Filter = {arronly:[{measure:true}],include:true}") {
  586. filter["onlyarr"][0]["measure"] = true;
  587. filter["include"] = true;
  588. CAPTURE(filter.as<std::string>());
  589. SECTION("include fixarray") {
  590. error = deserializeMsgPack(doc,
  591. "\x82\xA7onlyarr\x92"
  592. "\x82\xA8location\x01\xA7measure\x02"
  593. "\x82\xA8location\x02\xA7measure\x04"
  594. "\xA7include\x2A",
  595. filterOpt);
  596. CHECK(error == DeserializationError::Ok);
  597. CHECK(doc.as<std::string>() ==
  598. "{\"onlyarr\":[{\"measure\":2},{\"measure\":4}],\"include\":42}");
  599. CHECK(spy.log() ==
  600. AllocatorLog{
  601. Allocate(sizeofStringBuffer()),
  602. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  603. Allocate(sizeofPool()),
  604. Allocate(sizeofStringBuffer()),
  605. Reallocate(sizeofStringBuffer(), sizeofString("measure")),
  606. Allocate(sizeofStringBuffer()),
  607. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  608. Reallocate(sizeofPool(), sizeofObject(2) + sizeofArray(2) +
  609. 2 * sizeofObject(1)),
  610. });
  611. }
  612. SECTION("include array 16") {
  613. error = deserializeMsgPack(doc,
  614. "\x82\xA7onlyarr"
  615. "\xDC\x00\x02"
  616. "\x82\xA8location\x01\xA7measure\x02"
  617. "\x82\xA8location\x02\xA7measure\x04"
  618. "\xA7include\x2A",
  619. filterOpt);
  620. CHECK(error == DeserializationError::Ok);
  621. CHECK(doc.as<std::string>() ==
  622. "{\"onlyarr\":[{\"measure\":2},{\"measure\":4}],\"include\":42}");
  623. CHECK(spy.log() ==
  624. AllocatorLog{
  625. Allocate(sizeofStringBuffer()),
  626. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  627. Allocate(sizeofPool()),
  628. Allocate(sizeofStringBuffer()),
  629. Reallocate(sizeofStringBuffer(), sizeofString("measure")),
  630. Allocate(sizeofStringBuffer()),
  631. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  632. Reallocate(sizeofPool(), sizeofObject(2) + sizeofArray(2) +
  633. 2 * sizeofObject(1)),
  634. });
  635. }
  636. SECTION("include array 32") {
  637. error = deserializeMsgPack(doc,
  638. "\x82\xA7onlyarr"
  639. "\xDD\x00\x00\x00\x02"
  640. "\x82\xA8location\x01\xA7measure\x02"
  641. "\x82\xA8location\x02\xA7measure\x04"
  642. "\xA7include\x2A",
  643. filterOpt);
  644. CHECK(error == DeserializationError::Ok);
  645. CHECK(doc.as<std::string>() ==
  646. "{\"onlyarr\":[{\"measure\":2},{\"measure\":4}],\"include\":42}");
  647. CHECK(spy.log() ==
  648. AllocatorLog{
  649. Allocate(sizeofStringBuffer()),
  650. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  651. Allocate(sizeofPool()),
  652. Allocate(sizeofStringBuffer()),
  653. Reallocate(sizeofStringBuffer(), sizeofString("measure")),
  654. Allocate(sizeofStringBuffer()),
  655. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  656. Reallocate(sizeofPool(), sizeofObject(2) + sizeofArray(2) +
  657. 2 * sizeofObject(1)),
  658. });
  659. }
  660. SECTION("skip null") {
  661. error = deserializeMsgPack(doc, "\x82\xA7onlyarr\xC0\xA7include\x2A",
  662. filterOpt);
  663. CHECK(error == DeserializationError::Ok);
  664. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  665. CHECK(spy.log() ==
  666. AllocatorLog{
  667. Allocate(sizeofStringBuffer()),
  668. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  669. Allocate(sizeofPool()),
  670. Allocate(sizeofStringBuffer()),
  671. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  672. Reallocate(sizeofPool(), sizeofObject(2)),
  673. });
  674. }
  675. SECTION("skip false") {
  676. error = deserializeMsgPack(doc, "\x82\xA7onlyarr\xC2\xA7include\x2A",
  677. filterOpt);
  678. CHECK(error == DeserializationError::Ok);
  679. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  680. CHECK(spy.log() ==
  681. AllocatorLog{
  682. Allocate(sizeofStringBuffer()),
  683. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  684. Allocate(sizeofPool()),
  685. Allocate(sizeofStringBuffer()),
  686. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  687. Reallocate(sizeofPool(), sizeofObject(2)),
  688. });
  689. }
  690. SECTION("skip true") {
  691. error = deserializeMsgPack(doc, "\x82\xA7onlyarr\xC3\xA7include\x2A",
  692. filterOpt);
  693. CHECK(error == DeserializationError::Ok);
  694. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  695. CHECK(spy.log() ==
  696. AllocatorLog{
  697. Allocate(sizeofStringBuffer()),
  698. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  699. Allocate(sizeofPool()),
  700. Allocate(sizeofStringBuffer()),
  701. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  702. Reallocate(sizeofPool(), sizeofObject(2)),
  703. });
  704. }
  705. SECTION("skip positive fixint") {
  706. error = deserializeMsgPack(doc, "\x82\xA7onlyarr\x2A\xA7include\x2A",
  707. filterOpt);
  708. CHECK(error == DeserializationError::Ok);
  709. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  710. CHECK(spy.log() ==
  711. AllocatorLog{
  712. Allocate(sizeofStringBuffer()),
  713. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  714. Allocate(sizeofPool()),
  715. Allocate(sizeofStringBuffer()),
  716. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  717. Reallocate(sizeofPool(), sizeofObject(2)),
  718. });
  719. }
  720. SECTION("skip negative fixint") {
  721. error = deserializeMsgPack(doc, "\x82\xA7onlyarr\xFF\xA7include\x2A",
  722. filterOpt);
  723. CHECK(error == DeserializationError::Ok);
  724. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  725. CHECK(spy.log() ==
  726. AllocatorLog{
  727. Allocate(sizeofStringBuffer()),
  728. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  729. Allocate(sizeofPool()),
  730. Allocate(sizeofStringBuffer()),
  731. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  732. Reallocate(sizeofPool(), sizeofObject(2)),
  733. });
  734. }
  735. SECTION("skip uint 8") {
  736. error = deserializeMsgPack(
  737. doc, "\x82\xA7onlyarr\xCC\x2A\xA7include\x2A", filterOpt);
  738. CHECK(error == DeserializationError::Ok);
  739. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  740. CHECK(spy.log() ==
  741. AllocatorLog{
  742. Allocate(sizeofStringBuffer()),
  743. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  744. Allocate(sizeofPool()),
  745. Allocate(sizeofStringBuffer()),
  746. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  747. Reallocate(sizeofPool(), sizeofObject(2)),
  748. });
  749. }
  750. SECTION("skip uint 16") {
  751. error = deserializeMsgPack(
  752. doc, "\x82\xA7onlyarr\xcd\x30\x39\xA7include\x2A", filterOpt);
  753. CHECK(error == DeserializationError::Ok);
  754. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  755. CHECK(spy.log() ==
  756. AllocatorLog{
  757. Allocate(sizeofStringBuffer()),
  758. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  759. Allocate(sizeofPool()),
  760. Allocate(sizeofStringBuffer()),
  761. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  762. Reallocate(sizeofPool(), sizeofObject(2)),
  763. });
  764. }
  765. SECTION("skip uint 32") {
  766. error = deserializeMsgPack(
  767. doc, "\x82\xA7onlyarr\xCE\x12\x34\x56\x78\xA7include\x2A",
  768. filterOpt);
  769. CHECK(error == DeserializationError::Ok);
  770. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  771. CHECK(spy.log() ==
  772. AllocatorLog{
  773. Allocate(sizeofStringBuffer()),
  774. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  775. Allocate(sizeofPool()),
  776. Allocate(sizeofStringBuffer()),
  777. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  778. Reallocate(sizeofPool(), sizeofObject(2)),
  779. });
  780. }
  781. SECTION("skip uint 64") {
  782. error = deserializeMsgPack(doc,
  783. "\x82\xA7onlyarr\xCF\x12\x34\x56\x78\x9A\xBC"
  784. "\xDE\xF0\xA7include\x2A",
  785. filterOpt);
  786. CHECK(error == DeserializationError::Ok);
  787. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  788. CHECK(spy.log() ==
  789. AllocatorLog{
  790. Allocate(sizeofStringBuffer()),
  791. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  792. Allocate(sizeofPool()),
  793. Allocate(sizeofStringBuffer()),
  794. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  795. Reallocate(sizeofPool(), sizeofObject(2)),
  796. });
  797. }
  798. SECTION("skip int 8") {
  799. error = deserializeMsgPack(
  800. doc, "\x82\xA7onlyarr\xD0\x2A\xA7include\x2A", filterOpt);
  801. CHECK(error == DeserializationError::Ok);
  802. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  803. CHECK(spy.log() ==
  804. AllocatorLog{
  805. Allocate(sizeofStringBuffer()),
  806. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  807. Allocate(sizeofPool()),
  808. Allocate(sizeofStringBuffer()),
  809. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  810. Reallocate(sizeofPool(), sizeofObject(2)),
  811. });
  812. }
  813. SECTION("skip int 16") {
  814. error = deserializeMsgPack(
  815. doc, "\x82\xA7onlyarr\xD1\xCF\xC7\xA7include\x2A", filterOpt);
  816. CHECK(error == DeserializationError::Ok);
  817. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  818. CHECK(spy.log() ==
  819. AllocatorLog{
  820. Allocate(sizeofStringBuffer()),
  821. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  822. Allocate(sizeofPool()),
  823. Allocate(sizeofStringBuffer()),
  824. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  825. Reallocate(sizeofPool(), sizeofObject(2)),
  826. });
  827. }
  828. SECTION("skip int 32") {
  829. error = deserializeMsgPack(
  830. doc, "\x82\xA7onlyarr\xD2\xB6\x69\xFD\x2E\xA7include\x2A",
  831. filterOpt);
  832. CHECK(error == DeserializationError::Ok);
  833. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  834. CHECK(spy.log() ==
  835. AllocatorLog{
  836. Allocate(sizeofStringBuffer()),
  837. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  838. Allocate(sizeofPool()),
  839. Allocate(sizeofStringBuffer()),
  840. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  841. Reallocate(sizeofPool(), sizeofObject(2)),
  842. });
  843. }
  844. SECTION("skip int 64") {
  845. error = deserializeMsgPack(doc,
  846. "\x82\xA7onlyarr\xD3\x12\x34\x56\x78\x9A\xBC"
  847. "\xDE\xF0\xA7include\x2A",
  848. filterOpt);
  849. CHECK(error == DeserializationError::Ok);
  850. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  851. CHECK(spy.log() ==
  852. AllocatorLog{
  853. Allocate(sizeofStringBuffer()),
  854. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  855. Allocate(sizeofPool()),
  856. Allocate(sizeofStringBuffer()),
  857. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  858. Reallocate(sizeofPool(), sizeofObject(2)),
  859. });
  860. }
  861. SECTION("skip float 32") {
  862. error = deserializeMsgPack(
  863. doc, "\x82\xA7onlyarr\xCA\x40\x48\xF5\xC3\xA7include\x2A",
  864. filterOpt);
  865. CHECK(error == DeserializationError::Ok);
  866. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  867. CHECK(spy.log() ==
  868. AllocatorLog{
  869. Allocate(sizeofStringBuffer()),
  870. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  871. Allocate(sizeofPool()),
  872. Allocate(sizeofStringBuffer()),
  873. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  874. Reallocate(sizeofPool(), sizeofObject(2)),
  875. });
  876. }
  877. SECTION("skip float 64") {
  878. error = deserializeMsgPack(doc,
  879. "\x82\xA7onlyarr\xCB\x40\x09\x21\xCA\xC0\x83"
  880. "\x12\x6F\xA7include\x2A",
  881. filterOpt);
  882. CHECK(error == DeserializationError::Ok);
  883. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  884. CHECK(spy.log() ==
  885. AllocatorLog{
  886. Allocate(sizeofStringBuffer()),
  887. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  888. Allocate(sizeofPool()),
  889. Allocate(sizeofStringBuffer()),
  890. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  891. Reallocate(sizeofPool(), sizeofObject(2)),
  892. });
  893. }
  894. SECTION("skip fixstr") {
  895. error = deserializeMsgPack(
  896. doc, "\x82\xA7onlyarr\xABhello world\xA7include\x2A", filterOpt);
  897. CHECK(error == DeserializationError::Ok);
  898. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  899. CHECK(spy.log() ==
  900. AllocatorLog{
  901. Allocate(sizeofStringBuffer()),
  902. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  903. Allocate(sizeofPool()),
  904. Allocate(sizeofStringBuffer()),
  905. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  906. Reallocate(sizeofPool(), sizeofObject(2)),
  907. });
  908. }
  909. SECTION("skip str 8") {
  910. error = deserializeMsgPack(
  911. doc, "\x82\xA7onlyarr\xd9\x05hello\xA7include\x2A", filterOpt);
  912. CHECK(error == DeserializationError::Ok);
  913. }
  914. SECTION("skip str 16") {
  915. error = deserializeMsgPack(
  916. doc, "\x82\xA7onlyarr\xda\x00\x05hello\xA7include\x2A", filterOpt);
  917. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  918. }
  919. SECTION("skip str 32") {
  920. error = deserializeMsgPack(
  921. doc, "\x82\xA7onlyarr\xdb\x00\x00\x00\x05hello\xA7include\x2A",
  922. filterOpt);
  923. CHECK(spy.log() ==
  924. AllocatorLog{
  925. Allocate(sizeofStringBuffer()),
  926. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  927. Allocate(sizeofPool()),
  928. Allocate(sizeofStringBuffer()),
  929. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  930. Reallocate(sizeofPool(), sizeofObject(2)),
  931. });
  932. }
  933. SECTION("skip fixmap") {
  934. error = deserializeMsgPack(
  935. doc, "\x82\xA7onlyarr\x82\xA3one\x01\xA3two\x02\xA7include\x2A",
  936. filterOpt);
  937. CHECK(error == DeserializationError::Ok);
  938. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  939. CHECK(spy.log() ==
  940. AllocatorLog{
  941. Allocate(sizeofStringBuffer()),
  942. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  943. Allocate(sizeofPool()),
  944. Allocate(sizeofStringBuffer()),
  945. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  946. Reallocate(sizeofPool(), sizeofObject(2)),
  947. });
  948. }
  949. SECTION("skip map 16") {
  950. error = deserializeMsgPack(doc,
  951. "\x82\xA7onlyarr"
  952. "\xDE\x00\x02\xA1H\xA5hello\xA1W\xA5world"
  953. "\xA7include\x2A",
  954. filterOpt);
  955. CHECK(error == DeserializationError::Ok);
  956. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  957. CHECK(spy.log() ==
  958. AllocatorLog{
  959. Allocate(sizeofStringBuffer()),
  960. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  961. Allocate(sizeofPool()),
  962. Allocate(sizeofStringBuffer()),
  963. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  964. Reallocate(sizeofPool(), sizeofObject(2)),
  965. });
  966. }
  967. SECTION("skip map 32") {
  968. error = deserializeMsgPack(doc,
  969. "\x82\xA7onlyarr"
  970. "\xDF\x00\x00\x00\x02"
  971. "\xA4zero\xCA\x00\x00\x00\x00"
  972. "\xA2pi\xCA\x40\x48\xF5\xC3"
  973. "\xA7include\x2A",
  974. filterOpt);
  975. CHECK(error == DeserializationError::Ok);
  976. CHECK(doc.as<std::string>() == "{\"onlyarr\":null,\"include\":42}");
  977. CHECK(spy.log() ==
  978. AllocatorLog{
  979. Allocate(sizeofStringBuffer()),
  980. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  981. Allocate(sizeofPool()),
  982. Allocate(sizeofStringBuffer()),
  983. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  984. Reallocate(sizeofPool(), sizeofObject(2)),
  985. });
  986. }
  987. }
  988. }
  989. SECTION("root is fixarray") {
  990. SECTION("filter = [false, true]") {
  991. filter[0] = false; // only the first elment of the filter matters
  992. filter[1] = true; // so this one is ignored
  993. SECTION("input = [1,2,3]") {
  994. error = deserializeMsgPack(doc, "\x93\x01\x02\x03", filterOpt);
  995. CHECK(error == DeserializationError::Ok);
  996. CHECK(doc.as<std::string>() == "[]");
  997. CHECK(spy.log() == AllocatorLog());
  998. }
  999. }
  1000. SECTION("filter = [true, false]") {
  1001. filter[0] = true; // only the first elment of the filter matters
  1002. filter[1] = false; // so this one is ignored
  1003. SECTION("input = [1,2,3]") {
  1004. error = deserializeMsgPack(doc, "\x93\x01\x02\x03", filterOpt);
  1005. CHECK(error == DeserializationError::Ok);
  1006. CHECK(doc.as<std::string>() == "[1,2,3]");
  1007. CHECK(spy.log() == AllocatorLog{
  1008. Allocate(sizeofPool()),
  1009. Reallocate(sizeofPool(), sizeofArray(3)),
  1010. });
  1011. }
  1012. }
  1013. }
  1014. SECTION("Filter = {onlyobj:{measure:true},include:true}") {
  1015. filter["onlyobj"]["measure"] = true;
  1016. filter["include"] = true;
  1017. CAPTURE(filter.as<std::string>());
  1018. SECTION("include fixmap") {
  1019. error = deserializeMsgPack(doc,
  1020. "\x82\xA7onlyobj"
  1021. "\x82\xA8location\x01\xA7measure\x02"
  1022. "\xA7include\x2A",
  1023. filterOpt);
  1024. CHECK(error == DeserializationError::Ok);
  1025. CHECK(doc.as<std::string>() ==
  1026. "{\"onlyobj\":{\"measure\":2},\"include\":42}");
  1027. CHECK(spy.log() ==
  1028. AllocatorLog{
  1029. Allocate(sizeofStringBuffer()),
  1030. Reallocate(sizeofStringBuffer(), sizeofString("onlyobj")),
  1031. Allocate(sizeofPool()),
  1032. Allocate(sizeofStringBuffer()),
  1033. Reallocate(sizeofStringBuffer(), sizeofString("measure")),
  1034. Allocate(sizeofStringBuffer()),
  1035. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1036. Reallocate(sizeofPool(), sizeofObject(2) + sizeofObject(1)),
  1037. });
  1038. }
  1039. SECTION("include map 16") {
  1040. error = deserializeMsgPack(doc,
  1041. "\x82\xA7onlyobj"
  1042. "\xDE\x00\x02\xA8location\x01\xA7measure\x02"
  1043. "\xA7include\x2A",
  1044. filterOpt);
  1045. CHECK(error == DeserializationError::Ok);
  1046. CHECK(doc.as<std::string>() ==
  1047. "{\"onlyobj\":{\"measure\":2},\"include\":42}");
  1048. CHECK(spy.log() ==
  1049. AllocatorLog{
  1050. Allocate(sizeofStringBuffer()),
  1051. Reallocate(sizeofStringBuffer(), sizeofString("onlyobj")),
  1052. Allocate(sizeofPool()),
  1053. Allocate(sizeofStringBuffer()),
  1054. Reallocate(sizeofStringBuffer(), sizeofString("measure")),
  1055. Allocate(sizeofStringBuffer()),
  1056. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1057. Reallocate(sizeofPool(), sizeofObject(2) + sizeofObject(1)),
  1058. });
  1059. }
  1060. SECTION("include map 32") {
  1061. error = deserializeMsgPack(doc,
  1062. "\x82\xA7onlyobj"
  1063. "\xDF\x00\x00\x00\x02"
  1064. "\xA8location\x01\xA7measure\x02"
  1065. "\xA7include\x2A",
  1066. filterOpt);
  1067. CHECK(error == DeserializationError::Ok);
  1068. CHECK(doc.as<std::string>() ==
  1069. "{\"onlyobj\":{\"measure\":2},\"include\":42}");
  1070. CHECK(spy.log() ==
  1071. AllocatorLog{
  1072. Allocate(sizeofStringBuffer()),
  1073. Reallocate(sizeofStringBuffer(), sizeofString("onlyobj")),
  1074. Allocate(sizeofPool()),
  1075. Allocate(sizeofStringBuffer()),
  1076. Reallocate(sizeofStringBuffer(), sizeofString("measure")),
  1077. Allocate(sizeofStringBuffer()),
  1078. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1079. Reallocate(sizeofPool(), sizeofObject(2) + sizeofObject(1)),
  1080. });
  1081. }
  1082. SECTION("skip null") {
  1083. error = deserializeMsgPack(doc, "\x82\xA7onlyobj\xC0\xA7include\x2A",
  1084. filterOpt);
  1085. CHECK(error == DeserializationError::Ok);
  1086. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1087. CHECK(spy.log() ==
  1088. AllocatorLog{
  1089. Allocate(sizeofStringBuffer()),
  1090. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1091. Allocate(sizeofPool()),
  1092. Allocate(sizeofStringBuffer()),
  1093. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1094. Reallocate(sizeofPool(), sizeofObject(2)),
  1095. });
  1096. }
  1097. SECTION("skip false") {
  1098. error = deserializeMsgPack(doc, "\x82\xA7onlyobj\xC2\xA7include\x2A",
  1099. filterOpt);
  1100. CHECK(error == DeserializationError::Ok);
  1101. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1102. CHECK(spy.log() ==
  1103. AllocatorLog{
  1104. Allocate(sizeofStringBuffer()),
  1105. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1106. Allocate(sizeofPool()),
  1107. Allocate(sizeofStringBuffer()),
  1108. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1109. Reallocate(sizeofPool(), sizeofObject(2)),
  1110. });
  1111. }
  1112. SECTION("skip true") {
  1113. error = deserializeMsgPack(doc, "\x82\xA7onlyobj\xC3\xA7include\x2A",
  1114. filterOpt);
  1115. CHECK(error == DeserializationError::Ok);
  1116. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1117. CHECK(spy.log() ==
  1118. AllocatorLog{
  1119. Allocate(sizeofStringBuffer()),
  1120. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1121. Allocate(sizeofPool()),
  1122. Allocate(sizeofStringBuffer()),
  1123. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1124. Reallocate(sizeofPool(), sizeofObject(2)),
  1125. });
  1126. }
  1127. SECTION("skip positive fixint") {
  1128. error = deserializeMsgPack(doc, "\x82\xA7onlyobj\x2A\xA7include\x2A",
  1129. filterOpt);
  1130. CHECK(error == DeserializationError::Ok);
  1131. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1132. CHECK(spy.log() ==
  1133. AllocatorLog{
  1134. Allocate(sizeofStringBuffer()),
  1135. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1136. Allocate(sizeofPool()),
  1137. Allocate(sizeofStringBuffer()),
  1138. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1139. Reallocate(sizeofPool(), sizeofObject(2)),
  1140. });
  1141. }
  1142. SECTION("skip negative fixint") {
  1143. error = deserializeMsgPack(doc, "\x82\xA7onlyobj\xFF\xA7include\x2A",
  1144. filterOpt);
  1145. CHECK(error == DeserializationError::Ok);
  1146. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1147. CHECK(spy.log() ==
  1148. AllocatorLog{
  1149. Allocate(sizeofStringBuffer()),
  1150. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1151. Allocate(sizeofPool()),
  1152. Allocate(sizeofStringBuffer()),
  1153. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1154. Reallocate(sizeofPool(), sizeofObject(2)),
  1155. });
  1156. }
  1157. SECTION("skip uint 8") {
  1158. error = deserializeMsgPack(doc, "\x82\xA7onlyobj\xCC\x2A\xA7include\x2A",
  1159. filterOpt);
  1160. CHECK(error == DeserializationError::Ok);
  1161. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1162. CHECK(spy.log() ==
  1163. AllocatorLog{
  1164. Allocate(sizeofStringBuffer()),
  1165. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1166. Allocate(sizeofPool()),
  1167. Allocate(sizeofStringBuffer()),
  1168. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1169. Reallocate(sizeofPool(), sizeofObject(2)),
  1170. });
  1171. }
  1172. SECTION("skip uint 16") {
  1173. error = deserializeMsgPack(
  1174. doc, "\x82\xA7onlyobj\xcd\x30\x39\xA7include\x2A", filterOpt);
  1175. CHECK(error == DeserializationError::Ok);
  1176. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1177. CHECK(spy.log() ==
  1178. AllocatorLog{
  1179. Allocate(sizeofStringBuffer()),
  1180. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1181. Allocate(sizeofPool()),
  1182. Allocate(sizeofStringBuffer()),
  1183. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1184. Reallocate(sizeofPool(), sizeofObject(2)),
  1185. });
  1186. }
  1187. SECTION("skip uint 32") {
  1188. error = deserializeMsgPack(
  1189. doc, "\x82\xA7onlyobj\xCE\x12\x34\x56\x78\xA7include\x2A", filterOpt);
  1190. CHECK(error == DeserializationError::Ok);
  1191. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1192. CHECK(spy.log() ==
  1193. AllocatorLog{
  1194. Allocate(sizeofStringBuffer()),
  1195. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1196. Allocate(sizeofPool()),
  1197. Allocate(sizeofStringBuffer()),
  1198. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1199. Reallocate(sizeofPool(), sizeofObject(2)),
  1200. });
  1201. }
  1202. SECTION("skip uint 64") {
  1203. error = deserializeMsgPack(doc,
  1204. "\x82\xA7onlyobj\xCF\x12\x34\x56\x78\x9A\xBC"
  1205. "\xDE\xF0\xA7include\x2A",
  1206. filterOpt);
  1207. CHECK(error == DeserializationError::Ok);
  1208. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1209. CHECK(spy.log() ==
  1210. AllocatorLog{
  1211. Allocate(sizeofStringBuffer()),
  1212. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1213. Allocate(sizeofPool()),
  1214. Allocate(sizeofStringBuffer()),
  1215. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1216. Reallocate(sizeofPool(), sizeofObject(2)),
  1217. });
  1218. }
  1219. SECTION("skip int 8") {
  1220. error = deserializeMsgPack(doc, "\x82\xA7onlyobj\xD0\x2A\xA7include\x2A",
  1221. filterOpt);
  1222. CHECK(error == DeserializationError::Ok);
  1223. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1224. CHECK(spy.log() ==
  1225. AllocatorLog{
  1226. Allocate(sizeofStringBuffer()),
  1227. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1228. Allocate(sizeofPool()),
  1229. Allocate(sizeofStringBuffer()),
  1230. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1231. Reallocate(sizeofPool(), sizeofObject(2)),
  1232. });
  1233. }
  1234. SECTION("skip int 16") {
  1235. error = deserializeMsgPack(
  1236. doc, "\x82\xA7onlyobj\xD1\xCF\xC7\xA7include\x2A", filterOpt);
  1237. CHECK(error == DeserializationError::Ok);
  1238. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1239. CHECK(spy.log() ==
  1240. AllocatorLog{
  1241. Allocate(sizeofStringBuffer()),
  1242. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1243. Allocate(sizeofPool()),
  1244. Allocate(sizeofStringBuffer()),
  1245. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1246. Reallocate(sizeofPool(), sizeofObject(2)),
  1247. });
  1248. }
  1249. SECTION("skip int 32") {
  1250. error = deserializeMsgPack(
  1251. doc, "\x82\xA7onlyobj\xD2\xB6\x69\xFD\x2E\xA7include\x2A", filterOpt);
  1252. CHECK(error == DeserializationError::Ok);
  1253. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1254. CHECK(spy.log() ==
  1255. AllocatorLog{
  1256. Allocate(sizeofStringBuffer()),
  1257. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1258. Allocate(sizeofPool()),
  1259. Allocate(sizeofStringBuffer()),
  1260. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1261. Reallocate(sizeofPool(), sizeofObject(2)),
  1262. });
  1263. }
  1264. SECTION("skip int 64") {
  1265. error = deserializeMsgPack(doc,
  1266. "\x82\xA7onlyobj\xD3\x12\x34\x56\x78\x9A\xBC"
  1267. "\xDE\xF0\xA7include\x2A",
  1268. filterOpt);
  1269. CHECK(error == DeserializationError::Ok);
  1270. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1271. CHECK(spy.log() ==
  1272. AllocatorLog{
  1273. Allocate(sizeofStringBuffer()),
  1274. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1275. Allocate(sizeofPool()),
  1276. Allocate(sizeofStringBuffer()),
  1277. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1278. Reallocate(sizeofPool(), sizeofObject(2)),
  1279. });
  1280. }
  1281. SECTION("skip float 32") {
  1282. error = deserializeMsgPack(
  1283. doc, "\x82\xA7onlyobj\xCA\x40\x48\xF5\xC3\xA7include\x2A", filterOpt);
  1284. CHECK(error == DeserializationError::Ok);
  1285. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1286. CHECK(spy.log() ==
  1287. AllocatorLog{
  1288. Allocate(sizeofStringBuffer()),
  1289. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1290. Allocate(sizeofPool()),
  1291. Allocate(sizeofStringBuffer()),
  1292. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1293. Reallocate(sizeofPool(), sizeofObject(2)),
  1294. });
  1295. }
  1296. SECTION("skip float 64") {
  1297. error = deserializeMsgPack(doc,
  1298. "\x82\xA7onlyobj\xCB\x40\x09\x21\xCA\xC0\x83"
  1299. "\x12\x6F\xA7include\x2A",
  1300. filterOpt);
  1301. CHECK(error == DeserializationError::Ok);
  1302. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1303. CHECK(spy.log() ==
  1304. AllocatorLog{
  1305. Allocate(sizeofStringBuffer()),
  1306. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1307. Allocate(sizeofPool()),
  1308. Allocate(sizeofStringBuffer()),
  1309. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1310. Reallocate(sizeofPool(), sizeofObject(2)),
  1311. });
  1312. }
  1313. SECTION("skip fixstr") {
  1314. error = deserializeMsgPack(
  1315. doc, "\x82\xA7onlyobj\xABhello world\xA7include\x2A", filterOpt);
  1316. CHECK(error == DeserializationError::Ok);
  1317. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1318. CHECK(spy.log() ==
  1319. AllocatorLog{
  1320. Allocate(sizeofStringBuffer()),
  1321. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1322. Allocate(sizeofPool()),
  1323. Allocate(sizeofStringBuffer()),
  1324. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1325. Reallocate(sizeofPool(), sizeofObject(2)),
  1326. });
  1327. }
  1328. SECTION("skip str 8") {
  1329. error = deserializeMsgPack(
  1330. doc, "\x82\xA7onlyobj\xd9\x05hello\xA7include\x2A", filterOpt);
  1331. CHECK(error == DeserializationError::Ok);
  1332. }
  1333. SECTION("skip str 16") {
  1334. error = deserializeMsgPack(
  1335. doc, "\x82\xA7onlyobj\xda\x00\x05hello\xA7include\x2A", filterOpt);
  1336. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1337. }
  1338. SECTION("skip str 32") {
  1339. error = deserializeMsgPack(
  1340. doc, "\x82\xA7onlyobj\xdb\x00\x00\x00\x05hello\xA7include\x2A",
  1341. filterOpt);
  1342. CHECK(spy.log() ==
  1343. AllocatorLog{
  1344. Allocate(sizeofStringBuffer()),
  1345. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1346. Allocate(sizeofPool()),
  1347. Allocate(sizeofStringBuffer()),
  1348. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1349. Reallocate(sizeofPool(), sizeofObject(2)),
  1350. });
  1351. }
  1352. SECTION("skip fixarray") {
  1353. error = deserializeMsgPack(
  1354. doc, "\x82\xA7onlyobj\x92\x01\x02\xA7include\x2A", filterOpt);
  1355. CHECK(error == DeserializationError::Ok);
  1356. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1357. CHECK(spy.log() ==
  1358. AllocatorLog{
  1359. Allocate(sizeofStringBuffer()),
  1360. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1361. Allocate(sizeofPool()),
  1362. Allocate(sizeofStringBuffer()),
  1363. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1364. Reallocate(sizeofPool(), sizeofObject(2)),
  1365. });
  1366. }
  1367. SECTION("skip array 16") {
  1368. error = deserializeMsgPack(doc,
  1369. "\x82\xA7onlyobj\xDC\x00\x01\xA7"
  1370. "example\xA7include\x2A",
  1371. filterOpt);
  1372. CHECK(error == DeserializationError::Ok);
  1373. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1374. CHECK(spy.log() ==
  1375. AllocatorLog{
  1376. Allocate(sizeofStringBuffer()),
  1377. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1378. Allocate(sizeofPool()),
  1379. Allocate(sizeofStringBuffer()),
  1380. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1381. Reallocate(sizeofPool(), sizeofObject(2)),
  1382. });
  1383. }
  1384. SECTION("skip array 32") {
  1385. error = deserializeMsgPack(doc,
  1386. "\x82\xA7onlyobj"
  1387. "\xDD\x00\x00\x00\x02\x01\x02"
  1388. "\xA7include\x2A",
  1389. filterOpt);
  1390. CHECK(error == DeserializationError::Ok);
  1391. CHECK(doc.as<std::string>() == "{\"onlyobj\":null,\"include\":42}");
  1392. CHECK(spy.log() ==
  1393. AllocatorLog{
  1394. Allocate(sizeofStringBuffer()),
  1395. Reallocate(sizeofStringBuffer(), sizeofString("onlyarr")),
  1396. Allocate(sizeofPool()),
  1397. Allocate(sizeofStringBuffer()),
  1398. Reallocate(sizeofStringBuffer(), sizeofString("include")),
  1399. Reallocate(sizeofPool(), sizeofObject(2)),
  1400. });
  1401. }
  1402. }
  1403. SECTION("filter = true") {
  1404. filter.set(true);
  1405. error = deserializeMsgPack(doc, "\x90", filterOpt);
  1406. CHECK(error == DeserializationError::Ok);
  1407. CHECK(doc.is<JsonArray>() == true);
  1408. CHECK(doc.size() == 0);
  1409. }
  1410. SECTION("filter = false") {
  1411. filter.set(false);
  1412. SECTION("input = fixarray") {
  1413. error = deserializeMsgPack(doc, "\x92\x01\x02", filterOpt);
  1414. CHECK(error == DeserializationError::Ok);
  1415. CHECK(doc.isNull() == true);
  1416. }
  1417. SECTION("input = array 16") {
  1418. error = deserializeMsgPack(doc, "\xDC\x00\x02\x01\x02", filterOpt);
  1419. CHECK(error == DeserializationError::Ok);
  1420. CHECK(doc.isNull() == true);
  1421. }
  1422. SECTION("array too deep") {
  1423. error = deserializeMsgPack(doc, "\x91\x91\x91\x91\x91", 5, filterOpt,
  1424. DeserializationOption::NestingLimit(4));
  1425. CHECK(error == DeserializationError::TooDeep);
  1426. }
  1427. SECTION("object too deep") {
  1428. error = deserializeMsgPack(
  1429. doc, "\x81\xA1z\x81\xA1z\x81\xA1z\x81\xA1z\x81\xA1z", 15, filterOpt,
  1430. DeserializationOption::NestingLimit(4));
  1431. CHECK(error == DeserializationError::TooDeep);
  1432. }
  1433. }
  1434. }
  1435. TEST_CASE("Zero-copy mode") { // issue #1697
  1436. char input[] = "\x82\xA7include\x01\xA6ignore\x02";
  1437. JsonDocument filter;
  1438. filter["include"] = true;
  1439. JsonDocument doc;
  1440. DeserializationError err =
  1441. deserializeMsgPack(doc, input, 18, DeserializationOption::Filter(filter));
  1442. CHECK(err == DeserializationError::Ok);
  1443. CHECK(doc.as<std::string>() == "{\"include\":1}");
  1444. }
  1445. TEST_CASE("Overloads") {
  1446. JsonDocument doc;
  1447. JsonDocument filter;
  1448. using namespace DeserializationOption;
  1449. // deserializeMsgPack(..., Filter)
  1450. SECTION("const char*, Filter") {
  1451. deserializeMsgPack(doc, "{}", Filter(filter));
  1452. }
  1453. SECTION("const char*, size_t, Filter") {
  1454. deserializeMsgPack(doc, "{}", 2, Filter(filter));
  1455. }
  1456. SECTION("const std::string&, Filter") {
  1457. deserializeMsgPack(doc, std::string("{}"), Filter(filter));
  1458. }
  1459. SECTION("std::istream&, Filter") {
  1460. std::stringstream s("{}");
  1461. deserializeMsgPack(doc, s, Filter(filter));
  1462. }
  1463. #ifdef HAS_VARIABLE_LENGTH_ARRAY
  1464. SECTION("char[n], Filter") {
  1465. size_t i = 4;
  1466. char vla[i];
  1467. strcpy(vla, "{}");
  1468. deserializeMsgPack(doc, vla, Filter(filter));
  1469. }
  1470. #endif
  1471. // deserializeMsgPack(..., Filter, NestingLimit)
  1472. SECTION("const char*, Filter, NestingLimit") {
  1473. deserializeMsgPack(doc, "{}", Filter(filter), NestingLimit(5));
  1474. }
  1475. SECTION("const char*, size_t, Filter, NestingLimit") {
  1476. deserializeMsgPack(doc, "{}", 2, Filter(filter), NestingLimit(5));
  1477. }
  1478. SECTION("const std::string&, Filter, NestingLimit") {
  1479. deserializeMsgPack(doc, std::string("{}"), Filter(filter), NestingLimit(5));
  1480. }
  1481. SECTION("std::istream&, Filter, NestingLimit") {
  1482. std::stringstream s("{}");
  1483. deserializeMsgPack(doc, s, Filter(filter), NestingLimit(5));
  1484. }
  1485. #ifdef HAS_VARIABLE_LENGTH_ARRAY
  1486. SECTION("char[n], Filter, NestingLimit") {
  1487. size_t i = 4;
  1488. char vla[i];
  1489. strcpy(vla, "{}");
  1490. deserializeMsgPack(doc, vla, Filter(filter), NestingLimit(5));
  1491. }
  1492. #endif
  1493. // deserializeMsgPack(..., NestingLimit, Filter)
  1494. SECTION("const char*, NestingLimit, Filter") {
  1495. deserializeMsgPack(doc, "{}", NestingLimit(5), Filter(filter));
  1496. }
  1497. SECTION("const char*, size_t, NestingLimit, Filter") {
  1498. deserializeMsgPack(doc, "{}", 2, NestingLimit(5), Filter(filter));
  1499. }
  1500. SECTION("const std::string&, NestingLimit, Filter") {
  1501. deserializeMsgPack(doc, std::string("{}"), NestingLimit(5), Filter(filter));
  1502. }
  1503. SECTION("std::istream&, NestingLimit, Filter") {
  1504. std::stringstream s("{}");
  1505. deserializeMsgPack(doc, s, NestingLimit(5), Filter(filter));
  1506. }
  1507. #ifdef HAS_VARIABLE_LENGTH_ARRAY
  1508. SECTION("char[n], NestingLimit, Filter") {
  1509. size_t i = 4;
  1510. char vla[i];
  1511. strcpy(vla, "{}");
  1512. deserializeMsgPack(doc, vla, NestingLimit(5), Filter(filter));
  1513. }
  1514. #endif
  1515. }