| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068 | 
							- //     __ _____ _____ _____
 
- //  __|  |   __|     |   | |  JSON for Modern C++
 
- // |  |  |__   |  |  | | | |  version 3.12.0
 
- // |_____|_____|_____|_|___|  https://github.com/nlohmann/json
 
- //
 
- // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann <https://nlohmann.me>
 
- // SPDX-License-Identifier: MIT
 
- #pragma once
 
- #include <algorithm> // generate_n
 
- #include <array> // array
 
- #include <cmath> // ldexp
 
- #include <cstddef> // size_t
 
- #include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
 
- #include <cstdio> // snprintf
 
- #include <cstring> // memcpy
 
- #include <iterator> // back_inserter
 
- #include <limits> // numeric_limits
 
- #include <string> // char_traits, string
 
- #include <utility> // make_pair, move
 
- #include <vector> // vector
 
- #ifdef __cpp_lib_byteswap
 
-     #include <bit>  //byteswap
 
- #endif
 
- #include <nlohmann/detail/exceptions.hpp>
 
- #include <nlohmann/detail/input/input_adapters.hpp>
 
- #include <nlohmann/detail/input/json_sax.hpp>
 
- #include <nlohmann/detail/input/lexer.hpp>
 
- #include <nlohmann/detail/macro_scope.hpp>
 
- #include <nlohmann/detail/meta/is_sax.hpp>
 
- #include <nlohmann/detail/meta/type_traits.hpp>
 
- #include <nlohmann/detail/string_concat.hpp>
 
- #include <nlohmann/detail/value_t.hpp>
 
- NLOHMANN_JSON_NAMESPACE_BEGIN
 
- namespace detail
 
- {
 
- /// how to treat CBOR tags
 
- enum class cbor_tag_handler_t
 
- {
 
-     error,   ///< throw a parse_error exception in case of a tag
 
-     ignore,  ///< ignore tags
 
-     store    ///< store tags as binary type
 
- };
 
- /*!
 
- @brief determine system byte order
 
- @return true if and only if system's byte order is little endian
 
- @note from https://stackoverflow.com/a/1001328/266378
 
- */
 
- static inline bool little_endianness(int num = 1) noexcept
 
- {
 
-     return *reinterpret_cast<char*>(&num) == 1;
 
- }
 
- ///////////////////
 
- // binary reader //
 
- ///////////////////
 
- /*!
 
- @brief deserialization of CBOR, MessagePack, and UBJSON values
 
- */
 
- template<typename BasicJsonType, typename InputAdapterType, typename SAX = json_sax_dom_parser<BasicJsonType, InputAdapterType>>
 
- class binary_reader
 
- {
 
-     using number_integer_t = typename BasicJsonType::number_integer_t;
 
-     using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
 
-     using number_float_t = typename BasicJsonType::number_float_t;
 
-     using string_t = typename BasicJsonType::string_t;
 
-     using binary_t = typename BasicJsonType::binary_t;
 
-     using json_sax_t = SAX;
 
-     using char_type = typename InputAdapterType::char_type;
 
-     using char_int_type = typename char_traits<char_type>::int_type;
 
-   public:
 
-     /*!
 
-     @brief create a binary reader
 
-     @param[in] adapter  input adapter to read from
 
-     */
 
-     explicit binary_reader(InputAdapterType&& adapter, const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format)
 
-     {
 
-         (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
 
-     }
 
-     // make class move-only
 
-     binary_reader(const binary_reader&) = delete;
 
-     binary_reader(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
 
-     binary_reader& operator=(const binary_reader&) = delete;
 
-     binary_reader& operator=(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor)
 
-     ~binary_reader() = default;
 
-     /*!
 
-     @param[in] format  the binary format to parse
 
-     @param[in] sax_    a SAX event processor
 
-     @param[in] strict  whether to expect the input to be consumed completed
 
-     @param[in] tag_handler  how to treat CBOR tags
 
-     @return whether parsing was successful
 
-     */
 
-     JSON_HEDLEY_NON_NULL(3)
 
-     bool sax_parse(const input_format_t format,
 
-                    json_sax_t* sax_,
 
-                    const bool strict = true,
 
-                    const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
 
-     {
 
-         sax = sax_;
 
-         bool result = false;
 
-         switch (format)
 
-         {
 
-             case input_format_t::bson:
 
-                 result = parse_bson_internal();
 
-                 break;
 
-             case input_format_t::cbor:
 
-                 result = parse_cbor_internal(true, tag_handler);
 
-                 break;
 
-             case input_format_t::msgpack:
 
-                 result = parse_msgpack_internal();
 
-                 break;
 
-             case input_format_t::ubjson:
 
-             case input_format_t::bjdata:
 
-                 result = parse_ubjson_internal();
 
-                 break;
 
-             case input_format_t::json: // LCOV_EXCL_LINE
 
-             default:            // LCOV_EXCL_LINE
 
-                 JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
 
-         }
 
-         // strict mode: next byte must be EOF
 
-         if (result && strict)
 
-         {
 
-             if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata)
 
-             {
 
-                 get_ignore_noop();
 
-             }
 
-             else
 
-             {
 
-                 get();
 
-             }
 
-             if (JSON_HEDLEY_UNLIKELY(current != char_traits<char_type>::eof()))
 
-             {
 
-                 return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read,
 
-                                         exception_message(input_format, concat("expected end of input; last byte: 0x", get_token_string()), "value"), nullptr));
 
-             }
 
-         }
 
-         return result;
 
-     }
 
-   private:
 
-     //////////
 
-     // BSON //
 
-     //////////
 
-     /*!
 
-     @brief Reads in a BSON-object and passes it to the SAX-parser.
 
-     @return whether a valid BSON-value was passed to the SAX parser
 
-     */
 
-     bool parse_bson_internal()
 
-     {
 
-         std::int32_t document_size{};
 
-         get_number<std::int32_t, true>(input_format_t::bson, document_size);
 
-         if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
 
-         {
 
-             return false;
 
-         }
 
-         if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/false)))
 
-         {
 
-             return false;
 
-         }
 
-         return sax->end_object();
 
-     }
 
-     /*!
 
-     @brief Parses a C-style string from the BSON input.
 
-     @param[in,out] result  A reference to the string variable where the read
 
-                             string is to be stored.
 
-     @return `true` if the \x00-byte indicating the end of the string was
 
-              encountered before the EOF; false` indicates an unexpected EOF.
 
-     */
 
-     bool get_bson_cstr(string_t& result)
 
-     {
 
-         auto out = std::back_inserter(result);
 
-         while (true)
 
-         {
 
-             get();
 
-             if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, "cstring")))
 
-             {
 
-                 return false;
 
-             }
 
-             if (current == 0x00)
 
-             {
 
-                 return true;
 
-             }
 
-             *out++ = static_cast<typename string_t::value_type>(current);
 
-         }
 
-     }
 
-     /*!
 
-     @brief Parses a zero-terminated string of length @a len from the BSON
 
-            input.
 
-     @param[in] len  The length (including the zero-byte at the end) of the
 
-                     string to be read.
 
-     @param[in,out] result  A reference to the string variable where the read
 
-                             string is to be stored.
 
-     @tparam NumberType The type of the length @a len
 
-     @pre len >= 1
 
-     @return `true` if the string was successfully parsed
 
-     */
 
-     template<typename NumberType>
 
-     bool get_bson_string(const NumberType len, string_t& result)
 
-     {
 
-         if (JSON_HEDLEY_UNLIKELY(len < 1))
 
-         {
 
-             auto last_token = get_token_string();
 
-             return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
 
-                                     exception_message(input_format_t::bson, concat("string length must be at least 1, is ", std::to_string(len)), "string"), nullptr));
 
-         }
 
-         return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) && get() != char_traits<char_type>::eof();
 
-     }
 
-     /*!
 
-     @brief Parses a byte array input of length @a len from the BSON input.
 
-     @param[in] len  The length of the byte array to be read.
 
-     @param[in,out] result  A reference to the binary variable where the read
 
-                             array is to be stored.
 
-     @tparam NumberType The type of the length @a len
 
-     @pre len >= 0
 
-     @return `true` if the byte array was successfully parsed
 
-     */
 
-     template<typename NumberType>
 
-     bool get_bson_binary(const NumberType len, binary_t& result)
 
-     {
 
-         if (JSON_HEDLEY_UNLIKELY(len < 0))
 
-         {
 
-             auto last_token = get_token_string();
 
-             return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
 
-                                     exception_message(input_format_t::bson, concat("byte array length cannot be negative, is ", std::to_string(len)), "binary"), nullptr));
 
-         }
 
-         // All BSON binary values have a subtype
 
-         std::uint8_t subtype{};
 
-         get_number<std::uint8_t>(input_format_t::bson, subtype);
 
-         result.set_subtype(subtype);
 
-         return get_binary(input_format_t::bson, len, result);
 
-     }
 
-     /*!
 
-     @brief Read a BSON document element of the given @a element_type.
 
-     @param[in] element_type The BSON element type, c.f. http://bsonspec.org/spec.html
 
-     @param[in] element_type_parse_position The position in the input stream,
 
-                where the `element_type` was read.
 
-     @warning Not all BSON element types are supported yet. An unsupported
 
-              @a element_type will give rise to a parse_error.114:
 
-              Unsupported BSON record type 0x...
 
-     @return whether a valid BSON-object/array was passed to the SAX parser
 
-     */
 
-     bool parse_bson_element_internal(const char_int_type element_type,
 
-                                      const std::size_t element_type_parse_position)
 
-     {
 
-         switch (element_type)
 
-         {
 
-             case 0x01: // double
 
-             {
 
-                 double number{};
 
-                 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(static_cast<number_float_t>(number), "");
 
-             }
 
-             case 0x02: // string
 
-             {
 
-                 std::int32_t len{};
 
-                 string_t value;
 
-                 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
 
-             }
 
-             case 0x03: // object
 
-             {
 
-                 return parse_bson_internal();
 
-             }
 
-             case 0x04: // array
 
-             {
 
-                 return parse_bson_array();
 
-             }
 
-             case 0x05: // binary
 
-             {
 
-                 std::int32_t len{};
 
-                 binary_t value;
 
-                 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
 
-             }
 
-             case 0x08: // boolean
 
-             {
 
-                 return sax->boolean(get() != 0);
 
-             }
 
-             case 0x0A: // null
 
-             {
 
-                 return sax->null();
 
-             }
 
-             case 0x10: // int32
 
-             {
 
-                 std::int32_t value{};
 
-                 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
 
-             }
 
-             case 0x12: // int64
 
-             {
 
-                 std::int64_t value{};
 
-                 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
 
-             }
 
-             case 0x11: // uint64
 
-             {
 
-                 std::uint64_t value{};
 
-                 return get_number<std::uint64_t, true>(input_format_t::bson, value) && sax->number_unsigned(value);
 
-             }
 
-             default: // anything else not supported (yet)
 
-             {
 
-                 std::array<char, 3> cr{{}};
 
-                 static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
 
-                 const std::string cr_str{cr.data()};
 
-                 return sax->parse_error(element_type_parse_position, cr_str,
 
-                                         parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr));
 
-             }
 
-         }
 
-     }
 
-     /*!
 
-     @brief Read a BSON element list (as specified in the BSON-spec)
 
-     The same binary layout is used for objects and arrays, hence it must be
 
-     indicated with the argument @a is_array which one is expected
 
-     (true --> array, false --> object).
 
-     @param[in] is_array Determines if the element list being read is to be
 
-                         treated as an object (@a is_array == false), or as an
 
-                         array (@a is_array == true).
 
-     @return whether a valid BSON-object/array was passed to the SAX parser
 
-     */
 
-     bool parse_bson_element_list(const bool is_array)
 
-     {
 
-         string_t key;
 
-         while (auto element_type = get())
 
-         {
 
-             if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, "element list")))
 
-             {
 
-                 return false;
 
-             }
 
-             const std::size_t element_type_parse_position = chars_read;
 
-             if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
 
-             {
 
-                 return false;
 
-             }
 
-             if (!is_array && !sax->key(key))
 
-             {
 
-                 return false;
 
-             }
 
-             if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
 
-             {
 
-                 return false;
 
-             }
 
-             // get_bson_cstr only appends
 
-             key.clear();
 
-         }
 
-         return true;
 
-     }
 
-     /*!
 
-     @brief Reads an array from the BSON input and passes it to the SAX-parser.
 
-     @return whether a valid BSON-array was passed to the SAX parser
 
-     */
 
-     bool parse_bson_array()
 
-     {
 
-         std::int32_t document_size{};
 
-         get_number<std::int32_t, true>(input_format_t::bson, document_size);
 
-         if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
 
-         {
 
-             return false;
 
-         }
 
-         if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/true)))
 
-         {
 
-             return false;
 
-         }
 
-         return sax->end_array();
 
-     }
 
-     //////////
 
-     // CBOR //
 
-     //////////
 
-     /*!
 
-     @param[in] get_char  whether a new character should be retrieved from the
 
-                          input (true) or whether the last read character should
 
-                          be considered instead (false)
 
-     @param[in] tag_handler how CBOR tags should be treated
 
-     @return whether a valid CBOR value was passed to the SAX parser
 
-     */
 
-     bool parse_cbor_internal(const bool get_char,
 
-                              const cbor_tag_handler_t tag_handler)
 
-     {
 
-         switch (get_char ? get() : current)
 
-         {
 
-             // EOF
 
-             case char_traits<char_type>::eof():
 
-                 return unexpect_eof(input_format_t::cbor, "value");
 
-             // Integer 0x00..0x17 (0..23)
 
-             case 0x00:
 
-             case 0x01:
 
-             case 0x02:
 
-             case 0x03:
 
-             case 0x04:
 
-             case 0x05:
 
-             case 0x06:
 
-             case 0x07:
 
-             case 0x08:
 
-             case 0x09:
 
-             case 0x0A:
 
-             case 0x0B:
 
-             case 0x0C:
 
-             case 0x0D:
 
-             case 0x0E:
 
-             case 0x0F:
 
-             case 0x10:
 
-             case 0x11:
 
-             case 0x12:
 
-             case 0x13:
 
-             case 0x14:
 
-             case 0x15:
 
-             case 0x16:
 
-             case 0x17:
 
-                 return sax->number_unsigned(static_cast<number_unsigned_t>(current));
 
-             case 0x18: // Unsigned integer (one-byte uint8_t follows)
 
-             {
 
-                 std::uint8_t number{};
 
-                 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
 
-             }
 
-             case 0x19: // Unsigned integer (two-byte uint16_t follows)
 
-             {
 
-                 std::uint16_t number{};
 
-                 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
 
-             }
 
-             case 0x1A: // Unsigned integer (four-byte uint32_t follows)
 
-             {
 
-                 std::uint32_t number{};
 
-                 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
 
-             }
 
-             case 0x1B: // Unsigned integer (eight-byte uint64_t follows)
 
-             {
 
-                 std::uint64_t number{};
 
-                 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
 
-             }
 
-             // Negative integer -1-0x00..-1-0x17 (-1..-24)
 
-             case 0x20:
 
-             case 0x21:
 
-             case 0x22:
 
-             case 0x23:
 
-             case 0x24:
 
-             case 0x25:
 
-             case 0x26:
 
-             case 0x27:
 
-             case 0x28:
 
-             case 0x29:
 
-             case 0x2A:
 
-             case 0x2B:
 
-             case 0x2C:
 
-             case 0x2D:
 
-             case 0x2E:
 
-             case 0x2F:
 
-             case 0x30:
 
-             case 0x31:
 
-             case 0x32:
 
-             case 0x33:
 
-             case 0x34:
 
-             case 0x35:
 
-             case 0x36:
 
-             case 0x37:
 
-                 return sax->number_integer(static_cast<std::int8_t>(0x20 - 1 - current));
 
-             case 0x38: // Negative integer (one-byte uint8_t follows)
 
-             {
 
-                 std::uint8_t number{};
 
-                 return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);
 
-             }
 
-             case 0x39: // Negative integer -1-n (two-byte uint16_t follows)
 
-             {
 
-                 std::uint16_t number{};
 
-                 return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);
 
-             }
 
-             case 0x3A: // Negative integer -1-n (four-byte uint32_t follows)
 
-             {
 
-                 std::uint32_t number{};
 
-                 return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);
 
-             }
 
-             case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows)
 
-             {
 
-                 std::uint64_t number{};
 
-                 return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1)
 
-                         - static_cast<number_integer_t>(number));
 
-             }
 
-             // Binary data (0x00..0x17 bytes follow)
 
-             case 0x40:
 
-             case 0x41:
 
-             case 0x42:
 
-             case 0x43:
 
-             case 0x44:
 
-             case 0x45:
 
-             case 0x46:
 
-             case 0x47:
 
-             case 0x48:
 
-             case 0x49:
 
-             case 0x4A:
 
-             case 0x4B:
 
-             case 0x4C:
 
-             case 0x4D:
 
-             case 0x4E:
 
-             case 0x4F:
 
-             case 0x50:
 
-             case 0x51:
 
-             case 0x52:
 
-             case 0x53:
 
-             case 0x54:
 
-             case 0x55:
 
-             case 0x56:
 
-             case 0x57:
 
-             case 0x58: // Binary data (one-byte uint8_t for n follows)
 
-             case 0x59: // Binary data (two-byte uint16_t for n follow)
 
-             case 0x5A: // Binary data (four-byte uint32_t for n follow)
 
-             case 0x5B: // Binary data (eight-byte uint64_t for n follow)
 
-             case 0x5F: // Binary data (indefinite length)
 
-             {
 
-                 binary_t b;
 
-                 return get_cbor_binary(b) && sax->binary(b);
 
-             }
 
-             // UTF-8 string (0x00..0x17 bytes follow)
 
-             case 0x60:
 
-             case 0x61:
 
-             case 0x62:
 
-             case 0x63:
 
-             case 0x64:
 
-             case 0x65:
 
-             case 0x66:
 
-             case 0x67:
 
-             case 0x68:
 
-             case 0x69:
 
-             case 0x6A:
 
-             case 0x6B:
 
-             case 0x6C:
 
-             case 0x6D:
 
-             case 0x6E:
 
-             case 0x6F:
 
-             case 0x70:
 
-             case 0x71:
 
-             case 0x72:
 
-             case 0x73:
 
-             case 0x74:
 
-             case 0x75:
 
-             case 0x76:
 
-             case 0x77:
 
-             case 0x78: // UTF-8 string (one-byte uint8_t for n follows)
 
-             case 0x79: // UTF-8 string (two-byte uint16_t for n follow)
 
-             case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)
 
-             case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)
 
-             case 0x7F: // UTF-8 string (indefinite length)
 
-             {
 
-                 string_t s;
 
-                 return get_cbor_string(s) && sax->string(s);
 
-             }
 
-             // array (0x00..0x17 data items follow)
 
-             case 0x80:
 
-             case 0x81:
 
-             case 0x82:
 
-             case 0x83:
 
-             case 0x84:
 
-             case 0x85:
 
-             case 0x86:
 
-             case 0x87:
 
-             case 0x88:
 
-             case 0x89:
 
-             case 0x8A:
 
-             case 0x8B:
 
-             case 0x8C:
 
-             case 0x8D:
 
-             case 0x8E:
 
-             case 0x8F:
 
-             case 0x90:
 
-             case 0x91:
 
-             case 0x92:
 
-             case 0x93:
 
-             case 0x94:
 
-             case 0x95:
 
-             case 0x96:
 
-             case 0x97:
 
-                 return get_cbor_array(
 
-                            conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
 
-             case 0x98: // array (one-byte uint8_t for n follows)
 
-             {
 
-                 std::uint8_t len{};
 
-                 return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
 
-             }
 
-             case 0x99: // array (two-byte uint16_t for n follow)
 
-             {
 
-                 std::uint16_t len{};
 
-                 return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
 
-             }
 
-             case 0x9A: // array (four-byte uint32_t for n follow)
 
-             {
 
-                 std::uint32_t len{};
 
-                 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
 
-             }
 
-             case 0x9B: // array (eight-byte uint64_t for n follow)
 
-             {
 
-                 std::uint64_t len{};
 
-                 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
 
-             }
 
-             case 0x9F: // array (indefinite length)
 
-                 return get_cbor_array(detail::unknown_size(), tag_handler);
 
-             // map (0x00..0x17 pairs of data items follow)
 
-             case 0xA0:
 
-             case 0xA1:
 
-             case 0xA2:
 
-             case 0xA3:
 
-             case 0xA4:
 
-             case 0xA5:
 
-             case 0xA6:
 
-             case 0xA7:
 
-             case 0xA8:
 
-             case 0xA9:
 
-             case 0xAA:
 
-             case 0xAB:
 
-             case 0xAC:
 
-             case 0xAD:
 
-             case 0xAE:
 
-             case 0xAF:
 
-             case 0xB0:
 
-             case 0xB1:
 
-             case 0xB2:
 
-             case 0xB3:
 
-             case 0xB4:
 
-             case 0xB5:
 
-             case 0xB6:
 
-             case 0xB7:
 
-                 return get_cbor_object(conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
 
-             case 0xB8: // map (one-byte uint8_t for n follows)
 
-             {
 
-                 std::uint8_t len{};
 
-                 return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
 
-             }
 
-             case 0xB9: // map (two-byte uint16_t for n follow)
 
-             {
 
-                 std::uint16_t len{};
 
-                 return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
 
-             }
 
-             case 0xBA: // map (four-byte uint32_t for n follow)
 
-             {
 
-                 std::uint32_t len{};
 
-                 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
 
-             }
 
-             case 0xBB: // map (eight-byte uint64_t for n follow)
 
-             {
 
-                 std::uint64_t len{};
 
-                 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
 
-             }
 
-             case 0xBF: // map (indefinite length)
 
-                 return get_cbor_object(detail::unknown_size(), tag_handler);
 
-             case 0xC6: // tagged item
 
-             case 0xC7:
 
-             case 0xC8:
 
-             case 0xC9:
 
-             case 0xCA:
 
-             case 0xCB:
 
-             case 0xCC:
 
-             case 0xCD:
 
-             case 0xCE:
 
-             case 0xCF:
 
-             case 0xD0:
 
-             case 0xD1:
 
-             case 0xD2:
 
-             case 0xD3:
 
-             case 0xD4:
 
-             case 0xD8: // tagged item (1 bytes follow)
 
-             case 0xD9: // tagged item (2 bytes follow)
 
-             case 0xDA: // tagged item (4 bytes follow)
 
-             case 0xDB: // tagged item (8 bytes follow)
 
-             {
 
-                 switch (tag_handler)
 
-                 {
 
-                     case cbor_tag_handler_t::error:
 
-                     {
 
-                         auto last_token = get_token_string();
 
-                         return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
 
-                                                 exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr));
 
-                     }
 
-                     case cbor_tag_handler_t::ignore:
 
-                     {
 
-                         // ignore binary subtype
 
-                         switch (current)
 
-                         {
 
-                             case 0xD8:
 
-                             {
 
-                                 std::uint8_t subtype_to_ignore{};
 
-                                 get_number(input_format_t::cbor, subtype_to_ignore);
 
-                                 break;
 
-                             }
 
-                             case 0xD9:
 
-                             {
 
-                                 std::uint16_t subtype_to_ignore{};
 
-                                 get_number(input_format_t::cbor, subtype_to_ignore);
 
-                                 break;
 
-                             }
 
-                             case 0xDA:
 
-                             {
 
-                                 std::uint32_t subtype_to_ignore{};
 
-                                 get_number(input_format_t::cbor, subtype_to_ignore);
 
-                                 break;
 
-                             }
 
-                             case 0xDB:
 
-                             {
 
-                                 std::uint64_t subtype_to_ignore{};
 
-                                 get_number(input_format_t::cbor, subtype_to_ignore);
 
-                                 break;
 
-                             }
 
-                             default:
 
-                                 break;
 
-                         }
 
-                         return parse_cbor_internal(true, tag_handler);
 
-                     }
 
-                     case cbor_tag_handler_t::store:
 
-                     {
 
-                         binary_t b;
 
-                         // use binary subtype and store in binary container
 
-                         switch (current)
 
-                         {
 
-                             case 0xD8:
 
-                             {
 
-                                 std::uint8_t subtype{};
 
-                                 get_number(input_format_t::cbor, subtype);
 
-                                 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
 
-                                 break;
 
-                             }
 
-                             case 0xD9:
 
-                             {
 
-                                 std::uint16_t subtype{};
 
-                                 get_number(input_format_t::cbor, subtype);
 
-                                 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
 
-                                 break;
 
-                             }
 
-                             case 0xDA:
 
-                             {
 
-                                 std::uint32_t subtype{};
 
-                                 get_number(input_format_t::cbor, subtype);
 
-                                 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
 
-                                 break;
 
-                             }
 
-                             case 0xDB:
 
-                             {
 
-                                 std::uint64_t subtype{};
 
-                                 get_number(input_format_t::cbor, subtype);
 
-                                 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
 
-                                 break;
 
-                             }
 
-                             default:
 
-                                 return parse_cbor_internal(true, tag_handler);
 
-                         }
 
-                         get();
 
-                         return get_cbor_binary(b) && sax->binary(b);
 
-                     }
 
-                     default:                 // LCOV_EXCL_LINE
 
-                         JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
 
-                         return false;        // LCOV_EXCL_LINE
 
-                 }
 
-             }
 
-             case 0xF4: // false
 
-                 return sax->boolean(false);
 
-             case 0xF5: // true
 
-                 return sax->boolean(true);
 
-             case 0xF6: // null
 
-                 return sax->null();
 
-             case 0xF9: // Half-Precision Float (two-byte IEEE 754)
 
-             {
 
-                 const auto byte1_raw = get();
 
-                 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "number")))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 const auto byte2_raw = get();
 
-                 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "number")))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 const auto byte1 = static_cast<unsigned char>(byte1_raw);
 
-                 const auto byte2 = static_cast<unsigned char>(byte2_raw);
 
-                 // code from RFC 7049, Appendix D, Figure 3:
 
-                 // As half-precision floating-point numbers were only added
 
-                 // to IEEE 754 in 2008, today's programming platforms often
 
-                 // still only have limited support for them. It is very
 
-                 // easy to include at least decoding support for them even
 
-                 // without such support. An example of a small decoder for
 
-                 // half-precision floating-point numbers in the C language
 
-                 // is shown in Fig. 3.
 
-                 const auto half = static_cast<unsigned int>((byte1 << 8u) + byte2);
 
-                 const double val = [&half]
 
-                 {
 
-                     const int exp = (half >> 10u) & 0x1Fu;
 
-                     const unsigned int mant = half & 0x3FFu;
 
-                     JSON_ASSERT(0 <= exp&& exp <= 32);
 
-                     JSON_ASSERT(mant <= 1024);
 
-                     switch (exp)
 
-                     {
 
-                         case 0:
 
-                             return std::ldexp(mant, -24);
 
-                         case 31:
 
-                             return (mant == 0)
 
-                             ? std::numeric_limits<double>::infinity()
 
-                             : std::numeric_limits<double>::quiet_NaN();
 
-                         default:
 
-                             return std::ldexp(mant + 1024, exp - 25);
 
-                     }
 
-                 }();
 
-                 return sax->number_float((half & 0x8000u) != 0
 
-                                          ? static_cast<number_float_t>(-val)
 
-                                          : static_cast<number_float_t>(val), "");
 
-             }
 
-             case 0xFA: // Single-Precision Float (four-byte IEEE 754)
 
-             {
 
-                 float number{};
 
-                 return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), "");
 
-             }
 
-             case 0xFB: // Double-Precision Float (eight-byte IEEE 754)
 
-             {
 
-                 double number{};
 
-                 return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), "");
 
-             }
 
-             default: // anything else (0xFF is handled inside the other types)
 
-             {
 
-                 auto last_token = get_token_string();
 
-                 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
 
-                                         exception_message(input_format_t::cbor, concat("invalid byte: 0x", last_token), "value"), nullptr));
 
-             }
 
-         }
 
-     }
 
-     /*!
 
-     @brief reads a CBOR string
 
-     This function first reads starting bytes to determine the expected
 
-     string length and then copies this number of bytes into a string.
 
-     Additionally, CBOR's strings with indefinite lengths are supported.
 
-     @param[out] result  created string
 
-     @return whether string creation completed
 
-     */
 
-     bool get_cbor_string(string_t& result)
 
-     {
 
-         if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "string")))
 
-         {
 
-             return false;
 
-         }
 
-         switch (current)
 
-         {
 
-             // UTF-8 string (0x00..0x17 bytes follow)
 
-             case 0x60:
 
-             case 0x61:
 
-             case 0x62:
 
-             case 0x63:
 
-             case 0x64:
 
-             case 0x65:
 
-             case 0x66:
 
-             case 0x67:
 
-             case 0x68:
 
-             case 0x69:
 
-             case 0x6A:
 
-             case 0x6B:
 
-             case 0x6C:
 
-             case 0x6D:
 
-             case 0x6E:
 
-             case 0x6F:
 
-             case 0x70:
 
-             case 0x71:
 
-             case 0x72:
 
-             case 0x73:
 
-             case 0x74:
 
-             case 0x75:
 
-             case 0x76:
 
-             case 0x77:
 
-             {
 
-                 return get_string(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result);
 
-             }
 
-             case 0x78: // UTF-8 string (one-byte uint8_t for n follows)
 
-             {
 
-                 std::uint8_t len{};
 
-                 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
 
-             }
 
-             case 0x79: // UTF-8 string (two-byte uint16_t for n follow)
 
-             {
 
-                 std::uint16_t len{};
 
-                 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
 
-             }
 
-             case 0x7A: // UTF-8 string (four-byte uint32_t for n follow)
 
-             {
 
-                 std::uint32_t len{};
 
-                 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
 
-             }
 
-             case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow)
 
-             {
 
-                 std::uint64_t len{};
 
-                 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
 
-             }
 
-             case 0x7F: // UTF-8 string (indefinite length)
 
-             {
 
-                 while (get() != 0xFF)
 
-                 {
 
-                     string_t chunk;
 
-                     if (!get_cbor_string(chunk))
 
-                     {
 
-                         return false;
 
-                     }
 
-                     result.append(chunk);
 
-                 }
 
-                 return true;
 
-             }
 
-             default:
 
-             {
 
-                 auto last_token = get_token_string();
 
-                 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
 
-                                         exception_message(input_format_t::cbor, concat("expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token), "string"), nullptr));
 
-             }
 
-         }
 
-     }
 
-     /*!
 
-     @brief reads a CBOR byte array
 
-     This function first reads starting bytes to determine the expected
 
-     byte array length and then copies this number of bytes into the byte array.
 
-     Additionally, CBOR's byte arrays with indefinite lengths are supported.
 
-     @param[out] result  created byte array
 
-     @return whether byte array creation completed
 
-     */
 
-     bool get_cbor_binary(binary_t& result)
 
-     {
 
-         if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "binary")))
 
-         {
 
-             return false;
 
-         }
 
-         switch (current)
 
-         {
 
-             // Binary data (0x00..0x17 bytes follow)
 
-             case 0x40:
 
-             case 0x41:
 
-             case 0x42:
 
-             case 0x43:
 
-             case 0x44:
 
-             case 0x45:
 
-             case 0x46:
 
-             case 0x47:
 
-             case 0x48:
 
-             case 0x49:
 
-             case 0x4A:
 
-             case 0x4B:
 
-             case 0x4C:
 
-             case 0x4D:
 
-             case 0x4E:
 
-             case 0x4F:
 
-             case 0x50:
 
-             case 0x51:
 
-             case 0x52:
 
-             case 0x53:
 
-             case 0x54:
 
-             case 0x55:
 
-             case 0x56:
 
-             case 0x57:
 
-             {
 
-                 return get_binary(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result);
 
-             }
 
-             case 0x58: // Binary data (one-byte uint8_t for n follows)
 
-             {
 
-                 std::uint8_t len{};
 
-                 return get_number(input_format_t::cbor, len) &&
 
-                        get_binary(input_format_t::cbor, len, result);
 
-             }
 
-             case 0x59: // Binary data (two-byte uint16_t for n follow)
 
-             {
 
-                 std::uint16_t len{};
 
-                 return get_number(input_format_t::cbor, len) &&
 
-                        get_binary(input_format_t::cbor, len, result);
 
-             }
 
-             case 0x5A: // Binary data (four-byte uint32_t for n follow)
 
-             {
 
-                 std::uint32_t len{};
 
-                 return get_number(input_format_t::cbor, len) &&
 
-                        get_binary(input_format_t::cbor, len, result);
 
-             }
 
-             case 0x5B: // Binary data (eight-byte uint64_t for n follow)
 
-             {
 
-                 std::uint64_t len{};
 
-                 return get_number(input_format_t::cbor, len) &&
 
-                        get_binary(input_format_t::cbor, len, result);
 
-             }
 
-             case 0x5F: // Binary data (indefinite length)
 
-             {
 
-                 while (get() != 0xFF)
 
-                 {
 
-                     binary_t chunk;
 
-                     if (!get_cbor_binary(chunk))
 
-                     {
 
-                         return false;
 
-                     }
 
-                     result.insert(result.end(), chunk.begin(), chunk.end());
 
-                 }
 
-                 return true;
 
-             }
 
-             default:
 
-             {
 
-                 auto last_token = get_token_string();
 
-                 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
 
-                                         exception_message(input_format_t::cbor, concat("expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x", last_token), "binary"), nullptr));
 
-             }
 
-         }
 
-     }
 
-     /*!
 
-     @param[in] len  the length of the array or detail::unknown_size() for an
 
-                     array of indefinite size
 
-     @param[in] tag_handler how CBOR tags should be treated
 
-     @return whether array creation completed
 
-     */
 
-     bool get_cbor_array(const std::size_t len,
 
-                         const cbor_tag_handler_t tag_handler)
 
-     {
 
-         if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
 
-         {
 
-             return false;
 
-         }
 
-         if (len != detail::unknown_size())
 
-         {
 
-             for (std::size_t i = 0; i < len; ++i)
 
-             {
 
-                 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
 
-                 {
 
-                     return false;
 
-                 }
 
-             }
 
-         }
 
-         else
 
-         {
 
-             while (get() != 0xFF)
 
-             {
 
-                 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(false, tag_handler)))
 
-                 {
 
-                     return false;
 
-                 }
 
-             }
 
-         }
 
-         return sax->end_array();
 
-     }
 
-     /*!
 
-     @param[in] len  the length of the object or detail::unknown_size() for an
 
-                     object of indefinite size
 
-     @param[in] tag_handler how CBOR tags should be treated
 
-     @return whether object creation completed
 
-     */
 
-     bool get_cbor_object(const std::size_t len,
 
-                          const cbor_tag_handler_t tag_handler)
 
-     {
 
-         if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
 
-         {
 
-             return false;
 
-         }
 
-         if (len != 0)
 
-         {
 
-             string_t key;
 
-             if (len != detail::unknown_size())
 
-             {
 
-                 for (std::size_t i = 0; i < len; ++i)
 
-                 {
 
-                     get();
 
-                     if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
 
-                     {
 
-                         return false;
 
-                     }
 
-                     if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
 
-                     {
 
-                         return false;
 
-                     }
 
-                     key.clear();
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 while (get() != 0xFF)
 
-                 {
 
-                     if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
 
-                     {
 
-                         return false;
 
-                     }
 
-                     if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
 
-                     {
 
-                         return false;
 
-                     }
 
-                     key.clear();
 
-                 }
 
-             }
 
-         }
 
-         return sax->end_object();
 
-     }
 
-     /////////////
 
-     // MsgPack //
 
-     /////////////
 
-     /*!
 
-     @return whether a valid MessagePack value was passed to the SAX parser
 
-     */
 
-     bool parse_msgpack_internal()
 
-     {
 
-         switch (get())
 
-         {
 
-             // EOF
 
-             case char_traits<char_type>::eof():
 
-                 return unexpect_eof(input_format_t::msgpack, "value");
 
-             // positive fixint
 
-             case 0x00:
 
-             case 0x01:
 
-             case 0x02:
 
-             case 0x03:
 
-             case 0x04:
 
-             case 0x05:
 
-             case 0x06:
 
-             case 0x07:
 
-             case 0x08:
 
-             case 0x09:
 
-             case 0x0A:
 
-             case 0x0B:
 
-             case 0x0C:
 
-             case 0x0D:
 
-             case 0x0E:
 
-             case 0x0F:
 
-             case 0x10:
 
-             case 0x11:
 
-             case 0x12:
 
-             case 0x13:
 
-             case 0x14:
 
-             case 0x15:
 
-             case 0x16:
 
-             case 0x17:
 
-             case 0x18:
 
-             case 0x19:
 
-             case 0x1A:
 
-             case 0x1B:
 
-             case 0x1C:
 
-             case 0x1D:
 
-             case 0x1E:
 
-             case 0x1F:
 
-             case 0x20:
 
-             case 0x21:
 
-             case 0x22:
 
-             case 0x23:
 
-             case 0x24:
 
-             case 0x25:
 
-             case 0x26:
 
-             case 0x27:
 
-             case 0x28:
 
-             case 0x29:
 
-             case 0x2A:
 
-             case 0x2B:
 
-             case 0x2C:
 
-             case 0x2D:
 
-             case 0x2E:
 
-             case 0x2F:
 
-             case 0x30:
 
-             case 0x31:
 
-             case 0x32:
 
-             case 0x33:
 
-             case 0x34:
 
-             case 0x35:
 
-             case 0x36:
 
-             case 0x37:
 
-             case 0x38:
 
-             case 0x39:
 
-             case 0x3A:
 
-             case 0x3B:
 
-             case 0x3C:
 
-             case 0x3D:
 
-             case 0x3E:
 
-             case 0x3F:
 
-             case 0x40:
 
-             case 0x41:
 
-             case 0x42:
 
-             case 0x43:
 
-             case 0x44:
 
-             case 0x45:
 
-             case 0x46:
 
-             case 0x47:
 
-             case 0x48:
 
-             case 0x49:
 
-             case 0x4A:
 
-             case 0x4B:
 
-             case 0x4C:
 
-             case 0x4D:
 
-             case 0x4E:
 
-             case 0x4F:
 
-             case 0x50:
 
-             case 0x51:
 
-             case 0x52:
 
-             case 0x53:
 
-             case 0x54:
 
-             case 0x55:
 
-             case 0x56:
 
-             case 0x57:
 
-             case 0x58:
 
-             case 0x59:
 
-             case 0x5A:
 
-             case 0x5B:
 
-             case 0x5C:
 
-             case 0x5D:
 
-             case 0x5E:
 
-             case 0x5F:
 
-             case 0x60:
 
-             case 0x61:
 
-             case 0x62:
 
-             case 0x63:
 
-             case 0x64:
 
-             case 0x65:
 
-             case 0x66:
 
-             case 0x67:
 
-             case 0x68:
 
-             case 0x69:
 
-             case 0x6A:
 
-             case 0x6B:
 
-             case 0x6C:
 
-             case 0x6D:
 
-             case 0x6E:
 
-             case 0x6F:
 
-             case 0x70:
 
-             case 0x71:
 
-             case 0x72:
 
-             case 0x73:
 
-             case 0x74:
 
-             case 0x75:
 
-             case 0x76:
 
-             case 0x77:
 
-             case 0x78:
 
-             case 0x79:
 
-             case 0x7A:
 
-             case 0x7B:
 
-             case 0x7C:
 
-             case 0x7D:
 
-             case 0x7E:
 
-             case 0x7F:
 
-                 return sax->number_unsigned(static_cast<number_unsigned_t>(current));
 
-             // fixmap
 
-             case 0x80:
 
-             case 0x81:
 
-             case 0x82:
 
-             case 0x83:
 
-             case 0x84:
 
-             case 0x85:
 
-             case 0x86:
 
-             case 0x87:
 
-             case 0x88:
 
-             case 0x89:
 
-             case 0x8A:
 
-             case 0x8B:
 
-             case 0x8C:
 
-             case 0x8D:
 
-             case 0x8E:
 
-             case 0x8F:
 
-                 return get_msgpack_object(conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu));
 
-             // fixarray
 
-             case 0x90:
 
-             case 0x91:
 
-             case 0x92:
 
-             case 0x93:
 
-             case 0x94:
 
-             case 0x95:
 
-             case 0x96:
 
-             case 0x97:
 
-             case 0x98:
 
-             case 0x99:
 
-             case 0x9A:
 
-             case 0x9B:
 
-             case 0x9C:
 
-             case 0x9D:
 
-             case 0x9E:
 
-             case 0x9F:
 
-                 return get_msgpack_array(conditional_static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu));
 
-             // fixstr
 
-             case 0xA0:
 
-             case 0xA1:
 
-             case 0xA2:
 
-             case 0xA3:
 
-             case 0xA4:
 
-             case 0xA5:
 
-             case 0xA6:
 
-             case 0xA7:
 
-             case 0xA8:
 
-             case 0xA9:
 
-             case 0xAA:
 
-             case 0xAB:
 
-             case 0xAC:
 
-             case 0xAD:
 
-             case 0xAE:
 
-             case 0xAF:
 
-             case 0xB0:
 
-             case 0xB1:
 
-             case 0xB2:
 
-             case 0xB3:
 
-             case 0xB4:
 
-             case 0xB5:
 
-             case 0xB6:
 
-             case 0xB7:
 
-             case 0xB8:
 
-             case 0xB9:
 
-             case 0xBA:
 
-             case 0xBB:
 
-             case 0xBC:
 
-             case 0xBD:
 
-             case 0xBE:
 
-             case 0xBF:
 
-             case 0xD9: // str 8
 
-             case 0xDA: // str 16
 
-             case 0xDB: // str 32
 
-             {
 
-                 string_t s;
 
-                 return get_msgpack_string(s) && sax->string(s);
 
-             }
 
-             case 0xC0: // nil
 
-                 return sax->null();
 
-             case 0xC2: // false
 
-                 return sax->boolean(false);
 
-             case 0xC3: // true
 
-                 return sax->boolean(true);
 
-             case 0xC4: // bin 8
 
-             case 0xC5: // bin 16
 
-             case 0xC6: // bin 32
 
-             case 0xC7: // ext 8
 
-             case 0xC8: // ext 16
 
-             case 0xC9: // ext 32
 
-             case 0xD4: // fixext 1
 
-             case 0xD5: // fixext 2
 
-             case 0xD6: // fixext 4
 
-             case 0xD7: // fixext 8
 
-             case 0xD8: // fixext 16
 
-             {
 
-                 binary_t b;
 
-                 return get_msgpack_binary(b) && sax->binary(b);
 
-             }
 
-             case 0xCA: // float 32
 
-             {
 
-                 float number{};
 
-                 return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), "");
 
-             }
 
-             case 0xCB: // float 64
 
-             {
 
-                 double number{};
 
-                 return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), "");
 
-             }
 
-             case 0xCC: // uint 8
 
-             {
 
-                 std::uint8_t number{};
 
-                 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
 
-             }
 
-             case 0xCD: // uint 16
 
-             {
 
-                 std::uint16_t number{};
 
-                 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
 
-             }
 
-             case 0xCE: // uint 32
 
-             {
 
-                 std::uint32_t number{};
 
-                 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
 
-             }
 
-             case 0xCF: // uint 64
 
-             {
 
-                 std::uint64_t number{};
 
-                 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
 
-             }
 
-             case 0xD0: // int 8
 
-             {
 
-                 std::int8_t number{};
 
-                 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
 
-             }
 
-             case 0xD1: // int 16
 
-             {
 
-                 std::int16_t number{};
 
-                 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
 
-             }
 
-             case 0xD2: // int 32
 
-             {
 
-                 std::int32_t number{};
 
-                 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
 
-             }
 
-             case 0xD3: // int 64
 
-             {
 
-                 std::int64_t number{};
 
-                 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
 
-             }
 
-             case 0xDC: // array 16
 
-             {
 
-                 std::uint16_t len{};
 
-                 return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast<std::size_t>(len));
 
-             }
 
-             case 0xDD: // array 32
 
-             {
 
-                 std::uint32_t len{};
 
-                 return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len));
 
-             }
 
-             case 0xDE: // map 16
 
-             {
 
-                 std::uint16_t len{};
 
-                 return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast<std::size_t>(len));
 
-             }
 
-             case 0xDF: // map 32
 
-             {
 
-                 std::uint32_t len{};
 
-                 return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len));
 
-             }
 
-             // negative fixint
 
-             case 0xE0:
 
-             case 0xE1:
 
-             case 0xE2:
 
-             case 0xE3:
 
-             case 0xE4:
 
-             case 0xE5:
 
-             case 0xE6:
 
-             case 0xE7:
 
-             case 0xE8:
 
-             case 0xE9:
 
-             case 0xEA:
 
-             case 0xEB:
 
-             case 0xEC:
 
-             case 0xED:
 
-             case 0xEE:
 
-             case 0xEF:
 
-             case 0xF0:
 
-             case 0xF1:
 
-             case 0xF2:
 
-             case 0xF3:
 
-             case 0xF4:
 
-             case 0xF5:
 
-             case 0xF6:
 
-             case 0xF7:
 
-             case 0xF8:
 
-             case 0xF9:
 
-             case 0xFA:
 
-             case 0xFB:
 
-             case 0xFC:
 
-             case 0xFD:
 
-             case 0xFE:
 
-             case 0xFF:
 
-                 return sax->number_integer(static_cast<std::int8_t>(current));
 
-             default: // anything else
 
-             {
 
-                 auto last_token = get_token_string();
 
-                 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
 
-                                         exception_message(input_format_t::msgpack, concat("invalid byte: 0x", last_token), "value"), nullptr));
 
-             }
 
-         }
 
-     }
 
-     /*!
 
-     @brief reads a MessagePack string
 
-     This function first reads starting bytes to determine the expected
 
-     string length and then copies this number of bytes into a string.
 
-     @param[out] result  created string
 
-     @return whether string creation completed
 
-     */
 
-     bool get_msgpack_string(string_t& result)
 
-     {
 
-         if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack, "string")))
 
-         {
 
-             return false;
 
-         }
 
-         switch (current)
 
-         {
 
-             // fixstr
 
-             case 0xA0:
 
-             case 0xA1:
 
-             case 0xA2:
 
-             case 0xA3:
 
-             case 0xA4:
 
-             case 0xA5:
 
-             case 0xA6:
 
-             case 0xA7:
 
-             case 0xA8:
 
-             case 0xA9:
 
-             case 0xAA:
 
-             case 0xAB:
 
-             case 0xAC:
 
-             case 0xAD:
 
-             case 0xAE:
 
-             case 0xAF:
 
-             case 0xB0:
 
-             case 0xB1:
 
-             case 0xB2:
 
-             case 0xB3:
 
-             case 0xB4:
 
-             case 0xB5:
 
-             case 0xB6:
 
-             case 0xB7:
 
-             case 0xB8:
 
-             case 0xB9:
 
-             case 0xBA:
 
-             case 0xBB:
 
-             case 0xBC:
 
-             case 0xBD:
 
-             case 0xBE:
 
-             case 0xBF:
 
-             {
 
-                 return get_string(input_format_t::msgpack, static_cast<unsigned int>(current) & 0x1Fu, result);
 
-             }
 
-             case 0xD9: // str 8
 
-             {
 
-                 std::uint8_t len{};
 
-                 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
 
-             }
 
-             case 0xDA: // str 16
 
-             {
 
-                 std::uint16_t len{};
 
-                 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
 
-             }
 
-             case 0xDB: // str 32
 
-             {
 
-                 std::uint32_t len{};
 
-                 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
 
-             }
 
-             default:
 
-             {
 
-                 auto last_token = get_token_string();
 
-                 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
 
-                                         exception_message(input_format_t::msgpack, concat("expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token), "string"), nullptr));
 
-             }
 
-         }
 
-     }
 
-     /*!
 
-     @brief reads a MessagePack byte array
 
-     This function first reads starting bytes to determine the expected
 
-     byte array length and then copies this number of bytes into a byte array.
 
-     @param[out] result  created byte array
 
-     @return whether byte array creation completed
 
-     */
 
-     bool get_msgpack_binary(binary_t& result)
 
-     {
 
-         // helper function to set the subtype
 
-         auto assign_and_return_true = [&result](std::int8_t subtype)
 
-         {
 
-             result.set_subtype(static_cast<std::uint8_t>(subtype));
 
-             return true;
 
-         };
 
-         switch (current)
 
-         {
 
-             case 0xC4: // bin 8
 
-             {
 
-                 std::uint8_t len{};
 
-                 return get_number(input_format_t::msgpack, len) &&
 
-                        get_binary(input_format_t::msgpack, len, result);
 
-             }
 
-             case 0xC5: // bin 16
 
-             {
 
-                 std::uint16_t len{};
 
-                 return get_number(input_format_t::msgpack, len) &&
 
-                        get_binary(input_format_t::msgpack, len, result);
 
-             }
 
-             case 0xC6: // bin 32
 
-             {
 
-                 std::uint32_t len{};
 
-                 return get_number(input_format_t::msgpack, len) &&
 
-                        get_binary(input_format_t::msgpack, len, result);
 
-             }
 
-             case 0xC7: // ext 8
 
-             {
 
-                 std::uint8_t len{};
 
-                 std::int8_t subtype{};
 
-                 return get_number(input_format_t::msgpack, len) &&
 
-                        get_number(input_format_t::msgpack, subtype) &&
 
-                        get_binary(input_format_t::msgpack, len, result) &&
 
-                        assign_and_return_true(subtype);
 
-             }
 
-             case 0xC8: // ext 16
 
-             {
 
-                 std::uint16_t len{};
 
-                 std::int8_t subtype{};
 
-                 return get_number(input_format_t::msgpack, len) &&
 
-                        get_number(input_format_t::msgpack, subtype) &&
 
-                        get_binary(input_format_t::msgpack, len, result) &&
 
-                        assign_and_return_true(subtype);
 
-             }
 
-             case 0xC9: // ext 32
 
-             {
 
-                 std::uint32_t len{};
 
-                 std::int8_t subtype{};
 
-                 return get_number(input_format_t::msgpack, len) &&
 
-                        get_number(input_format_t::msgpack, subtype) &&
 
-                        get_binary(input_format_t::msgpack, len, result) &&
 
-                        assign_and_return_true(subtype);
 
-             }
 
-             case 0xD4: // fixext 1
 
-             {
 
-                 std::int8_t subtype{};
 
-                 return get_number(input_format_t::msgpack, subtype) &&
 
-                        get_binary(input_format_t::msgpack, 1, result) &&
 
-                        assign_and_return_true(subtype);
 
-             }
 
-             case 0xD5: // fixext 2
 
-             {
 
-                 std::int8_t subtype{};
 
-                 return get_number(input_format_t::msgpack, subtype) &&
 
-                        get_binary(input_format_t::msgpack, 2, result) &&
 
-                        assign_and_return_true(subtype);
 
-             }
 
-             case 0xD6: // fixext 4
 
-             {
 
-                 std::int8_t subtype{};
 
-                 return get_number(input_format_t::msgpack, subtype) &&
 
-                        get_binary(input_format_t::msgpack, 4, result) &&
 
-                        assign_and_return_true(subtype);
 
-             }
 
-             case 0xD7: // fixext 8
 
-             {
 
-                 std::int8_t subtype{};
 
-                 return get_number(input_format_t::msgpack, subtype) &&
 
-                        get_binary(input_format_t::msgpack, 8, result) &&
 
-                        assign_and_return_true(subtype);
 
-             }
 
-             case 0xD8: // fixext 16
 
-             {
 
-                 std::int8_t subtype{};
 
-                 return get_number(input_format_t::msgpack, subtype) &&
 
-                        get_binary(input_format_t::msgpack, 16, result) &&
 
-                        assign_and_return_true(subtype);
 
-             }
 
-             default:           // LCOV_EXCL_LINE
 
-                 return false;  // LCOV_EXCL_LINE
 
-         }
 
-     }
 
-     /*!
 
-     @param[in] len  the length of the array
 
-     @return whether array creation completed
 
-     */
 
-     bool get_msgpack_array(const std::size_t len)
 
-     {
 
-         if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
 
-         {
 
-             return false;
 
-         }
 
-         for (std::size_t i = 0; i < len; ++i)
 
-         {
 
-             if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
 
-             {
 
-                 return false;
 
-             }
 
-         }
 
-         return sax->end_array();
 
-     }
 
-     /*!
 
-     @param[in] len  the length of the object
 
-     @return whether object creation completed
 
-     */
 
-     bool get_msgpack_object(const std::size_t len)
 
-     {
 
-         if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
 
-         {
 
-             return false;
 
-         }
 
-         string_t key;
 
-         for (std::size_t i = 0; i < len; ++i)
 
-         {
 
-             get();
 
-             if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
 
-             {
 
-                 return false;
 
-             }
 
-             if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
 
-             {
 
-                 return false;
 
-             }
 
-             key.clear();
 
-         }
 
-         return sax->end_object();
 
-     }
 
-     ////////////
 
-     // UBJSON //
 
-     ////////////
 
-     /*!
 
-     @param[in] get_char  whether a new character should be retrieved from the
 
-                          input (true, default) or whether the last read
 
-                          character should be considered instead
 
-     @return whether a valid UBJSON value was passed to the SAX parser
 
-     */
 
-     bool parse_ubjson_internal(const bool get_char = true)
 
-     {
 
-         return get_ubjson_value(get_char ? get_ignore_noop() : current);
 
-     }
 
-     /*!
 
-     @brief reads a UBJSON string
 
-     This function is either called after reading the 'S' byte explicitly
 
-     indicating a string, or in case of an object key where the 'S' byte can be
 
-     left out.
 
-     @param[out] result   created string
 
-     @param[in] get_char  whether a new character should be retrieved from the
 
-                          input (true, default) or whether the last read
 
-                          character should be considered instead
 
-     @return whether string creation completed
 
-     */
 
-     bool get_ubjson_string(string_t& result, const bool get_char = true)
 
-     {
 
-         if (get_char)
 
-         {
 
-             get();  // TODO(niels): may we ignore N here?
 
-         }
 
-         if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "value")))
 
-         {
 
-             return false;
 
-         }
 
-         switch (current)
 
-         {
 
-             case 'U':
 
-             {
 
-                 std::uint8_t len{};
 
-                 return get_number(input_format, len) && get_string(input_format, len, result);
 
-             }
 
-             case 'i':
 
-             {
 
-                 std::int8_t len{};
 
-                 return get_number(input_format, len) && get_string(input_format, len, result);
 
-             }
 
-             case 'I':
 
-             {
 
-                 std::int16_t len{};
 
-                 return get_number(input_format, len) && get_string(input_format, len, result);
 
-             }
 
-             case 'l':
 
-             {
 
-                 std::int32_t len{};
 
-                 return get_number(input_format, len) && get_string(input_format, len, result);
 
-             }
 
-             case 'L':
 
-             {
 
-                 std::int64_t len{};
 
-                 return get_number(input_format, len) && get_string(input_format, len, result);
 
-             }
 
-             case 'u':
 
-             {
 
-                 if (input_format != input_format_t::bjdata)
 
-                 {
 
-                     break;
 
-                 }
 
-                 std::uint16_t len{};
 
-                 return get_number(input_format, len) && get_string(input_format, len, result);
 
-             }
 
-             case 'm':
 
-             {
 
-                 if (input_format != input_format_t::bjdata)
 
-                 {
 
-                     break;
 
-                 }
 
-                 std::uint32_t len{};
 
-                 return get_number(input_format, len) && get_string(input_format, len, result);
 
-             }
 
-             case 'M':
 
-             {
 
-                 if (input_format != input_format_t::bjdata)
 
-                 {
 
-                     break;
 
-                 }
 
-                 std::uint64_t len{};
 
-                 return get_number(input_format, len) && get_string(input_format, len, result);
 
-             }
 
-             default:
 
-                 break;
 
-         }
 
-         auto last_token = get_token_string();
 
-         std::string message;
 
-         if (input_format != input_format_t::bjdata)
 
-         {
 
-             message = "expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
 
-         }
 
-         else
 
-         {
 
-             message = "expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token;
 
-         }
 
-         return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message, "string"), nullptr));
 
-     }
 
-     /*!
 
-     @param[out] dim  an integer vector storing the ND array dimensions
 
-     @return whether reading ND array size vector is successful
 
-     */
 
-     bool get_ubjson_ndarray_size(std::vector<size_t>& dim)
 
-     {
 
-         std::pair<std::size_t, char_int_type> size_and_type;
 
-         size_t dimlen = 0;
 
-         bool no_ndarray = true;
 
-         if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type, no_ndarray)))
 
-         {
 
-             return false;
 
-         }
 
-         if (size_and_type.first != npos)
 
-         {
 
-             if (size_and_type.second != 0)
 
-             {
 
-                 if (size_and_type.second != 'N')
 
-                 {
 
-                     for (std::size_t i = 0; i < size_and_type.first; ++i)
 
-                     {
 
-                         if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second)))
 
-                         {
 
-                             return false;
 
-                         }
 
-                         dim.push_back(dimlen);
 
-                     }
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 for (std::size_t i = 0; i < size_and_type.first; ++i)
 
-                 {
 
-                     if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray)))
 
-                     {
 
-                         return false;
 
-                     }
 
-                     dim.push_back(dimlen);
 
-                 }
 
-             }
 
-         }
 
-         else
 
-         {
 
-             while (current != ']')
 
-             {
 
-                 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current)))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 dim.push_back(dimlen);
 
-                 get_ignore_noop();
 
-             }
 
-         }
 
-         return true;
 
-     }
 
-     /*!
 
-     @param[out] result  determined size
 
-     @param[in,out] is_ndarray  for input, `true` means already inside an ndarray vector
 
-                                or ndarray dimension is not allowed; `false` means ndarray
 
-                                is allowed; for output, `true` means an ndarray is found;
 
-                                is_ndarray can only return `true` when its initial value
 
-                                is `false`
 
-     @param[in] prefix  type marker if already read, otherwise set to 0
 
-     @return whether size determination completed
 
-     */
 
-     bool get_ubjson_size_value(std::size_t& result, bool& is_ndarray, char_int_type prefix = 0)
 
-     {
 
-         if (prefix == 0)
 
-         {
 
-             prefix = get_ignore_noop();
 
-         }
 
-         switch (prefix)
 
-         {
 
-             case 'U':
 
-             {
 
-                 std::uint8_t number{};
 
-                 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 result = static_cast<std::size_t>(number);
 
-                 return true;
 
-             }
 
-             case 'i':
 
-             {
 
-                 std::int8_t number{};
 
-                 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 if (number < 0)
 
-                 {
 
-                     return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
 
-                                             exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr));
 
-                 }
 
-                 result = static_cast<std::size_t>(number); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): number is not a char
 
-                 return true;
 
-             }
 
-             case 'I':
 
-             {
 
-                 std::int16_t number{};
 
-                 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 if (number < 0)
 
-                 {
 
-                     return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
 
-                                             exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr));
 
-                 }
 
-                 result = static_cast<std::size_t>(number);
 
-                 return true;
 
-             }
 
-             case 'l':
 
-             {
 
-                 std::int32_t number{};
 
-                 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 if (number < 0)
 
-                 {
 
-                     return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
 
-                                             exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr));
 
-                 }
 
-                 result = static_cast<std::size_t>(number);
 
-                 return true;
 
-             }
 
-             case 'L':
 
-             {
 
-                 std::int64_t number{};
 
-                 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 if (number < 0)
 
-                 {
 
-                     return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
 
-                                             exception_message(input_format, "count in an optimized container must be positive", "size"), nullptr));
 
-                 }
 
-                 if (!value_in_range_of<std::size_t>(number))
 
-                 {
 
-                     return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
 
-                                             exception_message(input_format, "integer value overflow", "size"), nullptr));
 
-                 }
 
-                 result = static_cast<std::size_t>(number);
 
-                 return true;
 
-             }
 
-             case 'u':
 
-             {
 
-                 if (input_format != input_format_t::bjdata)
 
-                 {
 
-                     break;
 
-                 }
 
-                 std::uint16_t number{};
 
-                 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 result = static_cast<std::size_t>(number);
 
-                 return true;
 
-             }
 
-             case 'm':
 
-             {
 
-                 if (input_format != input_format_t::bjdata)
 
-                 {
 
-                     break;
 
-                 }
 
-                 std::uint32_t number{};
 
-                 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 result = conditional_static_cast<std::size_t>(number);
 
-                 return true;
 
-             }
 
-             case 'M':
 
-             {
 
-                 if (input_format != input_format_t::bjdata)
 
-                 {
 
-                     break;
 
-                 }
 
-                 std::uint64_t number{};
 
-                 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 if (!value_in_range_of<std::size_t>(number))
 
-                 {
 
-                     return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
 
-                                             exception_message(input_format, "integer value overflow", "size"), nullptr));
 
-                 }
 
-                 result = detail::conditional_static_cast<std::size_t>(number);
 
-                 return true;
 
-             }
 
-             case '[':
 
-             {
 
-                 if (input_format != input_format_t::bjdata)
 
-                 {
 
-                     break;
 
-                 }
 
-                 if (is_ndarray) // ndarray dimensional vector can only contain integers, and can not embed another array
 
-                 {
 
-                     return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read, exception_message(input_format, "ndarray dimensional vector is not allowed", "size"), nullptr));
 
-                 }
 
-                 std::vector<size_t> dim;
 
-                 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_ndarray_size(dim)))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1)) // return normal array size if 1D row vector
 
-                 {
 
-                     result = dim.at(dim.size() - 1);
 
-                     return true;
 
-                 }
 
-                 if (!dim.empty())  // if ndarray, convert to an object in JData annotated array format
 
-                 {
 
-                     for (auto i : dim) // test if any dimension in an ndarray is 0, if so, return a 1D empty container
 
-                     {
 
-                         if ( i == 0 )
 
-                         {
 
-                             result = 0;
 
-                             return true;
 
-                         }
 
-                     }
 
-                     string_t key = "_ArraySize_";
 
-                     if (JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(key) || !sax->start_array(dim.size())))
 
-                     {
 
-                         return false;
 
-                     }
 
-                     result = 1;
 
-                     for (auto i : dim)
 
-                     {
 
-                         result *= i;
 
-                         if (result == 0 || result == npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be npos as it is used to initialize size in get_ubjson_size_type()
 
-                         {
 
-                             return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr));
 
-                         }
 
-                         if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(static_cast<number_unsigned_t>(i))))
 
-                         {
 
-                             return false;
 
-                         }
 
-                     }
 
-                     is_ndarray = true;
 
-                     return sax->end_array();
 
-                 }
 
-                 result = 0;
 
-                 return true;
 
-             }
 
-             default:
 
-                 break;
 
-         }
 
-         auto last_token = get_token_string();
 
-         std::string message;
 
-         if (input_format != input_format_t::bjdata)
 
-         {
 
-             message = "expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token;
 
-         }
 
-         else
 
-         {
 
-             message = "expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token;
 
-         }
 
-         return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message, "size"), nullptr));
 
-     }
 
-     /*!
 
-     @brief determine the type and size for a container
 
-     In the optimized UBJSON format, a type and a size can be provided to allow
 
-     for a more compact representation.
 
-     @param[out] result  pair of the size and the type
 
-     @param[in] inside_ndarray  whether the parser is parsing an ND array dimensional vector
 
-     @return whether pair creation completed
 
-     */
 
-     bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result, bool inside_ndarray = false)
 
-     {
 
-         result.first = npos; // size
 
-         result.second = 0; // type
 
-         bool is_ndarray = false;
 
-         get_ignore_noop();
 
-         if (current == '$')
 
-         {
 
-             result.second = get();  // must not ignore 'N', because 'N' maybe the type
 
-             if (input_format == input_format_t::bjdata
 
-                     && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
 
-             {
 
-                 auto last_token = get_token_string();
 
-                 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
 
-                                         exception_message(input_format, concat("marker 0x", last_token, " is not a permitted optimized array type"), "type"), nullptr));
 
-             }
 
-             if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "type")))
 
-             {
 
-                 return false;
 
-             }
 
-             get_ignore_noop();
 
-             if (JSON_HEDLEY_UNLIKELY(current != '#'))
 
-             {
 
-                 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "value")))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 auto last_token = get_token_string();
 
-                 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
 
-                                         exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr));
 
-             }
 
-             const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
 
-             if (input_format == input_format_t::bjdata && is_ndarray)
 
-             {
 
-                 if (inside_ndarray)
 
-                 {
 
-                     return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
 
-                                             exception_message(input_format, "ndarray can not be recursive", "size"), nullptr));
 
-                 }
 
-                 result.second |= (1 << 8); // use bit 8 to indicate ndarray, all UBJSON and BJData markers should be ASCII letters
 
-             }
 
-             return is_error;
 
-         }
 
-         if (current == '#')
 
-         {
 
-             const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
 
-             if (input_format == input_format_t::bjdata && is_ndarray)
 
-             {
 
-                 return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
 
-                                         exception_message(input_format, "ndarray requires both type and size", "size"), nullptr));
 
-             }
 
-             return is_error;
 
-         }
 
-         return true;
 
-     }
 
-     /*!
 
-     @param prefix  the previously read or set type prefix
 
-     @return whether value creation completed
 
-     */
 
-     bool get_ubjson_value(const char_int_type prefix)
 
-     {
 
-         switch (prefix)
 
-         {
 
-             case char_traits<char_type>::eof():  // EOF
 
-                 return unexpect_eof(input_format, "value");
 
-             case 'T':  // true
 
-                 return sax->boolean(true);
 
-             case 'F':  // false
 
-                 return sax->boolean(false);
 
-             case 'Z':  // null
 
-                 return sax->null();
 
-             case 'B':  // byte
 
-             {
 
-                 if (input_format != input_format_t::bjdata)
 
-                 {
 
-                     break;
 
-                 }
 
-                 std::uint8_t number{};
 
-                 return get_number(input_format, number) && sax->number_unsigned(number);
 
-             }
 
-             case 'U':
 
-             {
 
-                 std::uint8_t number{};
 
-                 return get_number(input_format, number) && sax->number_unsigned(number);
 
-             }
 
-             case 'i':
 
-             {
 
-                 std::int8_t number{};
 
-                 return get_number(input_format, number) && sax->number_integer(number);
 
-             }
 
-             case 'I':
 
-             {
 
-                 std::int16_t number{};
 
-                 return get_number(input_format, number) && sax->number_integer(number);
 
-             }
 
-             case 'l':
 
-             {
 
-                 std::int32_t number{};
 
-                 return get_number(input_format, number) && sax->number_integer(number);
 
-             }
 
-             case 'L':
 
-             {
 
-                 std::int64_t number{};
 
-                 return get_number(input_format, number) && sax->number_integer(number);
 
-             }
 
-             case 'u':
 
-             {
 
-                 if (input_format != input_format_t::bjdata)
 
-                 {
 
-                     break;
 
-                 }
 
-                 std::uint16_t number{};
 
-                 return get_number(input_format, number) && sax->number_unsigned(number);
 
-             }
 
-             case 'm':
 
-             {
 
-                 if (input_format != input_format_t::bjdata)
 
-                 {
 
-                     break;
 
-                 }
 
-                 std::uint32_t number{};
 
-                 return get_number(input_format, number) && sax->number_unsigned(number);
 
-             }
 
-             case 'M':
 
-             {
 
-                 if (input_format != input_format_t::bjdata)
 
-                 {
 
-                     break;
 
-                 }
 
-                 std::uint64_t number{};
 
-                 return get_number(input_format, number) && sax->number_unsigned(number);
 
-             }
 
-             case 'h':
 
-             {
 
-                 if (input_format != input_format_t::bjdata)
 
-                 {
 
-                     break;
 
-                 }
 
-                 const auto byte1_raw = get();
 
-                 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "number")))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 const auto byte2_raw = get();
 
-                 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "number")))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 const auto byte1 = static_cast<unsigned char>(byte1_raw);
 
-                 const auto byte2 = static_cast<unsigned char>(byte2_raw);
 
-                 // code from RFC 7049, Appendix D, Figure 3:
 
-                 // As half-precision floating-point numbers were only added
 
-                 // to IEEE 754 in 2008, today's programming platforms often
 
-                 // still only have limited support for them. It is very
 
-                 // easy to include at least decoding support for them even
 
-                 // without such support. An example of a small decoder for
 
-                 // half-precision floating-point numbers in the C language
 
-                 // is shown in Fig. 3.
 
-                 const auto half = static_cast<unsigned int>((byte2 << 8u) + byte1);
 
-                 const double val = [&half]
 
-                 {
 
-                     const int exp = (half >> 10u) & 0x1Fu;
 
-                     const unsigned int mant = half & 0x3FFu;
 
-                     JSON_ASSERT(0 <= exp&& exp <= 32);
 
-                     JSON_ASSERT(mant <= 1024);
 
-                     switch (exp)
 
-                     {
 
-                         case 0:
 
-                             return std::ldexp(mant, -24);
 
-                         case 31:
 
-                             return (mant == 0)
 
-                             ? std::numeric_limits<double>::infinity()
 
-                             : std::numeric_limits<double>::quiet_NaN();
 
-                         default:
 
-                             return std::ldexp(mant + 1024, exp - 25);
 
-                     }
 
-                 }();
 
-                 return sax->number_float((half & 0x8000u) != 0
 
-                                          ? static_cast<number_float_t>(-val)
 
-                                          : static_cast<number_float_t>(val), "");
 
-             }
 
-             case 'd':
 
-             {
 
-                 float number{};
 
-                 return get_number(input_format, number) && sax->number_float(static_cast<number_float_t>(number), "");
 
-             }
 
-             case 'D':
 
-             {
 
-                 double number{};
 
-                 return get_number(input_format, number) && sax->number_float(static_cast<number_float_t>(number), "");
 
-             }
 
-             case 'H':
 
-             {
 
-                 return get_ubjson_high_precision_number();
 
-             }
 
-             case 'C':  // char
 
-             {
 
-                 get();
 
-                 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "char")))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 if (JSON_HEDLEY_UNLIKELY(current > 127))
 
-                 {
 
-                     auto last_token = get_token_string();
 
-                     return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
 
-                                             exception_message(input_format, concat("byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token), "char"), nullptr));
 
-                 }
 
-                 string_t s(1, static_cast<typename string_t::value_type>(current));
 
-                 return sax->string(s);
 
-             }
 
-             case 'S':  // string
 
-             {
 
-                 string_t s;
 
-                 return get_ubjson_string(s) && sax->string(s);
 
-             }
 
-             case '[':  // array
 
-                 return get_ubjson_array();
 
-             case '{':  // object
 
-                 return get_ubjson_object();
 
-             default: // anything else
 
-                 break;
 
-         }
 
-         auto last_token = get_token_string();
 
-         return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format, "invalid byte: 0x" + last_token, "value"), nullptr));
 
-     }
 
-     /*!
 
-     @return whether array creation completed
 
-     */
 
-     bool get_ubjson_array()
 
-     {
 
-         std::pair<std::size_t, char_int_type> size_and_type;
 
-         if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
 
-         {
 
-             return false;
 
-         }
 
-         // if bit-8 of size_and_type.second is set to 1, encode bjdata ndarray as an object in JData annotated array format (https://github.com/NeuroJSON/jdata):
 
-         // {"_ArrayType_" : "typeid", "_ArraySize_" : [n1, n2, ...], "_ArrayData_" : [v1, v2, ...]}
 
-         if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
 
-         {
 
-             size_and_type.second &= ~(static_cast<char_int_type>(1) << 8);  // use bit 8 to indicate ndarray, here we remove the bit to restore the type marker
 
-             auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](const bjd_type & p, char_int_type t)
 
-             {
 
-                 return p.first < t;
 
-             });
 
-             string_t key = "_ArrayType_";
 
-             if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second))
 
-             {
 
-                 auto last_token = get_token_string();
 
-                 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
 
-                                         exception_message(input_format, "invalid byte: 0x" + last_token, "type"), nullptr));
 
-             }
 
-             string_t type = it->second; // sax->string() takes a reference
 
-             if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type)))
 
-             {
 
-                 return false;
 
-             }
 
-             if (size_and_type.second == 'C' || size_and_type.second == 'B')
 
-             {
 
-                 size_and_type.second = 'U';
 
-             }
 
-             key = "_ArrayData_";
 
-             if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first) ))
 
-             {
 
-                 return false;
 
-             }
 
-             for (std::size_t i = 0; i < size_and_type.first; ++i)
 
-             {
 
-                 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
 
-                 {
 
-                     return false;
 
-                 }
 
-             }
 
-             return (sax->end_array() && sax->end_object());
 
-         }
 
-         // If BJData type marker is 'B' decode as binary
 
-         if (input_format == input_format_t::bjdata && size_and_type.first != npos && size_and_type.second == 'B')
 
-         {
 
-             binary_t result;
 
-             return get_binary(input_format, size_and_type.first, result) && sax->binary(result);
 
-         }
 
-         if (size_and_type.first != npos)
 
-         {
 
-             if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
 
-             {
 
-                 return false;
 
-             }
 
-             if (size_and_type.second != 0)
 
-             {
 
-                 if (size_and_type.second != 'N')
 
-                 {
 
-                     for (std::size_t i = 0; i < size_and_type.first; ++i)
 
-                     {
 
-                         if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
 
-                         {
 
-                             return false;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 for (std::size_t i = 0; i < size_and_type.first; ++i)
 
-                 {
 
-                     if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
 
-                     {
 
-                         return false;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         else
 
-         {
 
-             if (JSON_HEDLEY_UNLIKELY(!sax->start_array(detail::unknown_size())))
 
-             {
 
-                 return false;
 
-             }
 
-             while (current != ']')
 
-             {
 
-                 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(false)))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 get_ignore_noop();
 
-             }
 
-         }
 
-         return sax->end_array();
 
-     }
 
-     /*!
 
-     @return whether object creation completed
 
-     */
 
-     bool get_ubjson_object()
 
-     {
 
-         std::pair<std::size_t, char_int_type> size_and_type;
 
-         if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
 
-         {
 
-             return false;
 
-         }
 
-         // do not accept ND-array size in objects in BJData
 
-         if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
 
-         {
 
-             auto last_token = get_token_string();
 
-             return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
 
-                                     exception_message(input_format, "BJData object does not support ND-array size in optimized format", "object"), nullptr));
 
-         }
 
-         string_t key;
 
-         if (size_and_type.first != npos)
 
-         {
 
-             if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
 
-             {
 
-                 return false;
 
-             }
 
-             if (size_and_type.second != 0)
 
-             {
 
-                 for (std::size_t i = 0; i < size_and_type.first; ++i)
 
-                 {
 
-                     if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
 
-                     {
 
-                         return false;
 
-                     }
 
-                     if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
 
-                     {
 
-                         return false;
 
-                     }
 
-                     key.clear();
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 for (std::size_t i = 0; i < size_and_type.first; ++i)
 
-                 {
 
-                     if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
 
-                     {
 
-                         return false;
 
-                     }
 
-                     if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
 
-                     {
 
-                         return false;
 
-                     }
 
-                     key.clear();
 
-                 }
 
-             }
 
-         }
 
-         else
 
-         {
 
-             if (JSON_HEDLEY_UNLIKELY(!sax->start_object(detail::unknown_size())))
 
-             {
 
-                 return false;
 
-             }
 
-             while (current != '}')
 
-             {
 
-                 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key, false) || !sax->key(key)))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
 
-                 {
 
-                     return false;
 
-                 }
 
-                 get_ignore_noop();
 
-                 key.clear();
 
-             }
 
-         }
 
-         return sax->end_object();
 
-     }
 
-     // Note, no reader for UBJSON binary types is implemented because they do
 
-     // not exist
 
-     bool get_ubjson_high_precision_number()
 
-     {
 
-         // get size of following number string
 
-         std::size_t size{};
 
-         bool no_ndarray = true;
 
-         auto res = get_ubjson_size_value(size, no_ndarray);
 
-         if (JSON_HEDLEY_UNLIKELY(!res))
 
-         {
 
-             return res;
 
-         }
 
-         // get number string
 
-         std::vector<char> number_vector;
 
-         for (std::size_t i = 0; i < size; ++i)
 
-         {
 
-             get();
 
-             if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format, "number")))
 
-             {
 
-                 return false;
 
-             }
 
-             number_vector.push_back(static_cast<char>(current));
 
-         }
 
-         // parse number string
 
-         using ia_type = decltype(detail::input_adapter(number_vector));
 
-         auto number_lexer = detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector), false);
 
-         const auto result_number = number_lexer.scan();
 
-         const auto number_string = number_lexer.get_token_string();
 
-         const auto result_remainder = number_lexer.scan();
 
-         using token_type = typename detail::lexer_base<BasicJsonType>::token_type;
 
-         if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
 
-         {
 
-             return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
 
-                                     exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr));
 
-         }
 
-         switch (result_number)
 
-         {
 
-             case token_type::value_integer:
 
-                 return sax->number_integer(number_lexer.get_number_integer());
 
-             case token_type::value_unsigned:
 
-                 return sax->number_unsigned(number_lexer.get_number_unsigned());
 
-             case token_type::value_float:
 
-                 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
 
-             case token_type::uninitialized:
 
-             case token_type::literal_true:
 
-             case token_type::literal_false:
 
-             case token_type::literal_null:
 
-             case token_type::value_string:
 
-             case token_type::begin_array:
 
-             case token_type::begin_object:
 
-             case token_type::end_array:
 
-             case token_type::end_object:
 
-             case token_type::name_separator:
 
-             case token_type::value_separator:
 
-             case token_type::parse_error:
 
-             case token_type::end_of_input:
 
-             case token_type::literal_or_value:
 
-             default:
 
-                 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
 
-                                         exception_message(input_format, concat("invalid number text: ", number_lexer.get_token_string()), "high-precision number"), nullptr));
 
-         }
 
-     }
 
-     ///////////////////////
 
-     // Utility functions //
 
-     ///////////////////////
 
-     /*!
 
-     @brief get next character from the input
 
-     This function provides the interface to the used input adapter. It does
 
-     not throw in case the input reached EOF, but returns a -'ve valued
 
-     `char_traits<char_type>::eof()` in that case.
 
-     @return character read from the input
 
-     */
 
-     char_int_type get()
 
-     {
 
-         ++chars_read;
 
-         return current = ia.get_character();
 
-     }
 
-     /*!
 
-     @brief get_to read into a primitive type
 
-     This function provides the interface to the used input adapter. It does
 
-     not throw in case the input reached EOF, but returns false instead
 
-     @return bool, whether the read was successful
 
-     */
 
-     template<class T>
 
-     bool get_to(T& dest, const input_format_t format, const char* context)
 
-     {
 
-         auto new_chars_read = ia.get_elements(&dest);
 
-         chars_read += new_chars_read;
 
-         if (JSON_HEDLEY_UNLIKELY(new_chars_read < sizeof(T)))
 
-         {
 
-             // in case of failure, advance position by 1 to report failing location
 
-             ++chars_read;
 
-             sax->parse_error(chars_read, "<end of file>", parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr));
 
-             return false;
 
-         }
 
-         return true;
 
-     }
 
-     /*!
 
-     @return character read from the input after ignoring all 'N' entries
 
-     */
 
-     char_int_type get_ignore_noop()
 
-     {
 
-         do
 
-         {
 
-             get();
 
-         }
 
-         while (current == 'N');
 
-         return current;
 
-     }
 
-     template<class NumberType>
 
-     static void byte_swap(NumberType& number)
 
-     {
 
-         constexpr std::size_t sz = sizeof(number);
 
- #ifdef __cpp_lib_byteswap
 
-         if constexpr (sz == 1)
 
-         {
 
-             return;
 
-         }
 
-         if constexpr(std::is_integral_v<NumberType>)
 
-         {
 
-             number = std::byteswap(number);
 
-             return;
 
-         }
 
- #endif
 
-         auto* ptr = reinterpret_cast<std::uint8_t*>(&number);
 
-         for (std::size_t i = 0; i < sz / 2; ++i)
 
-         {
 
-             std::swap(ptr[i], ptr[sz - i - 1]);
 
-         }
 
-     }
 
-     /*
 
-     @brief read a number from the input
 
-     @tparam NumberType the type of the number
 
-     @param[in] format   the current format (for diagnostics)
 
-     @param[out] result  number of type @a NumberType
 
-     @return whether conversion completed
 
-     @note This function needs to respect the system's endianness, because
 
-           bytes in CBOR, MessagePack, and UBJSON are stored in network order
 
-           (big endian) and therefore need reordering on little endian systems.
 
-           On the other hand, BSON and BJData use little endian and should reorder
 
-           on big endian systems.
 
-     */
 
-     template<typename NumberType, bool InputIsLittleEndian = false>
 
-     bool get_number(const input_format_t format, NumberType& result)
 
-     {
 
-         // read in the original format
 
-         if (JSON_HEDLEY_UNLIKELY(!get_to(result, format, "number")))
 
-         {
 
-             return false;
 
-         }
 
-         if (is_little_endian != (InputIsLittleEndian || format == input_format_t::bjdata))
 
-         {
 
-             byte_swap(result);
 
-         }
 
-         return true;
 
-     }
 
-     /*!
 
-     @brief create a string by reading characters from the input
 
-     @tparam NumberType the type of the number
 
-     @param[in] format the current format (for diagnostics)
 
-     @param[in] len number of characters to read
 
-     @param[out] result string created by reading @a len bytes
 
-     @return whether string creation completed
 
-     @note We can not reserve @a len bytes for the result, because @a len
 
-           may be too large. Usually, @ref unexpect_eof() detects the end of
 
-           the input before we run out of string memory.
 
-     */
 
-     template<typename NumberType>
 
-     bool get_string(const input_format_t format,
 
-                     const NumberType len,
 
-                     string_t& result)
 
-     {
 
-         bool success = true;
 
-         for (NumberType i = 0; i < len; i++)
 
-         {
 
-             get();
 
-             if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "string")))
 
-             {
 
-                 success = false;
 
-                 break;
 
-             }
 
-             result.push_back(static_cast<typename string_t::value_type>(current));
 
-         }
 
-         return success;
 
-     }
 
-     /*!
 
-     @brief create a byte array by reading bytes from the input
 
-     @tparam NumberType the type of the number
 
-     @param[in] format the current format (for diagnostics)
 
-     @param[in] len number of bytes to read
 
-     @param[out] result byte array created by reading @a len bytes
 
-     @return whether byte array creation completed
 
-     @note We can not reserve @a len bytes for the result, because @a len
 
-           may be too large. Usually, @ref unexpect_eof() detects the end of
 
-           the input before we run out of memory.
 
-     */
 
-     template<typename NumberType>
 
-     bool get_binary(const input_format_t format,
 
-                     const NumberType len,
 
-                     binary_t& result)
 
-     {
 
-         bool success = true;
 
-         for (NumberType i = 0; i < len; i++)
 
-         {
 
-             get();
 
-             if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "binary")))
 
-             {
 
-                 success = false;
 
-                 break;
 
-             }
 
-             result.push_back(static_cast<std::uint8_t>(current));
 
-         }
 
-         return success;
 
-     }
 
-     /*!
 
-     @param[in] format   the current format (for diagnostics)
 
-     @param[in] context  further context information (for diagnostics)
 
-     @return whether the last read character is not EOF
 
-     */
 
-     JSON_HEDLEY_NON_NULL(3)
 
-     bool unexpect_eof(const input_format_t format, const char* context) const
 
-     {
 
-         if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof()))
 
-         {
 
-             return sax->parse_error(chars_read, "<end of file>",
 
-                                     parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), nullptr));
 
-         }
 
-         return true;
 
-     }
 
-     /*!
 
-     @return a string representation of the last read byte
 
-     */
 
-     std::string get_token_string() const
 
-     {
 
-         std::array<char, 3> cr{{}};
 
-         static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
 
-         return std::string{cr.data()};
 
-     }
 
-     /*!
 
-     @param[in] format   the current format
 
-     @param[in] detail   a detailed error message
 
-     @param[in] context  further context information
 
-     @return a message string to use in the parse_error exceptions
 
-     */
 
-     std::string exception_message(const input_format_t format,
 
-                                   const std::string& detail,
 
-                                   const std::string& context) const
 
-     {
 
-         std::string error_msg = "syntax error while parsing ";
 
-         switch (format)
 
-         {
 
-             case input_format_t::cbor:
 
-                 error_msg += "CBOR";
 
-                 break;
 
-             case input_format_t::msgpack:
 
-                 error_msg += "MessagePack";
 
-                 break;
 
-             case input_format_t::ubjson:
 
-                 error_msg += "UBJSON";
 
-                 break;
 
-             case input_format_t::bson:
 
-                 error_msg += "BSON";
 
-                 break;
 
-             case input_format_t::bjdata:
 
-                 error_msg += "BJData";
 
-                 break;
 
-             case input_format_t::json: // LCOV_EXCL_LINE
 
-             default:            // LCOV_EXCL_LINE
 
-                 JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE
 
-         }
 
-         return concat(error_msg, ' ', context, ": ", detail);
 
-     }
 
-   private:
 
-     static JSON_INLINE_VARIABLE constexpr std::size_t npos = detail::unknown_size();
 
-     /// input adapter
 
-     InputAdapterType ia;
 
-     /// the current character
 
-     char_int_type current = char_traits<char_type>::eof();
 
-     /// the number of characters read
 
-     std::size_t chars_read = 0;
 
-     /// whether we can assume little endianness
 
-     const bool is_little_endian = little_endianness();
 
-     /// input format
 
-     const input_format_t input_format = input_format_t::json;
 
-     /// the SAX parser
 
-     json_sax_t* sax = nullptr;
 
-     // excluded markers in bjdata optimized type
 
- #define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \
 
-     make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
 
- #define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
 
-     make_array<bjd_type>(                      \
 
-     bjd_type{'B', "byte"},                     \
 
-     bjd_type{'C', "char"},                     \
 
-     bjd_type{'D', "double"},                   \
 
-     bjd_type{'I', "int16"},                    \
 
-     bjd_type{'L', "int64"},                    \
 
-     bjd_type{'M', "uint64"},                   \
 
-     bjd_type{'U', "uint8"},                    \
 
-     bjd_type{'d', "single"},                   \
 
-     bjd_type{'i', "int8"},                     \
 
-     bjd_type{'l', "int32"},                    \
 
-     bjd_type{'m', "uint32"},                   \
 
-     bjd_type{'u', "uint16"})
 
-   JSON_PRIVATE_UNLESS_TESTED:
 
-     // lookup tables
 
-     // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
 
-     const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers =
 
-         JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
 
-     using bjd_type = std::pair<char_int_type, string_t>;
 
-     // NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
 
-     const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map =
 
-         JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_;
 
- #undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
 
- #undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
 
- };
 
- #ifndef JSON_HAS_CPP_17
 
-     template<typename BasicJsonType, typename InputAdapterType, typename SAX>
 
-     constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos;
 
- #endif
 
- }  // namespace detail
 
- NLOHMANN_JSON_NAMESPACE_END
 
 
  |