mirror of
https://github.com/nlohmann/json.git
synced 2026-10-09 07:57:13 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82e7ee29df |
No files matched your search
@@ -64,18 +64,7 @@ values of that type directly to a `basic_json` instance, and they will automatic
|
|||||||
rather than arrays:
|
rather than arrays:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
using custom_json = nlohmann::basic_json<
|
using custom_json = nlohmann::ordered_json::with_binary_t<std::vector<std::byte>>;
|
||||||
nlohmann::ordered_map, // ObjectType
|
|
||||||
std::vector, // ArrayType
|
|
||||||
std::string, // StringType
|
|
||||||
bool, // BooleanType
|
|
||||||
std::int64_t, // NumberIntegerType
|
|
||||||
std::uint64_t, // NumberUnsignedType
|
|
||||||
double, // NumberFloatType
|
|
||||||
std::allocator, // AllocatorType
|
|
||||||
nlohmann::adl_serializer,
|
|
||||||
std::vector<std::byte> // Custom BinaryType
|
|
||||||
>;
|
|
||||||
|
|
||||||
std::vector<std::byte> data{std::byte{1}, std::byte{2}, std::byte{3}};
|
std::vector<std::byte> data{std::byte{1}, std::byte{2}, std::byte{3}};
|
||||||
custom_json j = data; // Creates a binary value, not an array
|
custom_json j = data; // Creates a binary value, not an array
|
||||||
|
|||||||
@@ -15,19 +15,7 @@ class base_class_with_hidden_members
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using json = nlohmann::basic_json <
|
using json = nlohmann::json::with_base_class_t<base_class_with_hidden_members>;
|
||||||
std::map,
|
|
||||||
std::vector,
|
|
||||||
std::string,
|
|
||||||
bool,
|
|
||||||
std::int64_t,
|
|
||||||
std::uint64_t,
|
|
||||||
double,
|
|
||||||
std::allocator,
|
|
||||||
nlohmann::adl_serializer,
|
|
||||||
std::vector<std::uint8_t>,
|
|
||||||
base_class_with_hidden_members
|
|
||||||
>;
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,9 +46,7 @@ class huge_binary_t : public std::vector<std::uint8_t>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using huge_binary_json = nlohmann::basic_json <
|
using huge_binary_json = nlohmann::json::with_binary_t<huge_binary_t>;
|
||||||
std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t,
|
|
||||||
double, std::allocator, nlohmann::adl_serializer, huge_binary_t, void >;
|
|
||||||
|
|
||||||
// a string type that can be made to report a size beyond INT32_MAX without
|
// a string type that can be made to report a size beyond INT32_MAX without
|
||||||
// allocating that much memory, so BSON length overflow can be tested for
|
// allocating that much memory, so BSON length overflow can be tested for
|
||||||
@@ -96,9 +94,7 @@ class huge_string_t : public std::string
|
|||||||
bool pretend_huge = false;
|
bool pretend_huge = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
using huge_string_json = nlohmann::basic_json <
|
using huge_string_json = nlohmann::json::with_string_t<huge_string_t>;
|
||||||
std::map, std::vector, huge_string_t, bool, std::int64_t, std::uint64_t,
|
|
||||||
double, std::allocator, nlohmann::adl_serializer, std::vector<std::uint8_t>, void >;
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TEST_CASE("BSON")
|
TEST_CASE("BSON")
|
||||||
|
|||||||
@@ -400,20 +400,7 @@ class base_class_with_hidden_members
|
|||||||
std::size_t m_size = 42;
|
std::size_t m_size = 42;
|
||||||
};
|
};
|
||||||
|
|
||||||
using json_with_hidden_base_members =
|
using json_with_hidden_base_members = nlohmann::json::with_base_class_t<base_class_with_hidden_members>;
|
||||||
nlohmann::basic_json <
|
|
||||||
std::map,
|
|
||||||
std::vector,
|
|
||||||
std::string,
|
|
||||||
bool,
|
|
||||||
std::int64_t,
|
|
||||||
std::uint64_t,
|
|
||||||
double,
|
|
||||||
std::allocator,
|
|
||||||
nlohmann::adl_serializer,
|
|
||||||
std::vector<std::uint8_t>,
|
|
||||||
base_class_with_hidden_members
|
|
||||||
>;
|
|
||||||
|
|
||||||
TEST_CASE("JSON Node as_base_class")
|
TEST_CASE("JSON Node as_base_class")
|
||||||
{
|
{
|
||||||
@@ -459,19 +446,7 @@ struct const_member_base
|
|||||||
const int id = 7; // NOLINT(misc-non-private-member-variables-in-classes)
|
const int id = 7; // NOLINT(misc-non-private-member-variables-in-classes)
|
||||||
};
|
};
|
||||||
|
|
||||||
using json_with_const_base = nlohmann::basic_json <
|
using json_with_const_base = nlohmann::json::with_base_class_t<const_member_base>;
|
||||||
std::map,
|
|
||||||
std::vector,
|
|
||||||
std::string,
|
|
||||||
bool,
|
|
||||||
std::int64_t,
|
|
||||||
std::uint64_t,
|
|
||||||
double,
|
|
||||||
std::allocator,
|
|
||||||
nlohmann::adl_serializer,
|
|
||||||
std::vector<std::uint8_t>,
|
|
||||||
const_member_base
|
|
||||||
>;
|
|
||||||
|
|
||||||
// build an array nested @a depth levels deep, with the innermost value 1;
|
// build an array nested @a depth levels deep, with the innermost value 1;
|
||||||
// every level is constructed (never assigned), since const_member_base does
|
// every level is constructed (never assigned), since const_member_base does
|
||||||
|
|||||||
@@ -26,15 +26,11 @@ namespace
|
|||||||
|
|
||||||
// a BinaryType whose value type is signed: the elements must still be
|
// a BinaryType whose value type is signed: the elements must still be
|
||||||
// processed as the numbers 0..255
|
// processed as the numbers 0..255
|
||||||
using char_binary_json = nlohmann::basic_json <
|
using char_binary_json = nlohmann::json::with_binary_t<std::vector<char>>;
|
||||||
std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t,
|
|
||||||
double, std::allocator, nlohmann::adl_serializer, std::vector<char>, void >;
|
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#ifdef JSON_HAS_CPP_17
|
||||||
// a BinaryType whose value type is not an integer type at all
|
// a BinaryType whose value type is not an integer type at all
|
||||||
using byte_binary_json = nlohmann::basic_json <
|
using byte_binary_json = nlohmann::json::with_binary_t<std::vector<std::byte>>;
|
||||||
std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t,
|
|
||||||
double, std::allocator, nlohmann::adl_serializer, std::vector<std::byte>, void >;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -2201,10 +2201,7 @@ struct huge_array : std::vector<T, A>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using huge_array_json = nlohmann::basic_json <
|
using huge_array_json = nlohmann::json::with_array_t<huge_array>;
|
||||||
std::map, huge_array, std::string, bool, std::int64_t, std::uint64_t,
|
|
||||||
double, std::allocator, nlohmann::adl_serializer,
|
|
||||||
std::vector<std::uint8_t>, void >;
|
|
||||||
|
|
||||||
TEST_CASE("MessagePack Size above uint32 for array")
|
TEST_CASE("MessagePack Size above uint32 for array")
|
||||||
{
|
{
|
||||||
@@ -2249,18 +2246,7 @@ template<typename K, typename V,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using huge_object_json = nlohmann::basic_json <
|
using huge_object_json = nlohmann::json::with_object_t<huge_map>;
|
||||||
huge_map,
|
|
||||||
std::vector,
|
|
||||||
std::string,
|
|
||||||
bool,
|
|
||||||
std::int64_t,
|
|
||||||
std::uint64_t,
|
|
||||||
double,
|
|
||||||
std::allocator,
|
|
||||||
nlohmann::adl_serializer,
|
|
||||||
std::vector<std::uint8_t>,
|
|
||||||
void >;
|
|
||||||
|
|
||||||
TEST_CASE("MessagePack Size above uint32 for object")
|
TEST_CASE("MessagePack Size above uint32 for object")
|
||||||
{
|
{
|
||||||
@@ -2295,18 +2281,7 @@ struct huge_string : std::string
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using huge_string_json = nlohmann::basic_json <
|
using huge_string_json = nlohmann::json::with_string_t<huge_string>;
|
||||||
std::map,
|
|
||||||
std::vector,
|
|
||||||
huge_string,
|
|
||||||
bool,
|
|
||||||
std::int64_t,
|
|
||||||
std::uint64_t,
|
|
||||||
double,
|
|
||||||
std::allocator,
|
|
||||||
nlohmann::adl_serializer,
|
|
||||||
std::vector<std::uint8_t>,
|
|
||||||
void >;
|
|
||||||
|
|
||||||
TEST_CASE("MessagePack Size above uint32 for string")
|
TEST_CASE("MessagePack Size above uint32 for string")
|
||||||
{
|
{
|
||||||
@@ -2329,18 +2304,7 @@ struct huge_binary : std::vector<std::uint8_t>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using huge_binary_json = nlohmann::basic_json <
|
using huge_binary_json = nlohmann::json::with_binary_t<huge_binary>;
|
||||||
std::map,
|
|
||||||
std::vector,
|
|
||||||
std::string,
|
|
||||||
bool,
|
|
||||||
std::int64_t,
|
|
||||||
std::uint64_t,
|
|
||||||
double,
|
|
||||||
std::allocator,
|
|
||||||
nlohmann::adl_serializer,
|
|
||||||
huge_binary,
|
|
||||||
void >;
|
|
||||||
|
|
||||||
TEST_CASE("MessagePack Size above uint32 for binary")
|
TEST_CASE("MessagePack Size above uint32 for binary")
|
||||||
{
|
{
|
||||||
@@ -2390,14 +2354,10 @@ class beyond_uint32_string_t : public std::string
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using beyond_uint32_string_json = nlohmann::basic_json <
|
using beyond_uint32_string_json = nlohmann::json::with_string_t<beyond_uint32_string_t>;
|
||||||
std::map, std::vector, beyond_uint32_string_t, bool, std::int64_t, std::uint64_t,
|
|
||||||
double, std::allocator, nlohmann::adl_serializer, std::vector<std::uint8_t>, void >;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using beyond_uint32_binary_json = nlohmann::basic_json <
|
using beyond_uint32_binary_json = nlohmann::json::with_binary_t<beyond_uint32_binary_t>;
|
||||||
std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t,
|
|
||||||
double, std::allocator, nlohmann::adl_serializer, beyond_uint32_binary_t, void >;
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
TEST_CASE("MessagePack lengths beyond UINT32_MAX cannot be serialized")
|
TEST_CASE("MessagePack lengths beyond UINT32_MAX cannot be serialized")
|
||||||
|
|||||||
@@ -217,16 +217,7 @@ void int_to_string(alt_string& target, std::size_t value)
|
|||||||
target = std::to_string(value).c_str();
|
target = std::to_string(value).c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
using alt_json = nlohmann::basic_json <
|
using alt_json = nlohmann::json::with_string_t<alt_string>;
|
||||||
std::map,
|
|
||||||
std::vector,
|
|
||||||
alt_string,
|
|
||||||
bool,
|
|
||||||
std::int64_t,
|
|
||||||
std::uint64_t,
|
|
||||||
double,
|
|
||||||
std::allocator,
|
|
||||||
nlohmann::adl_serializer >;
|
|
||||||
|
|
||||||
bool operator<(const char* op1, const alt_string& op2) noexcept
|
bool operator<(const char* op1, const alt_string& op2) noexcept
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user