diff --git a/src/json.hpp b/src/json.hpp index a302bb02b..3f4052293 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -6142,6 +6142,499 @@ class basic_json /// @} + ///////////////////////// + // MessagePack support // + ///////////////////////// + + /// @name MessagePack support + /// @{ + + private: + static void to_msgpack_internal(const basic_json& j, std::vector& v) + { + switch (j.type()) + { + case value_t::null: + { + // nil + v.push_back(0xc0); + break; + } + + case value_t::boolean: + { + // true and false + v.push_back(j.m_value.boolean ? 0xc3 : 0xc2); + break; + } + + case value_t::number_integer: + { + if (j.m_value.number_integer >= -32 and j.m_value.number_integer < 128) + { + // negative fixnum and positive fixnum + v.push_back(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer >= INT8_MIN and j.m_value.number_integer <= INT8_MAX) + { + // int 8 + v.push_back(0xd0); + v.push_back(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer >= INT16_MIN and j.m_value.number_integer <= INT16_MAX) + { + // int 16 + v.push_back(0xd1); + v.push_back(static_cast((j.m_value.number_integer >> 010) & 0xff)); + v.push_back(static_cast(j.m_value.number_integer & 0xff)); + } + else if (j.m_value.number_integer >= INT32_MIN and j.m_value.number_integer <= INT32_MAX) + { + // int 32 + v.push_back(0xd2); + v.push_back(static_cast((j.m_value.number_integer >> 030) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 020) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 010) & 0xff)); + v.push_back(static_cast(j.m_value.number_integer & 0xff)); + } + else if (j.m_value.number_integer >= INT64_MIN and j.m_value.number_integer <= INT64_MAX) + { + // int 64 + v.push_back(0xd3); + v.push_back(static_cast((j.m_value.number_integer >> 070) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 060) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 050) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 040) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 030) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 020) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 010) & 0xff)); + v.push_back(static_cast(j.m_value.number_integer & 0xff)); + } + break; + } + + case value_t::number_unsigned: + { + if (j.m_value.number_unsigned < 128) + { + // positive fixnum + v.push_back(static_cast(j.m_value.number_unsigned)); + } + else if (j.m_value.number_unsigned <= UINT8_MAX) + { + // uint 8 + v.push_back(0xcc); + v.push_back(static_cast(j.m_value.number_unsigned)); + } + else if (j.m_value.number_unsigned <= UINT16_MAX) + { + // uint 16 + v.push_back(0xcd); + v.push_back(static_cast((j.m_value.number_unsigned >> 010) & 0xff)); + v.push_back(static_cast(j.m_value.number_unsigned & 0xff)); + } + else if (j.m_value.number_unsigned <= UINT32_MAX) + { + // uint 32 + v.push_back(0xce); + v.push_back(static_cast((j.m_value.number_unsigned >> 030) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 020) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 010) & 0xff)); + v.push_back(static_cast(j.m_value.number_unsigned & 0xff)); + } + else if (j.m_value.number_unsigned <= UINT64_MAX) + { + // uint 64 + v.push_back(0xcf); + v.push_back(static_cast((j.m_value.number_unsigned >> 070) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 060) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 050) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 040) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 030) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 020) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 010) & 0xff)); + v.push_back(static_cast(j.m_value.number_unsigned & 0xff)); + } + break; + } + + case value_t::number_float: + { + // float 64 + v.push_back(0xcb); + const uint8_t* helper = reinterpret_cast(&(j.m_value.number_float)); + for (size_t i = 0; i < 8; ++i) + { + v.push_back(helper[7 - i]); + } + break; + } + + case value_t::string: + { + const auto N = j.m_value.string->size(); + if (N <= 31) + { + // fixstr + v.push_back(static_cast(0xa0 | N)); + } + else if (N <= 255) + { + // str 8 + v.push_back(0xd9); + v.push_back(static_cast(N)); + } + else if (N <= 65535) + { + // str 16 + v.push_back(0xda); + v.push_back(static_cast((N >> 010) & 0xff)); + v.push_back(static_cast(N & 0xff)); + } + else if (N <= 4294967295) + { + // str 32 + v.push_back(0xdb); + v.push_back(static_cast((N >> 030) & 0xff)); + v.push_back(static_cast((N >> 020) & 0xff)); + v.push_back(static_cast((N >> 010) & 0xff)); + v.push_back(static_cast(N & 0xff)); + } + + // append string + std::copy(j.m_value.string->begin(), j.m_value.string->end(), + std::back_inserter(v)); + break; + } + + case value_t::array: + { + const auto N = j.m_value.array->size(); + if (N <= 15) + { + // fixarray + v.push_back(static_cast(0x90 | N)); + } + else if (N <= 0xffff) + { + // array 16 + v.push_back(0xdc); + v.push_back(static_cast((N >> 010) & 0xff)); + v.push_back(static_cast(N & 0xff)); + } + else if (N <= 0xffffffff) + { + // array 32 + v.push_back(0xdd); + v.push_back(static_cast((N >> 030) & 0xff)); + v.push_back(static_cast((N >> 020) & 0xff)); + v.push_back(static_cast((N >> 010) & 0xff)); + v.push_back(static_cast(N & 0xff)); + } + + // append each element + for (const auto& el : *j.m_value.array) + { + to_msgpack_internal(el, v); + } + break; + } + + case value_t::object: + { + const auto N = j.m_value.object->size(); + if (N <= 15) + { + // fixmap + v.push_back(static_cast(0x80 | (N & 0xf))); + } + else if (N <= 65535) + { + // map 16 + v.push_back(0xde); + v.push_back(static_cast((N >> 010) & 0xff)); + v.push_back(static_cast(N & 0xff)); + } + else if (N <= 4294967295) + { + // map 32 + v.push_back(0xdf); + v.push_back(static_cast((N >> 030) & 0xff)); + v.push_back(static_cast((N >> 020) & 0xff)); + v.push_back(static_cast((N >> 010) & 0xff)); + v.push_back(static_cast(N & 0xff)); + } + + // append each element + for (const auto& el : *j.m_value.object) + { + to_msgpack_internal(el.first, v); + to_msgpack_internal(el.second, v); + } + break; + } + + default: + { + break; + } + } + } + + /*! + @param[in] v MessagePack serialization + @param[in] idx byte index to start reading from @a v + */ + static basic_json from_msgpack_internal(const std::vector& v, size_t& idx) + { + // store and increment index + const size_t current_idx = idx++; + + if (v[current_idx] <= 0x7f) // positive fixint + { + return v[current_idx]; + } + else if (v[current_idx] <= 0x8f) // fixmap + { + basic_json result = value_t::object; + const size_t len = v[current_idx] & 0x0f; + for (size_t i = 0; i < len; ++i) + { + std::string key = from_msgpack_internal(v, idx); + result[key] = from_msgpack_internal(v, idx); + } + return result; + } + else if (v[current_idx] <= 0x9f) // fixarray + { + basic_json result = value_t::array; + const size_t len = v[current_idx] & 0x0f; + for (size_t i = 0; i < len; ++i) + { + result.push_back(from_msgpack_internal(v, idx)); + } + return result; + } + else if (v[current_idx] <= 0xbf) // fixstr + { + const size_t len = v[current_idx] & 0x1f; + const size_t offset = current_idx + 1; + idx += len; // skip content bytes + return std::string(reinterpret_cast(v.data()) + offset, len); + } + else if (v[current_idx] == 0xc0) // nil + { + return value_t::null; + } + else if (v[current_idx] == 0xc1) // never used + { + throw std::invalid_argument("value 0x31 must not be used@ " + std::to_string(current_idx)); + } + else if (v[current_idx] == 0xc2) // false + { + return false; + } + else if (v[current_idx] == 0xc3) // true + { + return true; + } + else if (v[current_idx] >= 0xc4 and v[current_idx] <= 0xc9) // bin/ext + { + throw std::invalid_argument("bin/ext are not supported @ " + std::to_string(current_idx)); + } + else if (v[current_idx] == 0xca) // float 32 + { + // copy bytes in reverse order into the double variable + float res; + for (size_t byte = 0; byte < sizeof(float); ++byte) + { + reinterpret_cast(&res)[sizeof(float) - byte - 1] = v[current_idx + 1 + byte]; + } + idx += sizeof(float); // skip content bytes + return res; + } + else if (v[current_idx] == 0xcb) // float 64 + { + // copy bytes in reverse order into the double variable + double res; + for (size_t byte = 0; byte < sizeof(double); ++byte) + { + reinterpret_cast(&res)[sizeof(double) - byte - 1] = v[current_idx + 1 + byte]; + } + idx += sizeof(double); // skip content bytes + return res; + } + else if (v[current_idx] == 0xcc) // uint 8 + { + idx += 1; // skip content byte + return v[current_idx + 1]; + } + else if (v[current_idx] == 0xcd) // uint 16 + { + idx += 2; // skip 2 content bytes + return static_cast((static_cast(v[current_idx + 1]) << 010) + + static_cast(v[current_idx + 2])); + } + else if (v[current_idx] == 0xce) // uint 32 + { + idx += 4; // skip 4 content bytes + return static_cast((static_cast(v[current_idx + 1]) << 030) + + (static_cast(v[current_idx + 2]) << 020) + + (static_cast(v[current_idx + 3]) << 010) + + static_cast(v[current_idx + 4])); + } + else if (v[current_idx] == 0xcf) // uint 64 + { + idx += 8; // skip 8 content bytes + return static_cast((static_cast(v[current_idx + 1]) << 070) + + (static_cast(v[current_idx + 2]) << 060) + + (static_cast(v[current_idx + 3]) << 050) + + (static_cast(v[current_idx + 4]) << 040) + + (static_cast(v[current_idx + 5]) << 030) + + (static_cast(v[current_idx + 6]) << 020) + + (static_cast(v[current_idx + 7]) << 010) + + static_cast(v[current_idx + 8])); + } + else if (v[current_idx] == 0xd0) // int 8 + { + idx += 1; // skip content byte + return static_cast(v[current_idx + 1]); + } + else if (v[current_idx] == 0xd1) // int 16 + { + idx += 2; // skip 2 content bytes + return static_cast((static_cast(v[current_idx + 1]) << 010) + + static_cast(v[current_idx + 2])); + } + else if (v[current_idx] == 0xd2) // int 32 + { + idx += 4; // skip 4 content bytes + return static_cast((static_cast(v[current_idx + 1]) << 030) + + (static_cast(v[current_idx + 2]) << 020) + + (static_cast(v[current_idx + 3]) << 010) + + static_cast(v[current_idx + 4])); + } + else if (v[current_idx] == 0xd3) // int 64 + { + idx += 8; // skip 8 content bytes + return static_cast((static_cast(v[current_idx + 1]) << 070) + + (static_cast(v[current_idx + 2]) << 060) + + (static_cast(v[current_idx + 3]) << 050) + + (static_cast(v[current_idx + 4]) << 040) + + (static_cast(v[current_idx + 5]) << 030) + + (static_cast(v[current_idx + 6]) << 020) + + (static_cast(v[current_idx + 7]) << 010) + + static_cast(v[current_idx + 8])); + } + else if (v[current_idx] >= 0xd4 and v[current_idx] <= 0xd8) // fixext + { + throw std::invalid_argument("bin/ext are not supported @ " + std::to_string(current_idx)); + } + else if (v[current_idx] == 0xd9) // str 8 + { + const size_t len = v[current_idx + 1]; + const size_t offset = current_idx + 2; + idx += len + 1; // skip size byte + content bytes + return std::string(reinterpret_cast(v.data()) + offset, len); + } + else if (v[current_idx] == 0xda) // str 16 + { + const size_t len = static_cast((v[current_idx + 1] << 010) + v[current_idx + 2]); + const size_t offset = current_idx + 3; + idx += len + 2; // skip 2 size bytes + content bytes + return std::string(reinterpret_cast(v.data()) + offset, len); + } + else if (v[current_idx] == 0xdb) // str 32 + { + const size_t len = static_cast((v[current_idx + 1] << 030) + + (v[current_idx + 2] << 020) + + (v[current_idx + 3] << 010) + + v[current_idx + 4]); + const size_t offset = current_idx + 5; + idx += len + 4; // skip 4 size bytes + content bytes + return std::string(reinterpret_cast(v.data()) + offset, len); + } + else if (v[current_idx] == 0xdc) // array 16 + { + basic_json result = value_t::array; + const size_t len = static_cast((v[current_idx + 1] << 010) + + v[current_idx + 2]); + idx += 2; // skip 2 size bytes + for (size_t i = 0; i < len; ++i) + { + result.push_back(from_msgpack_internal(v, idx)); + } + return result; + } + else if (v[current_idx] == 0xdd) // array 32 + { + basic_json result = value_t::array; + const size_t len = static_cast((v[current_idx + 1] << 030) + + (v[current_idx + 2] << 020) + + (v[current_idx + 3] << 010) + + v[current_idx + 4]); + idx += 4; // skip 4 size bytes + for (size_t i = 0; i < len; ++i) + { + result.push_back(from_msgpack_internal(v, idx)); + } + return result; + } + else if (v[current_idx] == 0xde) // map 16 + { + basic_json result = value_t::object; + const size_t len = static_cast((v[current_idx + 1] << 010) + + v[current_idx + 2]); + idx += 2; // skip 2 size bytes + for (size_t i = 0; i < len; ++i) + { + std::string key = from_msgpack_internal(v, idx); + result[key] = from_msgpack_internal(v, idx); + } + return result; + } + else if (v[current_idx] == 0xdf) // map 32 + { + basic_json result = value_t::object; + const size_t len = static_cast((v[current_idx + 1] << 030) + + (v[current_idx + 2] << 020) + + (v[current_idx + 3] << 010) + + v[current_idx + 4]); + idx += 4; // skip 4 size bytes + for (size_t i = 0; i < len; ++i) + { + std::string key = from_msgpack_internal(v, idx); + result[key] = from_msgpack_internal(v, idx); + } + return result; + } + else if (v[current_idx] >= 0xe0) // negative fixint + { + return static_cast(v[current_idx]); + } + + throw std::invalid_argument("error parsing a msgpack @ " + std::to_string(current_idx)); + } + + public: + /*! + @param[in] j JSON value to serialize + @retuen MessagePack serialization as char vector + */ + static std::vector to_msgpack(const basic_json& j) + { + std::vector result; + to_msgpack_internal(j, result); + return result; + } + + static basic_json from_msgpack(const std::vector& v) + { + size_t i = 0; + return from_msgpack_internal(v, i); + } + + /// @} private: /////////////////////////// diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index b829889d5..59113ffbd 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -6142,6 +6142,499 @@ class basic_json /// @} + ///////////////////////// + // MessagePack support // + ///////////////////////// + + /// @name MessagePack support + /// @{ + + private: + static void to_msgpack_internal(const basic_json& j, std::vector& v) + { + switch (j.type()) + { + case value_t::null: + { + // nil + v.push_back(0xc0); + break; + } + + case value_t::boolean: + { + // true and false + v.push_back(j.m_value.boolean ? 0xc3 : 0xc2); + break; + } + + case value_t::number_integer: + { + if (j.m_value.number_integer >= -32 and j.m_value.number_integer < 128) + { + // negative fixnum and positive fixnum + v.push_back(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer >= INT8_MIN and j.m_value.number_integer <= INT8_MAX) + { + // int 8 + v.push_back(0xd0); + v.push_back(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer >= INT16_MIN and j.m_value.number_integer <= INT16_MAX) + { + // int 16 + v.push_back(0xd1); + v.push_back(static_cast((j.m_value.number_integer >> 010) & 0xff)); + v.push_back(static_cast(j.m_value.number_integer & 0xff)); + } + else if (j.m_value.number_integer >= INT32_MIN and j.m_value.number_integer <= INT32_MAX) + { + // int 32 + v.push_back(0xd2); + v.push_back(static_cast((j.m_value.number_integer >> 030) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 020) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 010) & 0xff)); + v.push_back(static_cast(j.m_value.number_integer & 0xff)); + } + else if (j.m_value.number_integer >= INT64_MIN and j.m_value.number_integer <= INT64_MAX) + { + // int 64 + v.push_back(0xd3); + v.push_back(static_cast((j.m_value.number_integer >> 070) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 060) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 050) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 040) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 030) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 020) & 0xff)); + v.push_back(static_cast((j.m_value.number_integer >> 010) & 0xff)); + v.push_back(static_cast(j.m_value.number_integer & 0xff)); + } + break; + } + + case value_t::number_unsigned: + { + if (j.m_value.number_unsigned < 128) + { + // positive fixnum + v.push_back(static_cast(j.m_value.number_unsigned)); + } + else if (j.m_value.number_unsigned <= UINT8_MAX) + { + // uint 8 + v.push_back(0xcc); + v.push_back(static_cast(j.m_value.number_unsigned)); + } + else if (j.m_value.number_unsigned <= UINT16_MAX) + { + // uint 16 + v.push_back(0xcd); + v.push_back(static_cast((j.m_value.number_unsigned >> 010) & 0xff)); + v.push_back(static_cast(j.m_value.number_unsigned & 0xff)); + } + else if (j.m_value.number_unsigned <= UINT32_MAX) + { + // uint 32 + v.push_back(0xce); + v.push_back(static_cast((j.m_value.number_unsigned >> 030) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 020) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 010) & 0xff)); + v.push_back(static_cast(j.m_value.number_unsigned & 0xff)); + } + else if (j.m_value.number_unsigned <= UINT64_MAX) + { + // uint 64 + v.push_back(0xcf); + v.push_back(static_cast((j.m_value.number_unsigned >> 070) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 060) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 050) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 040) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 030) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 020) & 0xff)); + v.push_back(static_cast((j.m_value.number_unsigned >> 010) & 0xff)); + v.push_back(static_cast(j.m_value.number_unsigned & 0xff)); + } + break; + } + + case value_t::number_float: + { + // float 64 + v.push_back(0xcb); + const uint8_t* helper = reinterpret_cast(&(j.m_value.number_float)); + for (size_t i = 0; i < 8; ++i) + { + v.push_back(helper[7 - i]); + } + break; + } + + case value_t::string: + { + const auto N = j.m_value.string->size(); + if (N <= 31) + { + // fixstr + v.push_back(static_cast(0xa0 | N)); + } + else if (N <= 255) + { + // str 8 + v.push_back(0xd9); + v.push_back(static_cast(N)); + } + else if (N <= 65535) + { + // str 16 + v.push_back(0xda); + v.push_back(static_cast((N >> 010) & 0xff)); + v.push_back(static_cast(N & 0xff)); + } + else if (N <= 4294967295) + { + // str 32 + v.push_back(0xdb); + v.push_back(static_cast((N >> 030) & 0xff)); + v.push_back(static_cast((N >> 020) & 0xff)); + v.push_back(static_cast((N >> 010) & 0xff)); + v.push_back(static_cast(N & 0xff)); + } + + // append string + std::copy(j.m_value.string->begin(), j.m_value.string->end(), + std::back_inserter(v)); + break; + } + + case value_t::array: + { + const auto N = j.m_value.array->size(); + if (N <= 15) + { + // fixarray + v.push_back(static_cast(0x90 | N)); + } + else if (N <= 0xffff) + { + // array 16 + v.push_back(0xdc); + v.push_back(static_cast((N >> 010) & 0xff)); + v.push_back(static_cast(N & 0xff)); + } + else if (N <= 0xffffffff) + { + // array 32 + v.push_back(0xdd); + v.push_back(static_cast((N >> 030) & 0xff)); + v.push_back(static_cast((N >> 020) & 0xff)); + v.push_back(static_cast((N >> 010) & 0xff)); + v.push_back(static_cast(N & 0xff)); + } + + // append each element + for (const auto& el : *j.m_value.array) + { + to_msgpack_internal(el, v); + } + break; + } + + case value_t::object: + { + const auto N = j.m_value.object->size(); + if (N <= 15) + { + // fixmap + v.push_back(static_cast(0x80 | (N & 0xf))); + } + else if (N <= 65535) + { + // map 16 + v.push_back(0xde); + v.push_back(static_cast((N >> 010) & 0xff)); + v.push_back(static_cast(N & 0xff)); + } + else if (N <= 4294967295) + { + // map 32 + v.push_back(0xdf); + v.push_back(static_cast((N >> 030) & 0xff)); + v.push_back(static_cast((N >> 020) & 0xff)); + v.push_back(static_cast((N >> 010) & 0xff)); + v.push_back(static_cast(N & 0xff)); + } + + // append each element + for (const auto& el : *j.m_value.object) + { + to_msgpack_internal(el.first, v); + to_msgpack_internal(el.second, v); + } + break; + } + + default: + { + break; + } + } + } + + /*! + @param[in] v MessagePack serialization + @param[in] idx byte index to start reading from @a v + */ + static basic_json from_msgpack_internal(const std::vector& v, size_t& idx) + { + // store and increment index + const size_t current_idx = idx++; + + if (v[current_idx] <= 0x7f) // positive fixint + { + return v[current_idx]; + } + else if (v[current_idx] <= 0x8f) // fixmap + { + basic_json result = value_t::object; + const size_t len = v[current_idx] & 0x0f; + for (size_t i = 0; i < len; ++i) + { + std::string key = from_msgpack_internal(v, idx); + result[key] = from_msgpack_internal(v, idx); + } + return result; + } + else if (v[current_idx] <= 0x9f) // fixarray + { + basic_json result = value_t::array; + const size_t len = v[current_idx] & 0x0f; + for (size_t i = 0; i < len; ++i) + { + result.push_back(from_msgpack_internal(v, idx)); + } + return result; + } + else if (v[current_idx] <= 0xbf) // fixstr + { + const size_t len = v[current_idx] & 0x1f; + const size_t offset = current_idx + 1; + idx += len; // skip content bytes + return std::string(reinterpret_cast(v.data()) + offset, len); + } + else if (v[current_idx] == 0xc0) // nil + { + return value_t::null; + } + else if (v[current_idx] == 0xc1) // never used + { + throw std::invalid_argument("value 0x31 must not be used@ " + std::to_string(current_idx)); + } + else if (v[current_idx] == 0xc2) // false + { + return false; + } + else if (v[current_idx] == 0xc3) // true + { + return true; + } + else if (v[current_idx] >= 0xc4 and v[current_idx] <= 0xc9) // bin/ext + { + throw std::invalid_argument("bin/ext are not supported @ " + std::to_string(current_idx)); + } + else if (v[current_idx] == 0xca) // float 32 + { + // copy bytes in reverse order into the double variable + float res; + for (size_t byte = 0; byte < sizeof(float); ++byte) + { + reinterpret_cast(&res)[sizeof(float) - byte - 1] = v[current_idx + 1 + byte]; + } + idx += sizeof(float); // skip content bytes + return res; + } + else if (v[current_idx] == 0xcb) // float 64 + { + // copy bytes in reverse order into the double variable + double res; + for (size_t byte = 0; byte < sizeof(double); ++byte) + { + reinterpret_cast(&res)[sizeof(double) - byte - 1] = v[current_idx + 1 + byte]; + } + idx += sizeof(double); // skip content bytes + return res; + } + else if (v[current_idx] == 0xcc) // uint 8 + { + idx += 1; // skip content byte + return v[current_idx + 1]; + } + else if (v[current_idx] == 0xcd) // uint 16 + { + idx += 2; // skip 2 content bytes + return static_cast((static_cast(v[current_idx + 1]) << 010) + + static_cast(v[current_idx + 2])); + } + else if (v[current_idx] == 0xce) // uint 32 + { + idx += 4; // skip 4 content bytes + return static_cast((static_cast(v[current_idx + 1]) << 030) + + (static_cast(v[current_idx + 2]) << 020) + + (static_cast(v[current_idx + 3]) << 010) + + static_cast(v[current_idx + 4])); + } + else if (v[current_idx] == 0xcf) // uint 64 + { + idx += 8; // skip 8 content bytes + return static_cast((static_cast(v[current_idx + 1]) << 070) + + (static_cast(v[current_idx + 2]) << 060) + + (static_cast(v[current_idx + 3]) << 050) + + (static_cast(v[current_idx + 4]) << 040) + + (static_cast(v[current_idx + 5]) << 030) + + (static_cast(v[current_idx + 6]) << 020) + + (static_cast(v[current_idx + 7]) << 010) + + static_cast(v[current_idx + 8])); + } + else if (v[current_idx] == 0xd0) // int 8 + { + idx += 1; // skip content byte + return static_cast(v[current_idx + 1]); + } + else if (v[current_idx] == 0xd1) // int 16 + { + idx += 2; // skip 2 content bytes + return static_cast((static_cast(v[current_idx + 1]) << 010) + + static_cast(v[current_idx + 2])); + } + else if (v[current_idx] == 0xd2) // int 32 + { + idx += 4; // skip 4 content bytes + return static_cast((static_cast(v[current_idx + 1]) << 030) + + (static_cast(v[current_idx + 2]) << 020) + + (static_cast(v[current_idx + 3]) << 010) + + static_cast(v[current_idx + 4])); + } + else if (v[current_idx] == 0xd3) // int 64 + { + idx += 8; // skip 8 content bytes + return static_cast((static_cast(v[current_idx + 1]) << 070) + + (static_cast(v[current_idx + 2]) << 060) + + (static_cast(v[current_idx + 3]) << 050) + + (static_cast(v[current_idx + 4]) << 040) + + (static_cast(v[current_idx + 5]) << 030) + + (static_cast(v[current_idx + 6]) << 020) + + (static_cast(v[current_idx + 7]) << 010) + + static_cast(v[current_idx + 8])); + } + else if (v[current_idx] >= 0xd4 and v[current_idx] <= 0xd8) // fixext + { + throw std::invalid_argument("bin/ext are not supported @ " + std::to_string(current_idx)); + } + else if (v[current_idx] == 0xd9) // str 8 + { + const size_t len = v[current_idx + 1]; + const size_t offset = current_idx + 2; + idx += len + 1; // skip size byte + content bytes + return std::string(reinterpret_cast(v.data()) + offset, len); + } + else if (v[current_idx] == 0xda) // str 16 + { + const size_t len = static_cast((v[current_idx + 1] << 010) + v[current_idx + 2]); + const size_t offset = current_idx + 3; + idx += len + 2; // skip 2 size bytes + content bytes + return std::string(reinterpret_cast(v.data()) + offset, len); + } + else if (v[current_idx] == 0xdb) // str 32 + { + const size_t len = static_cast((v[current_idx + 1] << 030) + + (v[current_idx + 2] << 020) + + (v[current_idx + 3] << 010) + + v[current_idx + 4]); + const size_t offset = current_idx + 5; + idx += len + 4; // skip 4 size bytes + content bytes + return std::string(reinterpret_cast(v.data()) + offset, len); + } + else if (v[current_idx] == 0xdc) // array 16 + { + basic_json result = value_t::array; + const size_t len = static_cast((v[current_idx + 1] << 010) + + v[current_idx + 2]); + idx += 2; // skip 2 size bytes + for (size_t i = 0; i < len; ++i) + { + result.push_back(from_msgpack_internal(v, idx)); + } + return result; + } + else if (v[current_idx] == 0xdd) // array 32 + { + basic_json result = value_t::array; + const size_t len = static_cast((v[current_idx + 1] << 030) + + (v[current_idx + 2] << 020) + + (v[current_idx + 3] << 010) + + v[current_idx + 4]); + idx += 4; // skip 4 size bytes + for (size_t i = 0; i < len; ++i) + { + result.push_back(from_msgpack_internal(v, idx)); + } + return result; + } + else if (v[current_idx] == 0xde) // map 16 + { + basic_json result = value_t::object; + const size_t len = static_cast((v[current_idx + 1] << 010) + + v[current_idx + 2]); + idx += 2; // skip 2 size bytes + for (size_t i = 0; i < len; ++i) + { + std::string key = from_msgpack_internal(v, idx); + result[key] = from_msgpack_internal(v, idx); + } + return result; + } + else if (v[current_idx] == 0xdf) // map 32 + { + basic_json result = value_t::object; + const size_t len = static_cast((v[current_idx + 1] << 030) + + (v[current_idx + 2] << 020) + + (v[current_idx + 3] << 010) + + v[current_idx + 4]); + idx += 4; // skip 4 size bytes + for (size_t i = 0; i < len; ++i) + { + std::string key = from_msgpack_internal(v, idx); + result[key] = from_msgpack_internal(v, idx); + } + return result; + } + else if (v[current_idx] >= 0xe0) // negative fixint + { + return static_cast(v[current_idx]); + } + + throw std::invalid_argument("error parsing a msgpack @ " + std::to_string(current_idx)); + } + + public: + /*! + @param[in] j JSON value to serialize + @retuen MessagePack serialization as char vector + */ + static std::vector to_msgpack(const basic_json& j) + { + std::vector result; + to_msgpack_internal(j, result); + return result; + } + + static basic_json from_msgpack(const std::vector& v) + { + size_t i = 0; + return from_msgpack_internal(v, i); + } + + /// @} private: /////////////////////////// @@ -7802,6 +8295,7 @@ class basic_json re2c:define:YYMARKER = m_marker; re2c:define:YYFILL = "fill_line_buffer(@@); // LCOV_EXCL_LINE"; re2c:define:YYFILL:naked = 1; + re2c:yyfill:enable = 1; re2c:indent:string = " "; re2c:indent:top = 1; re2c:labelprefix = "basic_json_parser_"; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 782d5b53f..cf9f5f453 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,6 +26,7 @@ add_executable(${JSON_UNITTEST_TARGET_NAME} "src/unit-json_patch.cpp" "src/unit-json_pointer.cpp" "src/unit-modifiers.cpp" + "src/unit-msgpack.cpp" "src/unit-pointer_access.cpp" "src/unit-readme.cpp" "src/unit-reference_access.cpp" diff --git a/test/Makefile b/test/Makefile index ead1f0738..0f695a536 100644 --- a/test/Makefile +++ b/test/Makefile @@ -30,6 +30,7 @@ SOURCES = src/unit.cpp \ src/unit-json_patch.cpp \ src/unit-json_pointer.cpp \ src/unit-modifiers.cpp \ + src/unit-msgpack.cpp \ src/unit-pointer_access.cpp \ src/unit-readme.cpp \ src/unit-reference_access.cpp \ diff --git a/test/data/json.org/1.json.msgpack b/test/data/json.org/1.json.msgpack new file mode 100644 index 000000000..726875ce0 Binary files /dev/null and b/test/data/json.org/1.json.msgpack differ diff --git a/test/data/json.org/2.json.msgpack b/test/data/json.org/2.json.msgpack new file mode 100644 index 000000000..3321e1e22 --- /dev/null +++ b/test/data/json.org/2.json.msgpack @@ -0,0 +1 @@ +menupopupmenuitemonclickCreateNewDoc()valueNewonclickOpenDoc()valueOpenonclickCloseDoc()valueCloseidfilevalueFile \ No newline at end of file diff --git a/test/data/json.org/3.json.msgpack b/test/data/json.org/3.json.msgpack new file mode 100644 index 000000000..e261cd5f2 Binary files /dev/null and b/test/data/json.org/3.json.msgpack differ diff --git a/test/data/json.org/4.json.msgpack b/test/data/json.org/4.json.msgpack new file mode 100644 index 000000000..587c0affe Binary files /dev/null and b/test/data/json.org/4.json.msgpack differ diff --git a/test/data/json.org/5.json.msgpack b/test/data/json.org/5.json.msgpack new file mode 100644 index 000000000..cc70155e4 Binary files /dev/null and b/test/data/json.org/5.json.msgpack differ diff --git a/test/data/json_nlohmann_tests/all_unicode.json.msgpack b/test/data/json_nlohmann_tests/all_unicode.json.msgpack new file mode 100644 index 000000000..b02431685 Binary files /dev/null and b/test/data/json_nlohmann_tests/all_unicode.json.msgpack differ diff --git a/test/data/json_roundtrip/roundtrip01.json.msgpack b/test/data/json_roundtrip/roundtrip01.json.msgpack new file mode 100644 index 000000000..37932dfb2 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip01.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip02.json.msgpack b/test/data/json_roundtrip/roundtrip02.json.msgpack new file mode 100644 index 000000000..52b4164b2 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip02.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip03.json.msgpack b/test/data/json_roundtrip/roundtrip03.json.msgpack new file mode 100644 index 000000000..ea5929828 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip03.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip04.json.msgpack b/test/data/json_roundtrip/roundtrip04.json.msgpack new file mode 100644 index 000000000..5b8551b19 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip04.json.msgpack differ diff --git a/test/data/json_roundtrip/roundtrip05.json.msgpack b/test/data/json_roundtrip/roundtrip05.json.msgpack new file mode 100644 index 000000000..fed9247b0 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip05.json.msgpack @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip06.json.msgpack b/test/data/json_roundtrip/roundtrip06.json.msgpack new file mode 100644 index 000000000..9e99dd5ec --- /dev/null +++ b/test/data/json_roundtrip/roundtrip06.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip07.json.msgpack b/test/data/json_roundtrip/roundtrip07.json.msgpack new file mode 100644 index 000000000..5416677bc --- /dev/null +++ b/test/data/json_roundtrip/roundtrip07.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip08.json.msgpack b/test/data/json_roundtrip/roundtrip08.json.msgpack new file mode 100644 index 000000000..b361f804d Binary files /dev/null and b/test/data/json_roundtrip/roundtrip08.json.msgpack differ diff --git a/test/data/json_roundtrip/roundtrip09.json.msgpack b/test/data/json_roundtrip/roundtrip09.json.msgpack new file mode 100644 index 000000000..5ace8ec1b --- /dev/null +++ b/test/data/json_roundtrip/roundtrip09.json.msgpack @@ -0,0 +1 @@ +foobar \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip10.json.msgpack b/test/data/json_roundtrip/roundtrip10.json.msgpack new file mode 100644 index 000000000..f9791c10d --- /dev/null +++ b/test/data/json_roundtrip/roundtrip10.json.msgpack @@ -0,0 +1 @@ +afoobar \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip11.json.msgpack b/test/data/json_roundtrip/roundtrip11.json.msgpack new file mode 100644 index 000000000..97689a4d7 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip11.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip12.json.msgpack b/test/data/json_roundtrip/roundtrip12.json.msgpack new file mode 100644 index 000000000..d523c4adc Binary files /dev/null and b/test/data/json_roundtrip/roundtrip12.json.msgpack differ diff --git a/test/data/json_roundtrip/roundtrip13.json.msgpack b/test/data/json_roundtrip/roundtrip13.json.msgpack new file mode 100644 index 000000000..5b19d3e76 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip13.json.msgpack @@ -0,0 +1 @@ + ~ \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip14.json.msgpack b/test/data/json_roundtrip/roundtrip14.json.msgpack new file mode 100644 index 000000000..4b87c841c Binary files /dev/null and b/test/data/json_roundtrip/roundtrip14.json.msgpack differ diff --git a/test/data/json_roundtrip/roundtrip15.json.msgpack b/test/data/json_roundtrip/roundtrip15.json.msgpack new file mode 100644 index 000000000..0ad68ffd7 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip15.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip16.json.msgpack b/test/data/json_roundtrip/roundtrip16.json.msgpack new file mode 100644 index 000000000..199e499e3 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip16.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip17.json.msgpack b/test/data/json_roundtrip/roundtrip17.json.msgpack new file mode 100644 index 000000000..7e2a95585 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip17.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip18.json.msgpack b/test/data/json_roundtrip/roundtrip18.json.msgpack new file mode 100644 index 000000000..a24c12b20 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip18.json.msgpack @@ -0,0 +1 @@ +"} \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip19.json.msgpack b/test/data/json_roundtrip/roundtrip19.json.msgpack new file mode 100644 index 000000000..670c19302 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip19.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip20.json.msgpack b/test/data/json_roundtrip/roundtrip20.json.msgpack new file mode 100644 index 000000000..c4b7acf67 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip20.json.msgpack differ diff --git a/test/data/json_roundtrip/roundtrip21.json.msgpack b/test/data/json_roundtrip/roundtrip21.json.msgpack new file mode 100644 index 000000000..ebe72a0f8 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip21.json.msgpack differ diff --git a/test/data/json_roundtrip/roundtrip22.json.msgpack b/test/data/json_roundtrip/roundtrip22.json.msgpack new file mode 100644 index 000000000..bb8b079bd --- /dev/null +++ b/test/data/json_roundtrip/roundtrip22.json.msgpack @@ -0,0 +1 @@ +?n \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip23.json.msgpack b/test/data/json_roundtrip/roundtrip23.json.msgpack new file mode 100644 index 000000000..76ac4194a --- /dev/null +++ b/test/data/json_roundtrip/roundtrip23.json.msgpack @@ -0,0 +1 @@ +˿n \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip24.json.msgpack b/test/data/json_roundtrip/roundtrip24.json.msgpack new file mode 100644 index 000000000..f5bf071b3 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip24.json.msgpack differ diff --git a/test/data/json_roundtrip/roundtrip25.json.msgpack b/test/data/json_roundtrip/roundtrip25.json.msgpack new file mode 100644 index 000000000..c45fb0480 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip25.json.msgpack differ diff --git a/test/data/json_roundtrip/roundtrip26.json.msgpack b/test/data/json_roundtrip/roundtrip26.json.msgpack new file mode 100644 index 000000000..0a6b0373e Binary files /dev/null and b/test/data/json_roundtrip/roundtrip26.json.msgpack differ diff --git a/test/data/json_roundtrip/roundtrip27.json.msgpack b/test/data/json_roundtrip/roundtrip27.json.msgpack new file mode 100644 index 000000000..5f03c199c --- /dev/null +++ b/test/data/json_roundtrip/roundtrip27.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip28.json.msgpack b/test/data/json_roundtrip/roundtrip28.json.msgpack new file mode 100644 index 000000000..f5bf071b3 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip28.json.msgpack differ diff --git a/test/data/json_roundtrip/roundtrip29.json.msgpack b/test/data/json_roundtrip/roundtrip29.json.msgpack new file mode 100644 index 000000000..b1ef60a80 Binary files /dev/null and b/test/data/json_roundtrip/roundtrip29.json.msgpack differ diff --git a/test/data/json_roundtrip/roundtrip30.json.msgpack b/test/data/json_roundtrip/roundtrip30.json.msgpack new file mode 100644 index 000000000..4362c4c59 --- /dev/null +++ b/test/data/json_roundtrip/roundtrip30.json.msgpack @@ -0,0 +1 @@ +9  \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip31.json.msgpack b/test/data/json_roundtrip/roundtrip31.json.msgpack new file mode 100644 index 000000000..e4d9e9a0d --- /dev/null +++ b/test/data/json_roundtrip/roundtrip31.json.msgpack @@ -0,0 +1 @@ +F/)U \ No newline at end of file diff --git a/test/data/json_roundtrip/roundtrip32.json.msgpack b/test/data/json_roundtrip/roundtrip32.json.msgpack new file mode 100644 index 000000000..e4d9e9a0d --- /dev/null +++ b/test/data/json_roundtrip/roundtrip32.json.msgpack @@ -0,0 +1 @@ +F/)U \ No newline at end of file diff --git a/test/data/json_tests/pass1.json.msgpack b/test/data/json_tests/pass1.json.msgpack new file mode 100644 index 000000000..6b1e7315e Binary files /dev/null and b/test/data/json_tests/pass1.json.msgpack differ diff --git a/test/data/json_tests/pass2.json.msgpack b/test/data/json_tests/pass2.json.msgpack new file mode 100644 index 000000000..336ce90e2 --- /dev/null +++ b/test/data/json_tests/pass2.json.msgpack @@ -0,0 +1 @@ +Not too deep \ No newline at end of file diff --git a/test/data/json_tests/pass3.json.msgpack b/test/data/json_tests/pass3.json.msgpack new file mode 100644 index 000000000..aee42364d --- /dev/null +++ b/test/data/json_tests/pass3.json.msgpack @@ -0,0 +1 @@ +JSON Test Pattern pass3In this testIt is an object.The outermost valuemust be an object or array. \ No newline at end of file diff --git a/test/data/json_testsuite/sample.json.msgpack b/test/data/json_testsuite/sample.json.msgpack new file mode 100644 index 000000000..e1338ddcc Binary files /dev/null and b/test/data/json_testsuite/sample.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json.msgpack new file mode 100644 index 000000000..df3dff583 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_array_empty-string.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_array_empty-string.json.msgpack new file mode 100644 index 000000000..f8569fa68 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_array_empty-string.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_array_empty.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_array_empty.json.msgpack new file mode 100644 index 000000000..9e99dd5ec --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_array_empty.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json.msgpack new file mode 100644 index 000000000..42f268668 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json.msgpack @@ -0,0 +1 @@ +a \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_array_false.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_array_false.json.msgpack new file mode 100644 index 000000000..ea5929828 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_array_false.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_array_heterogeneous.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_array_heterogeneous.json.msgpack new file mode 100644 index 000000000..ef5e47a79 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_array_heterogeneous.json.msgpack @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_array_null.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_array_null.json.msgpack new file mode 100644 index 000000000..37932dfb2 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_array_null.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json.msgpack new file mode 100644 index 000000000..0ad68ffd7 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_array_with_leading_space.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_array_with_leading_space.json.msgpack new file mode 100644 index 000000000..0ad68ffd7 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_array_with_leading_space.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_array_with_several_null.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_array_with_several_null.json.msgpack new file mode 100644 index 000000000..dd22b5cce --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_array_with_several_null.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json.msgpack new file mode 100644 index 000000000..9dee29f18 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_number.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number.json.msgpack new file mode 100644 index 000000000..d8016f82b --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_number.json.msgpack @@ -0,0 +1 @@ +M22X \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_0e+1.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_0e+1.json.msgpack new file mode 100644 index 000000000..c4b7acf67 Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_0e+1.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_0e1.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_0e1.json.msgpack new file mode 100644 index 000000000..c4b7acf67 Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_0e1.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_after_space.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_after_space.json.msgpack new file mode 100644 index 000000000..49199835b --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_number_after_space.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json.msgpack new file mode 100644 index 000000000..22b702650 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json.msgpack @@ -0,0 +1 @@ +˯h \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json.msgpack new file mode 100644 index 000000000..c4b7acf67 Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_huge_exp.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_huge_exp.json.msgpack new file mode 100644 index 000000000..59db48b4a Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_huge_exp.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_int_with_exp.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_int_with_exp.json.msgpack new file mode 100644 index 000000000..6560b32f5 Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_int_with_exp.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_minus_zero.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_minus_zero.json.msgpack new file mode 100644 index 000000000..5b8551b19 Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_minus_zero.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_negative_int.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_negative_int.json.msgpack new file mode 100644 index 000000000..8da6fb98f --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_number_negative_int.json.msgpack @@ -0,0 +1 @@ +Ѕ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_negative_one.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_negative_one.json.msgpack new file mode 100644 index 000000000..97689a4d7 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_number_negative_one.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_negative_zero.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_negative_zero.json.msgpack new file mode 100644 index 000000000..5b8551b19 Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_negative_zero.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e.json.msgpack new file mode 100644 index 000000000..579cf7d2f --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e.json.msgpack @@ -0,0 +1 @@ +DMՒ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json.msgpack new file mode 100644 index 000000000..3ac2971ea --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json.msgpack @@ -0,0 +1 @@ +?zG{ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json.msgpack new file mode 100644 index 000000000..34ba122ca Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_real_exponent.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_real_exponent.json.msgpack new file mode 100644 index 000000000..7c1cc3719 Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_real_exponent.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json.msgpack new file mode 100644 index 000000000..ec7fe04fb --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json.msgpack @@ -0,0 +1 @@ +PO§ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json.msgpack new file mode 100644 index 000000000..3ac2971ea --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json.msgpack @@ -0,0 +1 @@ +?zG{ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json.msgpack new file mode 100644 index 000000000..1398605d0 Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json.msgpack new file mode 100644 index 000000000..34ba122ca Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json.msgpack new file mode 100644 index 000000000..59db48b4a Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_real_underflow.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_real_underflow.json.msgpack new file mode 100644 index 000000000..c4b7acf67 Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_number_real_underflow.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_simple_int.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_simple_int.json.msgpack new file mode 100644 index 000000000..d3ae4d8ba --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_number_simple_int.json.msgpack @@ -0,0 +1 @@ +{ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_number_simple_real.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_number_simple_real.json.msgpack new file mode 100644 index 000000000..09dcbc689 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_number_simple_real.json.msgpack @@ -0,0 +1 @@ +@^< \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_object.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_object.json.msgpack new file mode 100644 index 000000000..e902e95a0 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_object.json.msgpack @@ -0,0 +1 @@ +dfgfghasdsdf \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_object_basic.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_object_basic.json.msgpack new file mode 100644 index 000000000..8c89ddbf8 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_object_basic.json.msgpack @@ -0,0 +1 @@ +asdsdf \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_object_duplicated_key.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_object_duplicated_key.json.msgpack new file mode 100644 index 000000000..e82b9382b --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_object_duplicated_key.json.msgpack @@ -0,0 +1 @@ +ac \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json.msgpack new file mode 100644 index 000000000..12507c1c0 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json.msgpack @@ -0,0 +1 @@ +ab \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_object_empty.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_object_empty.json.msgpack new file mode 100644 index 000000000..5416677bc --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_object_empty.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_object_empty_key.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_object_empty_key.json.msgpack new file mode 100644 index 000000000..c89d18f73 Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_object_empty_key.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json.msgpack new file mode 100644 index 000000000..01069217d Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json.msgpack new file mode 100644 index 000000000..5f9299b21 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json.msgpack @@ -0,0 +1 @@ +maxE'/min'/ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_object_long_strings.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_object_long_strings.json.msgpack new file mode 100644 index 000000000..6c9909587 Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_object_long_strings.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_object_simple.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_object_simple.json.msgpack new file mode 100644 index 000000000..704d8df64 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_object_simple.json.msgpack @@ -0,0 +1 @@ +a \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_object_string_unicode.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_object_string_unicode.json.msgpack new file mode 100644 index 000000000..540f238ff Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_object_string_unicode.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_object_with_newlines.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_object_with_newlines.json.msgpack new file mode 100644 index 000000000..12507c1c0 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_object_with_newlines.json.msgpack @@ -0,0 +1 @@ +ab \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json.msgpack new file mode 100644 index 000000000..612152f93 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json.msgpack @@ -0,0 +1 @@ +`Īካ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json.msgpack new file mode 100644 index 000000000..a8d174a73 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json.msgpack @@ -0,0 +1 @@ +𝄞 \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json.msgpack new file mode 100644 index 000000000..7d0b6e45a --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json.msgpack @@ -0,0 +1 @@ +𐐷 \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json.msgpack new file mode 100644 index 000000000..72009e827 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json.msgpack @@ -0,0 +1 @@ +😹💍 \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json.msgpack new file mode 100644 index 000000000..017114bc8 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json.msgpack @@ -0,0 +1,2 @@ +"\/ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json.msgpack new file mode 100644 index 000000000..c4bab4321 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json.msgpack @@ -0,0 +1 @@ +\u0000 \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json.msgpack new file mode 100644 index 000000000..daab159ff --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json.msgpack @@ -0,0 +1 @@ +" \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_comments.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_comments.json.msgpack new file mode 100644 index 000000000..5364f2ce4 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_comments.json.msgpack @@ -0,0 +1 @@ +a/*b*/c/*d//e \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_double_escape_a.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_double_escape_a.json.msgpack new file mode 100644 index 000000000..ea41d0561 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_double_escape_a.json.msgpack @@ -0,0 +1 @@ +\a \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_double_escape_n.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_double_escape_n.json.msgpack new file mode 100644 index 000000000..327cf1ffc --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_double_escape_n.json.msgpack @@ -0,0 +1 @@ +\n \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json.msgpack new file mode 100644 index 000000000..8954efe5c --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json.msgpack new file mode 100644 index 000000000..80e7452fe --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json.msgpack @@ -0,0 +1 @@ +￿ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_in_array.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_in_array.json.msgpack new file mode 100644 index 000000000..1788db3c8 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_in_array.json.msgpack @@ -0,0 +1 @@ +asd \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json.msgpack new file mode 100644 index 000000000..1788db3c8 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json.msgpack @@ -0,0 +1 @@ +asd \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json.msgpack new file mode 100644 index 000000000..39a157ee5 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json.msgpack @@ -0,0 +1 @@ +􏿿 \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json.msgpack new file mode 100644 index 000000000..84ccc51db --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json.msgpack @@ -0,0 +1 @@ +new line \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json.msgpack new file mode 100644 index 000000000..39a157ee5 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json.msgpack @@ -0,0 +1 @@ +􏿿 \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json.msgpack new file mode 100644 index 000000000..19b98bd2a --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json.msgpack @@ -0,0 +1 @@ +𛿿 \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json.msgpack new file mode 100644 index 000000000..80e7452fe --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json.msgpack @@ -0,0 +1 @@ +￿ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_null_escape.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_null_escape.json.msgpack new file mode 100644 index 000000000..3c8ba669b Binary files /dev/null and b/test/data/nst_json_testsuite/test_parsing/y_string_null_escape.json.msgpack differ diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json.msgpack new file mode 100644 index 000000000..3d07f7faa --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json.msgpack @@ -0,0 +1 @@ +, \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_pi.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_pi.json.msgpack new file mode 100644 index 000000000..d9738e288 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_pi.json.msgpack @@ -0,0 +1 @@ +π \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_simple_ascii.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_simple_ascii.json.msgpack new file mode 100644 index 000000000..d33b64dc5 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_simple_ascii.json.msgpack @@ -0,0 +1 @@ +asd \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_space.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_space.json.msgpack new file mode 100644 index 000000000..ad1973431 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_space.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json.msgpack new file mode 100644 index 000000000..1d94ad05a --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json.msgpack @@ -0,0 +1 @@ +ࠡ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json.msgpack new file mode 100644 index 000000000..e100f6250 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json.msgpack @@ -0,0 +1 @@ +ģ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json.msgpack new file mode 100644 index 000000000..00866ae2b --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json.msgpack @@ -0,0 +1 @@ +
 \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json.msgpack new file mode 100644 index 000000000..b8f541d82 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json.msgpack @@ -0,0 +1 @@ +
 \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_uEscape.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_uEscape.json.msgpack new file mode 100644 index 000000000..9dd9e3039 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_uEscape.json.msgpack @@ -0,0 +1 @@ +aクリス \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json.msgpack new file mode 100644 index 000000000..b2827c93b --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_unicode.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_unicode.json.msgpack new file mode 100644 index 000000000..cfdc5618a --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_unicode.json.msgpack @@ -0,0 +1 @@ +ꙭ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json.msgpack new file mode 100644 index 000000000..2083b6900 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json.msgpack @@ -0,0 +1 @@ +\ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_unicode_2.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_unicode_2.json.msgpack new file mode 100644 index 000000000..8451f4a44 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_unicode_2.json.msgpack @@ -0,0 +1 @@ +⍂㈴⍂ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json.msgpack new file mode 100644 index 000000000..b175034e9 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json.msgpack @@ -0,0 +1 @@ +​ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json.msgpack new file mode 100644 index 000000000..febc5e0ae --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json.msgpack @@ -0,0 +1 @@ +⁤ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json.msgpack new file mode 100644 index 000000000..daab159ff --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json.msgpack @@ -0,0 +1 @@ +" \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_utf8.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_utf8.json.msgpack new file mode 100644 index 000000000..c0089d8e7 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_utf8.json.msgpack @@ -0,0 +1 @@ +€𝄞 \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_string_with_del_character.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_string_with_del_character.json.msgpack new file mode 100644 index 000000000..e0a87ec0e --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_string_with_del_character.json.msgpack @@ -0,0 +1 @@ +aa \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_false.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_false.json.msgpack new file mode 100644 index 000000000..527718838 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_false.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_int.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_int.json.msgpack new file mode 100644 index 000000000..f59ec20aa --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_int.json.msgpack @@ -0,0 +1 @@ +* \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json.msgpack new file mode 100644 index 000000000..8d624e446 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json.msgpack @@ -0,0 +1 @@ +˿ \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_null.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_null.json.msgpack new file mode 100644 index 000000000..e7754cae5 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_null.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_string.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_string.json.msgpack new file mode 100644 index 000000000..ac624bfcf --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_string.json.msgpack @@ -0,0 +1 @@ +asd \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_true.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_true.json.msgpack new file mode 100644 index 000000000..6b10f9584 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_structure_lonely_true.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_structure_string_empty.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_structure_string_empty.json.msgpack new file mode 100644 index 000000000..eea1bf0c3 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_structure_string_empty.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json.msgpack new file mode 100644 index 000000000..42f268668 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json.msgpack @@ -0,0 +1 @@ +a \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_structure_true_in_array.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_structure_true_in_array.json.msgpack new file mode 100644 index 000000000..52b4164b2 --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_structure_true_in_array.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json.msgpack b/test/data/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json.msgpack new file mode 100644 index 000000000..9e99dd5ec --- /dev/null +++ b/test/data/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json.msgpack @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/data/regression/floats.json.msgpack b/test/data/regression/floats.json.msgpack new file mode 100644 index 000000000..e54198cba Binary files /dev/null and b/test/data/regression/floats.json.msgpack differ diff --git a/test/data/regression/signed_ints.json.msgpack b/test/data/regression/signed_ints.json.msgpack new file mode 100644 index 000000000..d1daa467e Binary files /dev/null and b/test/data/regression/signed_ints.json.msgpack differ diff --git a/test/data/regression/unsigned_ints.json.msgpack b/test/data/regression/unsigned_ints.json.msgpack new file mode 100644 index 000000000..c995381ec Binary files /dev/null and b/test/data/regression/unsigned_ints.json.msgpack differ diff --git a/test/data/regression/working_file.json.msgpack b/test/data/regression/working_file.json.msgpack new file mode 100644 index 000000000..3abaa15f5 --- /dev/null +++ b/test/data/regression/working_file.json.msgpack @@ -0,0 +1 @@ +FullScreenãFOVZAmbientOcclusion®RenderDistanceWindowResXWindowResY8MipmapLevelVSyncôAnisotropicFiltering \ No newline at end of file diff --git a/test/src/unit-msgpack.cpp b/test/src/unit-msgpack.cpp new file mode 100644 index 000000000..442b184e4 --- /dev/null +++ b/test/src/unit-msgpack.cpp @@ -0,0 +1,782 @@ +/* + __ _____ _____ _____ + __| | __| | | | JSON for Modern C++ (test suite) +| | |__ | | | | | | version 2.0.7 +|_____|_____|_____|_|___| https://github.com/nlohmann/json + +Licensed under the MIT License . +Copyright (c) 2013-2016 Niels Lohmann . + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "catch.hpp" + +#include "json.hpp" +using nlohmann::json; + +#include + +TEST_CASE("MessagePack") +{ + SECTION("individual values") + { + SECTION("null") + { + json j = nullptr; + std::vector expected = {0xc0}; + const auto result = json::to_msgpack(j); + CHECK(result == expected); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + + SECTION("boolean") + { + SECTION("true") + { + json j = true; + std::vector expected = {0xc3}; + const auto result = json::to_msgpack(j); + CHECK(result == expected); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + + SECTION("false") + { + json j = false; + std::vector expected = {0xc2}; + const auto result = json::to_msgpack(j); + CHECK(result == expected); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + + SECTION("number") + { + SECTION("signed") + { + SECTION("-32..-1 (negative fixnum)") + { + for (auto i = -32; i <= -1; ++i) + { + CAPTURE(i); + + // create JSON value with integer number + json j = i; + + // check type + CHECK(j.is_number_integer()); + + // create expected byte vector + std::vector expected; + expected.push_back(static_cast(i)); + + // compare result + size + const auto result = json::to_msgpack(j); + CHECK(result == expected); + CHECK(result.size() == 1); + + // check individual bytes + CHECK(static_cast(result[0]) == i); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + + SECTION("0..127 (positive fixnum)") + { + for (size_t i = 0; i <= 127; ++i) + { + CAPTURE(i); + + // create JSON value with integer number + json j = -1; + j.get_ref() = static_cast(i); + + // check type + CHECK(j.is_number_integer()); + + // create expected byte vector + std::vector expected; + expected.push_back(static_cast(i)); + + // compare result + size + const auto result = json::to_msgpack(j); + CHECK(result == expected); + CHECK(result.size() == 1); + + // check individual bytes + CHECK(result[0] == i); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + + SECTION("-128..-33 (int 8)") + { + for (auto i = -128; i <= -33; ++i) + { + CAPTURE(i); + + // create JSON value with integer number + json j = i; + + // check type + CHECK(j.is_number_integer()); + + // create expected byte vector + std::vector expected; + expected.push_back(0xd0); + expected.push_back(static_cast(i)); + + // compare result + size + const auto result = json::to_msgpack(j); + CHECK(result == expected); + CHECK(result.size() == 2); + + // check individual bytes + CHECK(result[0] == 0xd0); + CHECK(static_cast(result[1]) == i); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + + SECTION("-9263 (int 16)") + { + json j = -9263; + std::vector expected = {0xd1, 0xdb, 0xd1}; + + const auto result = json::to_msgpack(j); + CHECK(result == expected); + + int16_t restored = (result[1] << 8) + result[2]; + CHECK(restored == -9263); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + + SECTION("-32768..-129 (int 16)") + { + for (int16_t i = -32768; i <= -129; ++i) + { + CAPTURE(i); + + // create JSON value with integer number + json j = i; + + // check type + CHECK(j.is_number_integer()); + + // create expected byte vector + std::vector expected; + expected.push_back(0xd1); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); + + // compare result + size + const auto result = json::to_msgpack(j); + CHECK(result == expected); + CHECK(result.size() == 3); + + // check individual bytes + CHECK(result[0] == 0xd1); + int16_t restored = (result[1] << 8) + result[2]; + CHECK(restored == i); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + } + + SECTION("unsigned") + { + SECTION("0..127 (positive fixnum)") + { + for (size_t i = 0; i <= 127; ++i) + { + CAPTURE(i); + + // create JSON value with unsigned integer number + json j = i; + + // check type + CHECK(j.is_number_unsigned()); + + // create expected byte vector + std::vector expected; + expected.push_back(static_cast(i)); + + // compare result + size + const auto result = json::to_msgpack(j); + CHECK(result == expected); + CHECK(result.size() == 1); + + // check individual bytes + CHECK(result[0] == i); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + + SECTION("128..255 (uint 8)") + { + for (size_t i = 128; i <= 255; ++i) + { + CAPTURE(i); + + // create JSON value with unsigned integer number + json j = i; + + // check type + CHECK(j.is_number_unsigned()); + + // create expected byte vector + std::vector expected; + expected.push_back(0xcc); + expected.push_back(static_cast(i)); + + // compare result + size + const auto result = json::to_msgpack(j); + CHECK(result == expected); + CHECK(result.size() == 2); + + // check individual bytes + CHECK(result[0] == 0xcc); + uint8_t restored = static_cast(result[1]); + CHECK(restored == i); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + + SECTION("256..65535 (uint 16)") + { + for (size_t i = 256; i <= 65535; ++i) + { + CAPTURE(i); + + // create JSON value with unsigned integer number + json j = i; + + // check type + CHECK(j.is_number_unsigned()); + + // create expected byte vector + std::vector expected; + expected.push_back(0xcd); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); + + // compare result + size + const auto result = json::to_msgpack(j); + CHECK(result == expected); + CHECK(result.size() == 3); + + // check individual bytes + CHECK(result[0] == 0xcd); + uint16_t restored = static_cast(result[1]) * 256 + static_cast(result[2]); + CHECK(restored == i); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + + SECTION("65536..4294967295 (uint 32)") + { + for (uint32_t i : + { + 65536u, 77777u, 1048576u + }) + { + CAPTURE(i); + + // create JSON value with unsigned integer number + json j = i; + + // check type + CHECK(j.is_number_unsigned()); + + // create expected byte vector + std::vector expected; + expected.push_back(0xce); + expected.push_back(static_cast((i >> 24) & 0xff)); + expected.push_back(static_cast((i >> 16) & 0xff)); + expected.push_back(static_cast((i >> 8) & 0xff)); + expected.push_back(static_cast(i & 0xff)); + + // compare result + size + const auto result = json::to_msgpack(j); + CHECK(result == expected); + CHECK(result.size() == 5); + + // check individual bytes + CHECK(result[0] == 0xce); + uint32_t restored = static_cast((static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4])); + CHECK(restored == i); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + } + + SECTION("float") + { + SECTION("3.1415925") + { + double v = 3.1415925; + json j = v; + std::vector expected = + { + 0xcb, 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc + }; + const auto result = json::to_msgpack(j); + CHECK(result == expected); + + // restore value (reverse array for endianess) + double restored; + std::reverse(expected.begin(), expected.end()); + memcpy(&restored, expected.data(), sizeof(double)); + CHECK(restored == v); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + } + + SECTION("string") + { + SECTION("N = 0..31") + { + // explicitly enumerate the first byte for all 32 strings + const std::vector first_bytes = + { + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, + 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, + 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, + 0xbb, 0xbc, 0xbd, 0xbe, 0xbf + }; + + for (size_t N = 0; N < first_bytes.size(); ++N) + { + CAPTURE(N); + + // create JSON value with string containing of N * 'x' + const auto s = std::string(N, 'x'); + json j = s; + + // create expected byte vector + std::vector expected; + expected.push_back(first_bytes[N]); + for (size_t i = 0; i < N; ++i) + { + expected.push_back('x'); + } + + // check first byte + CHECK((first_bytes[N] & 0x1f) == N); + + // compare result + size + const auto result = json::to_msgpack(j); + CHECK(result == expected); + CHECK(result.size() == N + 1); + // check that no null byte is appended + if (N > 0) + { + CHECK(result.back() != '\x00'); + } + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + + SECTION("N = 32..255") + { + for (size_t N = 32; N <= 255; ++N) + { + CAPTURE(N); + + // create JSON value with string containing of N * 'x' + const auto s = std::string(N, 'x'); + json j = s; + + // create expected byte vector + std::vector expected; + expected.push_back(0xd9); + expected.push_back(N); + for (size_t i = 0; i < N; ++i) + { + expected.push_back('x'); + } + + // compare result + size + const auto result = json::to_msgpack(j); + CHECK(result == expected); + CHECK(result.size() == N + 2); + // check that no null byte is appended + CHECK(result.back() != '\x00'); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + + SECTION("N = 256..65535") + { + for (size_t N : + { + 256u, 999u, 1025u, 3333u, 2048u, 65535u + }) + { + CAPTURE(N); + + // create JSON value with string containing of N * 'x' + const auto s = std::string(N, 'x'); + json j = s; + + // create expected byte vector (hack: create string first) + std::vector expected(N, 'x'); + // reverse order of commands, because we insert at begin() + expected.insert(expected.begin(), static_cast(N & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); + expected.insert(expected.begin(), 0xda); + + // compare result + size + const auto result = json::to_msgpack(j); + CHECK(result == expected); + CHECK(result.size() == N + 3); + // check that no null byte is appended + CHECK(result.back() != '\x00'); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + + SECTION("N = 65536..4294967295") + { + for (size_t N : + { + 65536u, 77777u, 1048576u + }) + { + CAPTURE(N); + + // create JSON value with string containing of N * 'x' + const auto s = std::string(N, 'x'); + json j = s; + + // create expected byte vector (hack: create string first) + std::vector expected(N, 'x'); + // reverse order of commands, because we insert at begin() + expected.insert(expected.begin(), static_cast(N & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 8) & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 16) & 0xff)); + expected.insert(expected.begin(), static_cast((N >> 24) & 0xff)); + expected.insert(expected.begin(), 0xdb); + + // compare result + size + const auto result = json::to_msgpack(j); + CHECK(result == expected); + CHECK(result.size() == N + 5); + // check that no null byte is appended + CHECK(result.back() != '\x00'); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + } + + SECTION("array") + { + SECTION("empty") + { + json j = json::array(); + std::vector expected = {0x90}; + const auto result = json::to_msgpack(j); + CHECK(result == expected); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + + SECTION("[null]") + { + json j = {nullptr}; + std::vector expected = {0x91, 0xc0}; + const auto result = json::to_msgpack(j); + CHECK(result == expected); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + + SECTION("[1,2,3,4,5]") + { + json j = json::parse("[1,2,3,4,5]"); + std::vector expected = {0x95, 0x01, 0x02, 0x03, 0x04, 0x05}; + const auto result = json::to_msgpack(j); + CHECK(result == expected); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + + SECTION("[[[[]]]]") + { + json j = json::parse("[[[[]]]]"); + std::vector expected = {0x91, 0x91, 0x91, 0x90}; + const auto result = json::to_msgpack(j); + CHECK(result == expected); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + + SECTION("object") + { + SECTION("empty") + { + json j = json::object(); + std::vector expected = {0x80}; + const auto result = json::to_msgpack(j); + CHECK(result == expected); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + + SECTION("{\"\":null}") + { + json j = {{"", nullptr}}; + std::vector expected = {0x81, 0xa0, 0xc0}; + const auto result = json::to_msgpack(j); + CHECK(result == expected); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + + SECTION("{\"a\": {\"b\": {\"c\": {}}}}") + { + json j = json::parse("{\"a\": {\"b\": {\"c\": {}}}}"); + std::vector expected = + { + 0x81, 0xa1, 0x61, 0x81, 0xa1, 0x62, 0x81, 0xa1, 0x63, 0x80 + }; + const auto result = json::to_msgpack(j); + CHECK(result == expected); + + // roundtrip + CHECK(json::from_msgpack(result) == j); + } + } + } + + SECTION("input from msgpack-python") + { + for (std::string filename : + { + "test/data/json_nlohmann_tests/all_unicode.json", + "test/data/json.org/1.json", + "test/data/json.org/2.json", + "test/data/json.org/3.json", + "test/data/json.org/4.json", + "test/data/json.org/5.json", + "test/data/json_roundtrip/roundtrip01.json", + "test/data/json_roundtrip/roundtrip02.json", + "test/data/json_roundtrip/roundtrip03.json", + "test/data/json_roundtrip/roundtrip04.json", + "test/data/json_roundtrip/roundtrip05.json", + "test/data/json_roundtrip/roundtrip06.json", + "test/data/json_roundtrip/roundtrip07.json", + "test/data/json_roundtrip/roundtrip08.json", + "test/data/json_roundtrip/roundtrip09.json", + "test/data/json_roundtrip/roundtrip10.json", + "test/data/json_roundtrip/roundtrip11.json", + "test/data/json_roundtrip/roundtrip12.json", + "test/data/json_roundtrip/roundtrip13.json", + "test/data/json_roundtrip/roundtrip14.json", + "test/data/json_roundtrip/roundtrip15.json", + "test/data/json_roundtrip/roundtrip16.json", + "test/data/json_roundtrip/roundtrip17.json", + "test/data/json_roundtrip/roundtrip18.json", + "test/data/json_roundtrip/roundtrip19.json", + "test/data/json_roundtrip/roundtrip20.json", + "test/data/json_roundtrip/roundtrip21.json", + "test/data/json_roundtrip/roundtrip22.json", + "test/data/json_roundtrip/roundtrip23.json", + "test/data/json_roundtrip/roundtrip24.json", + "test/data/json_roundtrip/roundtrip25.json", + "test/data/json_roundtrip/roundtrip26.json", + "test/data/json_roundtrip/roundtrip27.json", + "test/data/json_roundtrip/roundtrip28.json", + "test/data/json_roundtrip/roundtrip29.json", + "test/data/json_roundtrip/roundtrip30.json", + "test/data/json_roundtrip/roundtrip31.json", + "test/data/json_roundtrip/roundtrip32.json", + "test/data/json_testsuite/sample.json", + "test/data/json_tests/pass1.json", + "test/data/json_tests/pass2.json", + "test/data/json_tests/pass3.json", + "test/data/regression/floats.json", + "test/data/regression/signed_ints.json", + "test/data/regression/unsigned_ints.json", + "test/data/regression/working_file.json", + "test/data/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json", + "test/data/nst_json_testsuite/test_parsing/y_array_empty-string.json", + "test/data/nst_json_testsuite/test_parsing/y_array_empty.json", + "test/data/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json", + "test/data/nst_json_testsuite/test_parsing/y_array_false.json", + "test/data/nst_json_testsuite/test_parsing/y_array_heterogeneous.json", + "test/data/nst_json_testsuite/test_parsing/y_array_null.json", + "test/data/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json", + "test/data/nst_json_testsuite/test_parsing/y_array_with_leading_space.json", + "test/data/nst_json_testsuite/test_parsing/y_array_with_several_null.json", + "test/data/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json", + "test/data/nst_json_testsuite/test_parsing/y_number.json", + "test/data/nst_json_testsuite/test_parsing/y_number_0e+1.json", + "test/data/nst_json_testsuite/test_parsing/y_number_0e1.json", + "test/data/nst_json_testsuite/test_parsing/y_number_after_space.json", + "test/data/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json", + "test/data/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json", + "test/data/nst_json_testsuite/test_parsing/y_number_huge_exp.json", + "test/data/nst_json_testsuite/test_parsing/y_number_int_with_exp.json", + "test/data/nst_json_testsuite/test_parsing/y_number_minus_zero.json", + "test/data/nst_json_testsuite/test_parsing/y_number_negative_int.json", + "test/data/nst_json_testsuite/test_parsing/y_number_negative_one.json", + "test/data/nst_json_testsuite/test_parsing/y_number_negative_zero.json", + "test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e.json", + "test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json", + "test/data/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json", + "test/data/nst_json_testsuite/test_parsing/y_number_real_exponent.json", + "test/data/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json", + "test/data/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json", + "test/data/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json", + "test/data/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json", + "test/data/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json", + "test/data/nst_json_testsuite/test_parsing/y_number_real_underflow.json", + "test/data/nst_json_testsuite/test_parsing/y_number_simple_int.json", + "test/data/nst_json_testsuite/test_parsing/y_number_simple_real.json", + //"test/data/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json", + //"test/data/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json", + //"test/data/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json", + "test/data/nst_json_testsuite/test_parsing/y_object.json", + "test/data/nst_json_testsuite/test_parsing/y_object_basic.json", + "test/data/nst_json_testsuite/test_parsing/y_object_duplicated_key.json", + "test/data/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json", + "test/data/nst_json_testsuite/test_parsing/y_object_empty.json", + "test/data/nst_json_testsuite/test_parsing/y_object_empty_key.json", + "test/data/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json", + "test/data/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json", + "test/data/nst_json_testsuite/test_parsing/y_object_long_strings.json", + "test/data/nst_json_testsuite/test_parsing/y_object_simple.json", + "test/data/nst_json_testsuite/test_parsing/y_object_string_unicode.json", + "test/data/nst_json_testsuite/test_parsing/y_object_with_newlines.json", + "test/data/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json", + "test/data/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json", + "test/data/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json", + "test/data/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json", + "test/data/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json", + "test/data/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json", + "test/data/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json", + "test/data/nst_json_testsuite/test_parsing/y_string_comments.json", + "test/data/nst_json_testsuite/test_parsing/y_string_double_escape_a.json", + "test/data/nst_json_testsuite/test_parsing/y_string_double_escape_n.json", + "test/data/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json", + "test/data/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json", + "test/data/nst_json_testsuite/test_parsing/y_string_in_array.json", + "test/data/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json", + "test/data/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json", + "test/data/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json", + "test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json", + "test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json", + "test/data/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json", + "test/data/nst_json_testsuite/test_parsing/y_string_null_escape.json", + "test/data/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json", + "test/data/nst_json_testsuite/test_parsing/y_string_pi.json", + "test/data/nst_json_testsuite/test_parsing/y_string_simple_ascii.json", + "test/data/nst_json_testsuite/test_parsing/y_string_space.json", + "test/data/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json", + "test/data/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json", + "test/data/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json", + "test/data/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json", + "test/data/nst_json_testsuite/test_parsing/y_string_uEscape.json", + "test/data/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json", + "test/data/nst_json_testsuite/test_parsing/y_string_unicode.json", + "test/data/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json", + "test/data/nst_json_testsuite/test_parsing/y_string_unicode_2.json", + "test/data/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json", + "test/data/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json", + "test/data/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json", + // "test/data/nst_json_testsuite/test_parsing/y_string_utf16.json", + "test/data/nst_json_testsuite/test_parsing/y_string_utf8.json", + "test/data/nst_json_testsuite/test_parsing/y_string_with_del_character.json", + "test/data/nst_json_testsuite/test_parsing/y_structure_lonely_false.json", + "test/data/nst_json_testsuite/test_parsing/y_structure_lonely_int.json", + "test/data/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json", + "test/data/nst_json_testsuite/test_parsing/y_structure_lonely_null.json", + "test/data/nst_json_testsuite/test_parsing/y_structure_lonely_string.json", + "test/data/nst_json_testsuite/test_parsing/y_structure_lonely_true.json", + "test/data/nst_json_testsuite/test_parsing/y_structure_string_empty.json", + "test/data/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json", + "test/data/nst_json_testsuite/test_parsing/y_structure_true_in_array.json", + "test/data/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json" + }) + { + CAPTURE(filename); + + // parse JSON file + std::ifstream f_json(filename); + json j1 = json::parse(f_json); + + // parse MessagePack file + std::ifstream f_msgpack(filename + ".msgpack", std::ios::binary); + std::vector packed((std::istreambuf_iterator(f_msgpack)), + std::istreambuf_iterator()); + json j2; + CHECK_NOTHROW(j2 = json::from_msgpack(packed)); + + // compare parsed JSON values + CHECK(j1 == j2); + } + } +}