added start index for from_cbor and from_msgpack (#462)

This commit is contained in:
Niels Lohmann 2017-02-19 21:17:05 +01:00
parent 4151f2d297
commit 83f1d2c81b
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
5 changed files with 57 additions and 23 deletions

View file

@ -7917,9 +7917,11 @@ class basic_json
vector in MessagePack format.,to_msgpack} vector in MessagePack format.,to_msgpack}
@sa http://msgpack.org @sa http://msgpack.org
@sa @ref from_msgpack(const std::vector<uint8_t>&) for the analogous @sa @ref from_msgpack(const std::vector<uint8_t>&, const size_t) for the
deserialization analogous deserialization
@sa @ref to_cbor(const basic_json& for the related CBOR format @sa @ref to_cbor(const basic_json& for the related CBOR format
@since version 2.0.9
*/ */
static std::vector<uint8_t> to_msgpack(const basic_json& j) static std::vector<uint8_t> to_msgpack(const basic_json& j)
{ {
@ -7935,6 +7937,7 @@ class basic_json
serialization format. serialization format.
@param[in] v a byte vector in MessagePack format @param[in] v a byte vector in MessagePack format
@param[in] start_index the index to start reading from @a v (0 by default)
@return deserialized JSON value @return deserialized JSON value
@throw std::invalid_argument if unsupported features from MessagePack were @throw std::invalid_argument if unsupported features from MessagePack were
@ -7948,11 +7951,15 @@ class basic_json
@sa http://msgpack.org @sa http://msgpack.org
@sa @ref to_msgpack(const basic_json&) for the analogous serialization @sa @ref to_msgpack(const basic_json&) for the analogous serialization
@sa @ref from_cbor(const std::vector<uint8_t>&) for the related CBOR format @sa @ref from_cbor(const std::vector<uint8_t>&, const size_t) for the
related CBOR format
@since version 2.0.9, parameter @a start_index since 2.0.11
*/ */
static basic_json from_msgpack(const std::vector<uint8_t>& v) static basic_json from_msgpack(const std::vector<uint8_t>& v,
const size_t start_index = 0)
{ {
size_t i = 0; size_t i = start_index;
return from_msgpack_internal(v, i); return from_msgpack_internal(v, i);
} }
@ -7973,9 +7980,11 @@ class basic_json
vector in CBOR format.,to_cbor} vector in CBOR format.,to_cbor}
@sa http://cbor.io @sa http://cbor.io
@sa @ref from_cbor(const std::vector<uint8_t>&) for the analogous @sa @ref from_cbor(const std::vector<uint8_t>&, const size_t) for the
deserialization analogous deserialization
@sa @ref to_msgpack(const basic_json& for the related MessagePack format @sa @ref to_msgpack(const basic_json& for the related MessagePack format
@since version 2.0.9
*/ */
static std::vector<uint8_t> to_cbor(const basic_json& j) static std::vector<uint8_t> to_cbor(const basic_json& j)
{ {
@ -7991,6 +8000,7 @@ class basic_json
(Concise Binary Object Representation) serialization format. (Concise Binary Object Representation) serialization format.
@param[in] v a byte vector in CBOR format @param[in] v a byte vector in CBOR format
@param[in] start_index the index to start reading from @a v (0 by default)
@return deserialized JSON value @return deserialized JSON value
@throw std::invalid_argument if unsupported features from CBOR were used in @throw std::invalid_argument if unsupported features from CBOR were used in
@ -8004,12 +8014,15 @@ class basic_json
@sa http://cbor.io @sa http://cbor.io
@sa @ref to_cbor(const basic_json&) for the analogous serialization @sa @ref to_cbor(const basic_json&) for the analogous serialization
@sa @ref from_msgpack(const std::vector<uint8_t>&) for the related @sa @ref from_msgpack(const std::vector<uint8_t>&, const size_t) for the
MessagePack format related MessagePack format
@since version 2.0.9, parameter @a start_index since 2.0.11
*/ */
static basic_json from_cbor(const std::vector<uint8_t>& v) static basic_json from_cbor(const std::vector<uint8_t>& v,
const size_t start_index = 0)
{ {
size_t i = 0; size_t i = start_index;
return from_cbor_internal(v, i); return from_cbor_internal(v, i);
} }

View file

@ -7917,9 +7917,11 @@ class basic_json
vector in MessagePack format.,to_msgpack} vector in MessagePack format.,to_msgpack}
@sa http://msgpack.org @sa http://msgpack.org
@sa @ref from_msgpack(const std::vector<uint8_t>&) for the analogous @sa @ref from_msgpack(const std::vector<uint8_t>&, const size_t) for the
deserialization analogous deserialization
@sa @ref to_cbor(const basic_json& for the related CBOR format @sa @ref to_cbor(const basic_json& for the related CBOR format
@since version 2.0.9
*/ */
static std::vector<uint8_t> to_msgpack(const basic_json& j) static std::vector<uint8_t> to_msgpack(const basic_json& j)
{ {
@ -7935,6 +7937,7 @@ class basic_json
serialization format. serialization format.
@param[in] v a byte vector in MessagePack format @param[in] v a byte vector in MessagePack format
@param[in] start_index the index to start reading from @a v (0 by default)
@return deserialized JSON value @return deserialized JSON value
@throw std::invalid_argument if unsupported features from MessagePack were @throw std::invalid_argument if unsupported features from MessagePack were
@ -7948,11 +7951,15 @@ class basic_json
@sa http://msgpack.org @sa http://msgpack.org
@sa @ref to_msgpack(const basic_json&) for the analogous serialization @sa @ref to_msgpack(const basic_json&) for the analogous serialization
@sa @ref from_cbor(const std::vector<uint8_t>&) for the related CBOR format @sa @ref from_cbor(const std::vector<uint8_t>&, const size_t) for the
related CBOR format
@since version 2.0.9, parameter @a start_index since 2.0.11
*/ */
static basic_json from_msgpack(const std::vector<uint8_t>& v) static basic_json from_msgpack(const std::vector<uint8_t>& v,
const size_t start_index = 0)
{ {
size_t i = 0; size_t i = start_index;
return from_msgpack_internal(v, i); return from_msgpack_internal(v, i);
} }
@ -7973,9 +7980,11 @@ class basic_json
vector in CBOR format.,to_cbor} vector in CBOR format.,to_cbor}
@sa http://cbor.io @sa http://cbor.io
@sa @ref from_cbor(const std::vector<uint8_t>&) for the analogous @sa @ref from_cbor(const std::vector<uint8_t>&, const size_t) for the
deserialization analogous deserialization
@sa @ref to_msgpack(const basic_json& for the related MessagePack format @sa @ref to_msgpack(const basic_json& for the related MessagePack format
@since version 2.0.9
*/ */
static std::vector<uint8_t> to_cbor(const basic_json& j) static std::vector<uint8_t> to_cbor(const basic_json& j)
{ {
@ -7991,6 +8000,7 @@ class basic_json
(Concise Binary Object Representation) serialization format. (Concise Binary Object Representation) serialization format.
@param[in] v a byte vector in CBOR format @param[in] v a byte vector in CBOR format
@param[in] start_index the index to start reading from @a v (0 by default)
@return deserialized JSON value @return deserialized JSON value
@throw std::invalid_argument if unsupported features from CBOR were used in @throw std::invalid_argument if unsupported features from CBOR were used in
@ -8004,12 +8014,15 @@ class basic_json
@sa http://cbor.io @sa http://cbor.io
@sa @ref to_cbor(const basic_json&) for the analogous serialization @sa @ref to_cbor(const basic_json&) for the analogous serialization
@sa @ref from_msgpack(const std::vector<uint8_t>&) for the related @sa @ref from_msgpack(const std::vector<uint8_t>&, const size_t) for the
MessagePack format related MessagePack format
@since version 2.0.9, parameter @a start_index since 2.0.11
*/ */
static basic_json from_cbor(const std::vector<uint8_t>& v) static basic_json from_cbor(const std::vector<uint8_t>& v,
const size_t start_index = 0)
{ {
size_t i = 0; size_t i = start_index;
return from_cbor_internal(v, i); return from_cbor_internal(v, i);
} }

View file

@ -1184,6 +1184,10 @@ TEST_CASE("single CBOR roundtrip")
// compare parsed JSON values // compare parsed JSON values
CHECK(j1 == j2); CHECK(j1 == j2);
// check with different start index
packed.insert(packed.begin(), 5, 0xff);
CHECK(j1 == json::from_cbor(packed, 5));
} }
} }

View file

@ -1039,6 +1039,10 @@ TEST_CASE("single MessagePack roundtrip")
// compare parsed JSON values // compare parsed JSON values
CHECK(j1 == j2); CHECK(j1 == j2);
// check with different start index
packed.insert(packed.begin(), 5, 0xff);
CHECK(j1 == json::from_msgpack(packed, 5));
} }
} }

View file

@ -385,7 +385,7 @@ TEST_CASE("regression tests")
{ {
return '.'; return '.';
} }
std::string do_grouping() const std::string do_grouping() const
{ {
return "\03"; return "\03";