1
0
mirror of https://github.com/nlohmann/json synced 2024-11-25 05:10:05 +00:00

🚚 rename binary_array() to binary()

This commit is contained in:
Niels Lohmann 2020-05-19 13:30:22 +02:00
parent 86b053e916
commit 21b1680ea1
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
16 changed files with 85 additions and 61 deletions

View File

@ -1,6 +1,7 @@
#pragma once
#include <cstdint> // uint8_t
#include <tuple> // tie
#include <utility> // move
namespace nlohmann
@ -51,6 +52,17 @@ class byte_container_with_subtype : public BinaryType
, m_has_subtype(true)
{}
bool operator==(const byte_container_with_subtype& rhs) const
{
return std::tie(static_cast<const BinaryType&>(*this), m_subtype, m_has_subtype) ==
std::tie(static_cast<const BinaryType&>(rhs), rhs.m_subtype, rhs.m_has_subtype);
}
bool operator!=(const byte_container_with_subtype& rhs) const
{
return !(rhs == *this);
}
/*!
@brief sets the binary subtype

View File

@ -899,7 +899,7 @@ class basic_json
- If a subtype is given, it is used and added as unsigned 8-bit integer.
- If no subtype is given, the generic binary subtype 0x00 is used.
@sa @ref binary_array -- create a binary array
@sa @ref binary -- create a binary array
@since version 3.8.0
*/
@ -1672,7 +1672,7 @@ class basic_json
@since version 3.8.0
*/
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json binary_array(const typename binary_t::container_type& init)
static basic_json binary(const typename binary_t::container_type& init)
{
auto res = basic_json();
res.m_type = value_t::binary;
@ -1709,7 +1709,7 @@ class basic_json
@since version 3.8.0
*/
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json binary_array(const typename binary_t::container_type& init, std::uint8_t subtype)
static basic_json binary(const typename binary_t::container_type& init, std::uint8_t subtype)
{
auto res = basic_json();
res.m_type = value_t::binary;
@ -1717,9 +1717,9 @@ class basic_json
return res;
}
/// @copydoc binary_array(const typename binary_t::container_type&)
/// @copydoc binary(const typename binary_t::container_type&)
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json binary_array(typename binary_t::container_type&& init)
static basic_json binary(typename binary_t::container_type&& init)
{
auto res = basic_json();
res.m_type = value_t::binary;
@ -1727,9 +1727,9 @@ class basic_json
return res;
}
/// @copydoc binary_array(const typename binary_t::container_type&, std::uint8_t)
/// @copydoc binary(const typename binary_t::container_type&, std::uint8_t)
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json binary_array(typename binary_t::container_type&& init, std::uint8_t subtype)
static basic_json binary(typename binary_t::container_type&& init, std::uint8_t subtype)
{
auto res = basic_json();
res.m_type = value_t::binary;

View File

@ -4227,6 +4227,7 @@ struct adl_serializer
#include <cstdint> // uint8_t
#include <tuple> // tie
#include <utility> // move
namespace nlohmann
@ -4277,6 +4278,17 @@ class byte_container_with_subtype : public BinaryType
, m_has_subtype(true)
{}
bool operator==(const byte_container_with_subtype& rhs) const
{
return std::tie(static_cast<const BinaryType&>(*this), m_subtype, m_has_subtype) ==
std::tie(static_cast<const BinaryType&>(rhs), rhs.m_subtype, rhs.m_has_subtype);
}
bool operator!=(const byte_container_with_subtype& rhs) const
{
return !(rhs == *this);
}
/*!
@brief sets the binary subtype
@ -16680,7 +16692,7 @@ class basic_json
- If a subtype is given, it is used and added as unsigned 8-bit integer.
- If no subtype is given, the generic binary subtype 0x00 is used.
@sa @ref binary_array -- create a binary array
@sa @ref binary -- create a binary array
@since version 3.8.0
*/
@ -17453,7 +17465,7 @@ class basic_json
@since version 3.8.0
*/
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json binary_array(const typename binary_t::container_type& init)
static basic_json binary(const typename binary_t::container_type& init)
{
auto res = basic_json();
res.m_type = value_t::binary;
@ -17490,7 +17502,7 @@ class basic_json
@since version 3.8.0
*/
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json binary_array(const typename binary_t::container_type& init, std::uint8_t subtype)
static basic_json binary(const typename binary_t::container_type& init, std::uint8_t subtype)
{
auto res = basic_json();
res.m_type = value_t::binary;
@ -17498,9 +17510,9 @@ class basic_json
return res;
}
/// @copydoc binary_array(const typename binary_t::container_type&)
/// @copydoc binary(const typename binary_t::container_type&)
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json binary_array(typename binary_t::container_type&& init)
static basic_json binary(typename binary_t::container_type&& init)
{
auto res = basic_json();
res.m_type = value_t::binary;
@ -17508,9 +17520,9 @@ class basic_json
return res;
}
/// @copydoc binary_array(const typename binary_t::container_type&, std::uint8_t)
/// @copydoc binary(const typename binary_t::container_type&, std::uint8_t)
JSON_HEDLEY_WARN_UNUSED_RESULT
static basic_json binary_array(typename binary_t::container_type&& init, std::uint8_t subtype)
static basic_json binary(typename binary_t::container_type&& init, std::uint8_t subtype)
{
auto res = basic_json();
res.m_type = value_t::binary;

View File

@ -499,7 +499,7 @@ TEST_CASE("BSON")
const auto s = std::vector<std::uint8_t>(N, 'x');
json j =
{
{ "entry", json::binary_array(s) }
{ "entry", json::binary(s) }
};
std::vector<std::uint8_t> expected =
@ -529,7 +529,7 @@ TEST_CASE("BSON")
const std::vector<std::uint8_t> md5hash = {0xd7, 0x7e, 0x27, 0x54, 0xbe, 0x12, 0x37, 0xfe, 0xd6, 0x0c, 0x33, 0x98, 0x30, 0x3b, 0x8d, 0xc4};
json j =
{
{ "entry", json::binary_array(md5hash, 5) }
{ "entry", json::binary(md5hash, 5) }
};
std::vector<std::uint8_t> expected =

View File

@ -1450,7 +1450,7 @@ TEST_CASE("CBOR")
// create JSON value with byte array containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
// create expected byte vector
std::vector<uint8_t> expected;
@ -1484,7 +1484,7 @@ TEST_CASE("CBOR")
// create JSON value with string containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
// create expected byte vector
std::vector<uint8_t> expected;
@ -1519,7 +1519,7 @@ TEST_CASE("CBOR")
// create JSON value with string containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
// create expected byte vector (hack: create string first)
std::vector<uint8_t> expected(N, 'x');
@ -1552,7 +1552,7 @@ TEST_CASE("CBOR")
// create JSON value with string containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
// create expected byte vector (hack: create string first)
std::vector<uint8_t> expected(N, 'x');
@ -1581,7 +1581,7 @@ TEST_CASE("CBOR")
std::vector<std::uint8_t> input = {0x5F, 0x44, 0xaa, 0xbb, 0xcc, 0xdd, 0x43, 0xee, 0xff, 0x99, 0xFF};
auto j = json::from_cbor(input);
CHECK(j.is_binary());
auto k = json::binary_array({0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x99});
auto k = json::binary({0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x99});
CAPTURE(j.dump(0, ' ', false, json::error_handler_t::strict))
CHECK(j == k);
}
@ -1633,7 +1633,7 @@ TEST_CASE("CBOR")
0x00, 0x00, 0x00, 0x01, 0x61
};
json j = json::from_cbor(given);
CHECK(j == json::binary_array(std::vector<uint8_t> {'a'}));
CHECK(j == json::binary(std::vector<uint8_t> {'a'}));
}
SECTION("0x7b (string)")
@ -2502,7 +2502,7 @@ TEST_CASE("examples from RFC 7049 Appendix A")
std::ifstream f_bin(TEST_DATA_DIRECTORY "/binary_data/cbor_binary.out", std::ios::binary);
std::vector<uint8_t> expected((std::istreambuf_iterator<char>(f_bin)),
std::istreambuf_iterator<char>());
CHECK(j == json::binary_array(expected));
CHECK(j == json::binary(expected));
}
SECTION("arrays")

View File

@ -101,7 +101,7 @@ TEST_CASE("lexicographical comparison operators")
true, false,
{1, 2, 3}, {"one", "two", "three"},
{{"first", 1}, {"second", 2}}, {{"a", "A"}, {"b", {"B"}}},
json::binary_array({1, 2, 3}), json::binary_array({1, 2, 4})
json::binary({1, 2, 3}), json::binary({1, 2, 4})
};
SECTION("comparison: equal")

View File

@ -121,7 +121,7 @@ TEST_CASE("constructors")
auto t = json::value_t::binary;
json j(t);
CHECK(j.type() == t);
CHECK(j == json::binary_array({}));
CHECK(j == json::binary({}));
}
}
@ -1482,12 +1482,12 @@ TEST_CASE("constructors")
SECTION("binary")
{
{
json j = json::binary_array({1, 2, 3});
json j = json::binary({1, 2, 3});
json j_new(j.begin(), j.end());
CHECK((j == j_new));
}
{
json j = json::binary_array({1, 2, 3});
json j = json::binary({1, 2, 3});
json j_new(j.cbegin(), j.cend());
CHECK((j == j_new));
}

View File

@ -94,7 +94,7 @@ TEST_CASE("other constructors and destructor")
SECTION("binary")
{
json j = json::binary_array({1, 2, 3});
json j = json::binary({1, 2, 3});
json k(j);
CHECK(j == k);
}
@ -177,7 +177,7 @@ TEST_CASE("other constructors and destructor")
SECTION("binary")
{
json j = json::binary_array({1, 2, 3});
json j = json::binary({1, 2, 3});
json k;
k = j;
CHECK(j == k);

View File

@ -698,13 +698,13 @@ TEST_CASE("element access 1")
SECTION("binary")
{
{
json j = json::binary_array({1, 2, 3});
json j = json::binary({1, 2, 3});
json::iterator it = j.erase(j.begin());
CHECK(j.type() == json::value_t::null);
CHECK(it == j.end());
}
{
json j = json::binary_array({1, 2, 3});
json j = json::binary({1, 2, 3});
json::const_iterator it = j.erase(j.cbegin());
CHECK(j.type() == json::value_t::null);
CHECK(it == j.end());
@ -896,13 +896,13 @@ TEST_CASE("element access 1")
SECTION("binary")
{
{
json j = json::binary_array({1, 2, 3});
json j = json::binary({1, 2, 3});
json::iterator it = j.erase(j.begin(), j.end());
CHECK(j.type() == json::value_t::null);
CHECK(it == j.end());
}
{
json j = json::binary_array({1, 2, 3});
json j = json::binary({1, 2, 3});
json::const_iterator it = j.erase(j.cbegin(), j.cend());
CHECK(j.type() == json::value_t::null);
CHECK(it == j.end());

View File

@ -262,7 +262,7 @@ TEST_CASE("object inspection")
// inside the dump() function
CHECK(j.dump(1024).size() == 15472);
const auto binary = json::binary_array({1, 2, 3}, 128);
const auto binary = json::binary({1, 2, 3}, 128);
CHECK(binary.dump(1024).size() == 2086);
}
@ -472,7 +472,7 @@ TEST_CASE("object inspection")
SECTION("binary")
{
json j = json::binary_array({});
json j = json::binary({});
json::value_t t = j;
CHECK(t == j.type());
}

View File

@ -110,7 +110,7 @@ TEST_CASE("modifiers")
{
SECTION("empty binary")
{
json j = json::binary_array({});
json j = json::binary({});
json k = j;
j.clear();
@ -121,7 +121,7 @@ TEST_CASE("modifiers")
SECTION("filled binary")
{
json j = json::binary_array({1, 2, 3, 4, 5});
json j = json::binary({1, 2, 3, 4, 5});
json k = j;
j.clear();
@ -967,30 +967,30 @@ TEST_CASE("modifiers")
{
SECTION("binary_t type")
{
json j = json::binary_array({1, 2, 3, 4});
json j = json::binary({1, 2, 3, 4});
json::binary_t s = {{5, 6, 7, 8}};
j.swap(s);
CHECK(j == json::binary_array({5, 6, 7, 8}));
CHECK(j == json::binary({5, 6, 7, 8}));
j.swap(s);
CHECK(j == json::binary_array({1, 2, 3, 4}));
CHECK(j == json::binary({1, 2, 3, 4}));
}
SECTION("binary_t::container_type type")
{
json j = json::binary_array({1, 2, 3, 4});
json j = json::binary({1, 2, 3, 4});
std::vector<std::uint8_t> s = {{5, 6, 7, 8}};
j.swap(s);
CHECK(j == json::binary_array({5, 6, 7, 8}));
CHECK(j == json::binary({5, 6, 7, 8}));
j.swap(s);
CHECK(j == json::binary_array({1, 2, 3, 4}));
CHECK(j == json::binary({1, 2, 3, 4}));
}
SECTION("non-binary_t type")

View File

@ -1132,7 +1132,7 @@ TEST_CASE("MessagePack")
// create JSON value with byte array containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
std::uint8_t subtype = 42;
j.get_binary().set_subtype(subtype);
@ -1207,7 +1207,7 @@ TEST_CASE("MessagePack")
// create JSON value with string containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
std::uint8_t subtype = 42;
j.get_binary().set_subtype(subtype);
@ -1243,7 +1243,7 @@ TEST_CASE("MessagePack")
// create JSON value with string containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
std::uint8_t subtype = 42;
j.get_binary().set_subtype(subtype);
@ -1281,7 +1281,7 @@ TEST_CASE("MessagePack")
// create JSON value with byte array containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
// create expected byte vector
std::vector<std::uint8_t> expected;
@ -1319,7 +1319,7 @@ TEST_CASE("MessagePack")
// create JSON value with string containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
// create expected byte vector (hack: create string first)
std::vector<std::uint8_t> expected(N, 'x');
@ -1352,7 +1352,7 @@ TEST_CASE("MessagePack")
// create JSON value with string containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
// create expected byte vector (hack: create string first)
std::vector<uint8_t> expected(N, 'x');

View File

@ -443,7 +443,7 @@ TEST_CASE("pointer access")
SECTION("pointer access to const binary_t")
{
using test_type = const json::binary_t;
const json value = json::binary_array({1, 2, 3});
const json value = json::binary({1, 2, 3});
// check if pointers are returned correctly
test_type* p1 = value.get_ptr<test_type*>();
@ -472,7 +472,7 @@ TEST_CASE("pointer access")
SECTION("pointer access to const binary_t")
{
using test_type = const json::binary_t;
const json value = json::binary_array({});
const json value = json::binary({});
// check if pointers are returned correctly
test_type* p1 = value.get_ptr<test_type*>();

View File

@ -209,10 +209,10 @@ TEST_CASE_TEMPLATE("serialization for extreme integer values", T, int32_t, uint3
TEST_CASE("dump with binary values")
{
auto binary = json::binary_array({1, 2, 3, 4});
auto binary_empty = json::binary_array({});
auto binary_with_subtype = json::binary_array({1, 2, 3, 4}, 128);
auto binary_empty_with_subtype = json::binary_array({}, 128);
auto binary = json::binary({1, 2, 3, 4});
auto binary_empty = json::binary({});
auto binary_with_subtype = json::binary({1, 2, 3, 4}, 128);
auto binary_empty_with_subtype = json::binary({}, 128);
json object = {{"key", binary}};
json object_empty = {{"key", binary_empty}};

View File

@ -921,7 +921,7 @@ TEST_CASE("UBJSON")
// create JSON value with byte array containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
// create expected byte vector
std::vector<std::uint8_t> expected;
@ -972,7 +972,7 @@ TEST_CASE("UBJSON")
// create JSON value with byte array containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
// create expected byte vector
std::vector<uint8_t> expected;
@ -1012,7 +1012,7 @@ TEST_CASE("UBJSON")
// create JSON value with byte array containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
// create expected byte vector
std::vector<std::uint8_t> expected(N + 7, 'x');
@ -1049,7 +1049,7 @@ TEST_CASE("UBJSON")
// create JSON value with byte array containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
// create expected byte vector
std::vector<std::uint8_t> expected(N + 9, 'x');
@ -1081,7 +1081,7 @@ TEST_CASE("UBJSON")
{
const std::size_t N = 10;
const auto s = std::vector<std::uint8_t>(N, 'x');
json j = json::binary_array(s);
json j = json::binary(s);
SECTION("No Count No Type")
{

View File

@ -765,7 +765,7 @@ TEST_CASE("different basic_json types conversions")
SECTION("binary")
{
json j = json::binary_array({1, 2, 3});
json j = json::binary({1, 2, 3});
custom_json cj = j;
CHECK(cj.get_binary() == j.get_binary());
}