Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
9e1abb48
Unverified
Commit
9e1abb48
authored
Mar 20, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✅
improved coverage
parent
1e38ffc0
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
410 additions
and
178 deletions
+410
-178
include/nlohmann/detail/input/binary_reader.hpp
include/nlohmann/detail/input/binary_reader.hpp
+10
-8
include/nlohmann/detail/input/input_adapters.hpp
include/nlohmann/detail/input/input_adapters.hpp
+3
-0
include/nlohmann/detail/input/json_sax.hpp
include/nlohmann/detail/input/json_sax.hpp
+1
-25
include/nlohmann/detail/input/lexer.hpp
include/nlohmann/detail/input/lexer.hpp
+1
-1
include/nlohmann/detail/input/parser.hpp
include/nlohmann/detail/input/parser.hpp
+14
-11
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+24
-35
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+53
-80
test/src/unit-cbor.cpp
test/src/unit-cbor.cpp
+94
-0
test/src/unit-class_parser.cpp
test/src/unit-class_parser.cpp
+1
-12
test/src/unit-deserialization.cpp
test/src/unit-deserialization.cpp
+0
-6
test/src/unit-msgpack.cpp
test/src/unit-msgpack.cpp
+94
-0
test/src/unit-ubjson.cpp
test/src/unit-ubjson.cpp
+115
-0
No files found.
include/nlohmann/detail/input/binary_reader.hpp
View file @
9e1abb48
...
...
@@ -41,9 +41,6 @@ class binary_reader
using
json_sax_t
=
json_sax
<
BasicJsonType
>
;
public:
/// the supported binary input formats
enum
class
binary_format_t
{
cbor
,
msgpack
,
ubjson
};
/*!
@brief create a binary reader
...
...
@@ -61,30 +58,35 @@ class binary_reader
@return
*/
bool
sax_parse
(
const
binary_format_t
format
,
json_sax_t
*
sax_
,
const
bool
strict
)
bool
sax_parse
(
const
input_format_t
format
,
json_sax_t
*
sax_
,
const
bool
strict
=
true
)
{
sax
=
sax_
;
bool
result
;
switch
(
format
)
{
case
binary
_format_t
:
:
cbor
:
case
input
_format_t
:
:
cbor
:
result
=
parse_cbor_internal
();
break
;
case
binary
_format_t
:
:
msgpack
:
case
input
_format_t
:
:
msgpack
:
result
=
parse_msgpack_internal
();
break
;
case
binary
_format_t
:
:
ubjson
:
case
input
_format_t
:
:
ubjson
:
result
=
parse_ubjson_internal
();
break
;
default:
assert
(
false
);
// LCOV_EXCL_LINE
}
// strict mode: next byte must be EOF
if
(
result
and
strict
)
{
if
(
format
==
binary
_format_t
::
ubjson
)
if
(
format
==
input
_format_t
::
ubjson
)
{
get_ignore_noop
();
}
...
...
include/nlohmann/detail/input/input_adapters.hpp
View file @
9e1abb48
...
...
@@ -20,6 +20,9 @@ namespace nlohmann
{
namespace
detail
{
/// the supported input formats
enum
class
input_format_t
{
json
,
cbor
,
msgpack
,
ubjson
};
////////////////////
// input adapters //
////////////////////
...
...
include/nlohmann/detail/input/json_sax.hpp
View file @
9e1abb48
...
...
@@ -105,21 +105,12 @@ struct json_sax
*/
virtual
bool
end_array
()
=
0
;
/*!
@brief a binary value was read
@param[in] val byte vector
@return whether parsing should proceed
@note examples are CBOR type 2 strings, MessagePack bin, and maybe UBJSON
array<uint8t>
*/
virtual
bool
binary
(
const
std
::
vector
<
uint8_t
>&
val
)
=
0
;
/*!
@brief a parse error occurred
@param[in] position the position in the input where the error occurs
@param[in] last_token the last read token
@param[in] error_msg a detailed error message
@return whether parsing should proceed
@return whether parsing should proceed
(must return false)
*/
virtual
bool
parse_error
(
std
::
size_t
position
,
const
std
::
string
&
last_token
,
...
...
@@ -225,11 +216,6 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
return
true
;
}
bool
binary
(
const
std
::
vector
<
uint8_t
>&
)
override
{
return
true
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
detail
::
exception
&
ex
)
override
{
...
...
@@ -430,11 +416,6 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
return
true
;
}
bool
binary
(
const
std
::
vector
<
uint8_t
>&
)
override
{
return
true
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
detail
::
exception
&
ex
)
override
{
...
...
@@ -580,11 +561,6 @@ class json_sax_acceptor : public json_sax<BasicJsonType>
return
true
;
}
bool
binary
(
const
std
::
vector
<
uint8_t
>&
)
override
{
return
true
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
detail
::
exception
&
)
override
{
return
false
;
...
...
include/nlohmann/detail/input/lexer.hpp
View file @
9e1abb48
...
...
@@ -99,7 +99,7 @@ class lexer
}
}
explicit
lexer
(
detail
::
input_adapter_t
adapter
)
explicit
lexer
(
detail
::
input_adapter_t
&&
adapter
)
:
ia
(
std
::
move
(
adapter
)),
decimal_point_char
(
get_decimal_point
())
{}
// delete because of pointer members
...
...
include/nlohmann/detail/input/parser.hpp
View file @
9e1abb48
...
...
@@ -60,10 +60,10 @@ class parser
std
::
function
<
bool
(
int
depth
,
parse_event_t
event
,
BasicJsonType
&
parsed
)
>
;
/// a parser reading from an input adapter
explicit
parser
(
detail
::
input_adapter_t
adapter
,
explicit
parser
(
detail
::
input_adapter_t
&&
adapter
,
const
parser_callback_t
cb
=
nullptr
,
const
bool
allow_exceptions_
=
true
)
:
callback
(
cb
),
m_lexer
(
adapter
),
allow_exceptions
(
allow_exceptions_
)
:
callback
(
cb
),
m_lexer
(
std
::
move
(
adapter
)
),
allow_exceptions
(
allow_exceptions_
)
{
// read first token
get_token
();
...
...
@@ -160,19 +160,22 @@ class parser
bool
accept
(
const
bool
strict
=
true
)
{
json_sax_acceptor
<
BasicJsonType
>
sax_acceptor
;
return
sax_parse
(
&
sax_acceptor
,
strict
);
}
bool
sax_parse
(
json_sax_t
*
sax
,
const
bool
strict
=
true
)
{
const
bool
result
=
sax_parse_internal
(
sax
);
if
(
not
sax_parse_internal
(
&
sax_acceptor
))
// strict mode: next byte must be EOF
if
(
result
and
strict
and
(
get_token
()
!=
token_type
::
end_of_input
))
{
return
false
;
return
sax
->
parse_error
(
m_lexer
.
get_position
(),
m_lexer
.
get_token_string
(),
parse_error
::
create
(
101
,
m_lexer
.
get_position
(),
exception_message
(
token_type
::
end_of_input
)));
}
// strict => last token must be EOF
return
not
strict
or
(
get_token
()
==
token_type
::
end_of_input
);
}
bool
sax_parse
(
json_sax_t
*
sax
)
{
return
sax_parse_internal
(
sax
);
return
result
;
}
private:
...
...
include/nlohmann/json.hpp
View file @
9e1abb48
...
...
@@ -209,6 +209,8 @@ class basic_json
/// helper type for initializer lists of basic_json values
using
initializer_list_t
=
std
::
initializer_list
<
detail
::
json_ref
<
basic_json
>>
;
using
input_format_t
=
detail
::
input_format_t
;
////////////////
// exceptions //
////////////////
...
...
@@ -5996,19 +5998,7 @@ class basic_json
@since version 2.0.3 (contiguous containers)
*/
static
basic_json
parse
(
detail
::
input_adapter
i
,
const
parser_callback_t
cb
=
nullptr
,
const
bool
allow_exceptions
=
true
)
{
basic_json
result
;
parser
(
i
,
cb
,
allow_exceptions
).
parse
(
true
,
result
);
return
result
;
}
/*!
@copydoc basic_json parse(detail::input_adapter, const parser_callback_t)
*/
static
basic_json
parse
(
detail
::
input_adapter
&
i
,
static
basic_json
parse
(
detail
::
input_adapter
&&
i
,
const
parser_callback_t
cb
=
nullptr
,
const
bool
allow_exceptions
=
true
)
{
...
...
@@ -6017,24 +6007,23 @@ class basic_json
return
result
;
}
static
bool
accept
(
detail
::
input_adapter
i
)
static
bool
accept
(
detail
::
input_adapter
&&
i
)
{
return
parser
(
i
).
accept
(
true
);
}
static
bool
accept
(
detail
::
input_adapter
&
i
)
static
bool
sax_parse
(
detail
::
input_adapter
&&
i
,
json_sax_t
*
sax
,
input_format_t
format
=
input_format_t
::
json
,
const
bool
strict
=
true
)
{
return
parser
(
i
).
accept
(
true
);
}
static
bool
sax_parse
(
detail
::
input_adapter
i
,
json_sax_t
*
sax
)
{
return
parser
(
i
).
sax_parse
(
sax
);
}
static
bool
sax_parse
(
detail
::
input_adapter
&
i
,
json_sax_t
*
sax
)
{
return
parser
(
i
).
sax_parse
(
sax
);
assert
(
sax
);
switch
(
format
)
{
case
input_format_t
:
:
json
:
return
parser
(
std
::
move
(
i
)).
sax_parse
(
sax
,
strict
);
default:
return
binary_reader
(
std
::
move
(
i
)).
sax_parse
(
format
,
sax
,
strict
);
}
}
/*!
...
...
@@ -6639,13 +6628,13 @@ class basic_json
@a strict parameter since 3.0.0; added @allow_exceptions parameter
since 3.2.0
*/
static
basic_json
from_cbor
(
detail
::
input_adapter
i
,
static
basic_json
from_cbor
(
detail
::
input_adapter
&&
i
,
const
bool
strict
=
true
,
const
bool
allow_exceptions
=
true
)
{
basic_json
result
;
detail
::
json_sax_dom_parser
<
basic_json
>
sdp
(
result
,
allow_exceptions
);
const
bool
res
=
binary_reader
(
detail
::
input_adapter
(
i
)).
sax_parse
(
binary_reader
::
binary
_format_t
::
cbor
,
&
sdp
,
strict
);
const
bool
res
=
binary_reader
(
detail
::
input_adapter
(
i
)).
sax_parse
(
input
_format_t
::
cbor
,
&
sdp
,
strict
);
return
res
?
result
:
basic_json
(
value_t
::
discarded
);
}
...
...
@@ -6660,7 +6649,7 @@ class basic_json
{
basic_json
result
;
detail
::
json_sax_dom_parser
<
basic_json
>
sdp
(
result
,
allow_exceptions
);
const
bool
res
=
binary_reader
(
detail
::
input_adapter
(
std
::
forward
<
A1
>
(
a1
),
std
::
forward
<
A2
>
(
a2
))).
sax_parse
(
binary_reader
::
binary
_format_t
::
cbor
,
&
sdp
,
strict
);
const
bool
res
=
binary_reader
(
detail
::
input_adapter
(
std
::
forward
<
A1
>
(
a1
),
std
::
forward
<
A2
>
(
a2
))).
sax_parse
(
input
_format_t
::
cbor
,
&
sdp
,
strict
);
return
res
?
result
:
basic_json
(
value_t
::
discarded
);
}
...
...
@@ -6742,13 +6731,13 @@ class basic_json
@a strict parameter since 3.0.0; added @allow_exceptions parameter
since 3.2.0
*/
static
basic_json
from_msgpack
(
detail
::
input_adapter
i
,
static
basic_json
from_msgpack
(
detail
::
input_adapter
&&
i
,
const
bool
strict
=
true
,
const
bool
allow_exceptions
=
true
)
{
basic_json
result
;
detail
::
json_sax_dom_parser
<
basic_json
>
sdp
(
result
,
allow_exceptions
);
const
bool
res
=
binary_reader
(
detail
::
input_adapter
(
i
)).
sax_parse
(
binary_reader
::
binary
_format_t
::
msgpack
,
&
sdp
,
strict
);
const
bool
res
=
binary_reader
(
detail
::
input_adapter
(
i
)).
sax_parse
(
input
_format_t
::
msgpack
,
&
sdp
,
strict
);
return
res
?
result
:
basic_json
(
value_t
::
discarded
);
}
...
...
@@ -6763,7 +6752,7 @@ class basic_json
{
basic_json
result
;
detail
::
json_sax_dom_parser
<
basic_json
>
sdp
(
result
,
allow_exceptions
);
const
bool
res
=
binary_reader
(
detail
::
input_adapter
(
std
::
forward
<
A1
>
(
a1
),
std
::
forward
<
A2
>
(
a2
))).
sax_parse
(
binary_reader
::
binary
_format_t
::
msgpack
,
&
sdp
,
strict
);
const
bool
res
=
binary_reader
(
detail
::
input_adapter
(
std
::
forward
<
A1
>
(
a1
),
std
::
forward
<
A2
>
(
a2
))).
sax_parse
(
input
_format_t
::
msgpack
,
&
sdp
,
strict
);
return
res
?
result
:
basic_json
(
value_t
::
discarded
);
}
...
...
@@ -6824,13 +6813,13 @@ class basic_json
@since version 3.1.0; added @allow_exceptions parameter since 3.2.0
*/
static
basic_json
from_ubjson
(
detail
::
input_adapter
i
,
static
basic_json
from_ubjson
(
detail
::
input_adapter
&&
i
,
const
bool
strict
=
true
,
const
bool
allow_exceptions
=
true
)
{
basic_json
result
;
detail
::
json_sax_dom_parser
<
basic_json
>
sdp
(
result
,
allow_exceptions
);
const
bool
res
=
binary_reader
(
detail
::
input_adapter
(
i
)).
sax_parse
(
binary_reader
::
binary
_format_t
::
ubjson
,
&
sdp
,
strict
);
const
bool
res
=
binary_reader
(
detail
::
input_adapter
(
i
)).
sax_parse
(
input
_format_t
::
ubjson
,
&
sdp
,
strict
);
return
res
?
result
:
basic_json
(
value_t
::
discarded
);
}
...
...
@@ -6845,7 +6834,7 @@ class basic_json
{
basic_json
result
;
detail
::
json_sax_dom_parser
<
basic_json
>
sdp
(
result
,
allow_exceptions
);
const
bool
res
=
binary_reader
(
detail
::
input_adapter
(
std
::
forward
<
A1
>
(
a1
),
std
::
forward
<
A2
>
(
a2
))).
sax_parse
(
binary_reader
::
binary
_format_t
::
ubjson
,
&
sdp
,
strict
);
const
bool
res
=
binary_reader
(
detail
::
input_adapter
(
std
::
forward
<
A1
>
(
a1
),
std
::
forward
<
A2
>
(
a2
))).
sax_parse
(
input
_format_t
::
ubjson
,
&
sdp
,
strict
);
return
res
?
result
:
basic_json
(
value_t
::
discarded
);
}
...
...
single_include/nlohmann/json.hpp
View file @
9e1abb48
This diff is collapsed.
Click to expand it.
test/src/unit-cbor.cpp
View file @
9e1abb48
...
...
@@ -33,6 +33,76 @@ using nlohmann::json;
#include <fstream>
class
SaxCountdown
:
public
nlohmann
::
json
::
json_sax_t
{
public:
explicit
SaxCountdown
(
const
int
count
)
:
events_left
(
count
)
{}
bool
null
()
override
{
return
events_left
--
>
0
;
}
bool
boolean
(
bool
)
override
{
return
events_left
--
>
0
;
}
bool
number_integer
(
json
::
number_integer_t
)
override
{
return
events_left
--
>
0
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
)
override
{
return
events_left
--
>
0
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
override
{
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&&
)
override
{
return
events_left
--
>
0
;
}
bool
start_object
(
std
::
size_t
)
override
{
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&&
)
override
{
return
events_left
--
>
0
;
}
bool
end_object
()
override
{
return
events_left
--
>
0
;
}
bool
start_array
(
std
::
size_t
)
override
{
return
events_left
--
>
0
;
}
bool
end_array
()
override
{
return
events_left
--
>
0
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
{
return
false
;
}
private:
int
events_left
=
0
;
};
TEST_CASE
(
"CBOR"
)
{
SECTION
(
"individual values"
)
...
...
@@ -1467,6 +1537,30 @@ TEST_CASE("CBOR")
}
}
}
SECTION
(
"SAX aborts"
)
{
SECTION
(
"start_array(len)"
)
{
std
::
vector
<
uint8_t
>
v
=
{
0x83
,
0x01
,
0x02
,
0x03
};
SaxCountdown
scp
(
0
);
CHECK
(
not
json
::
sax_parse
(
v
,
&
scp
,
json
::
input_format_t
::
cbor
));
}
SECTION
(
"start_object(len)"
)
{
std
::
vector
<
uint8_t
>
v
=
{
0xA1
,
0x63
,
0x66
,
0x6F
,
0x6F
,
0xF4
};
SaxCountdown
scp
(
0
);
CHECK
(
not
json
::
sax_parse
(
v
,
&
scp
,
json
::
input_format_t
::
cbor
));
}
SECTION
(
"key()"
)
{
std
::
vector
<
uint8_t
>
v
=
{
0xA1
,
0x63
,
0x66
,
0x6F
,
0x6F
,
0xF4
};
SaxCountdown
scp
(
1
);
CHECK
(
not
json
::
sax_parse
(
v
,
&
scp
,
json
::
input_format_t
::
cbor
));
}
}
}
// use this testcase outside [hide] to run it with Valgrind
...
...
test/src/unit-class_parser.cpp
View file @
9e1abb48
...
...
@@ -117,12 +117,6 @@ class SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
binary
(
const
std
::
vector
<
uint8_t
>&
)
override
{
events
.
push_back
(
"binary()"
);
return
true
;
}
bool
parse_error
(
std
::
size_t
position
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
{
errored
=
true
;
...
...
@@ -195,11 +189,6 @@ class SaxCountdown : public nlohmann::json::json_sax_t
return
events_left
--
>
0
;
}
bool
binary
(
const
std
::
vector
<
uint8_t
>&
)
override
{
return
events_left
--
>
0
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
{
return
false
;
...
...
@@ -248,7 +237,7 @@ bool accept_helper(const std::string& s)
// 4. parse with SAX (compare with relaxed accept result)
SaxEventLogger
el
;
CHECK_NOTHROW
(
json
::
sax_parse
(
s
,
&
el
));
CHECK_NOTHROW
(
json
::
sax_parse
(
s
,
&
el
,
json
::
input_format_t
::
json
,
false
));
CHECK
(
json
::
parser
(
nlohmann
::
detail
::
input_adapter
(
s
)).
accept
(
false
)
==
not
el
.
errored
);
// 5. parse with simple callback
...
...
test/src/unit-deserialization.cpp
View file @
9e1abb48
...
...
@@ -116,12 +116,6 @@ struct SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
binary
(
const
std
::
vector
<
uint8_t
>&
)
override
{
events
.
push_back
(
"binary()"
);
return
true
;
}
bool
parse_error
(
std
::
size_t
position
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
{
events
.
push_back
(
"parse_error("
+
std
::
to_string
(
position
)
+
")"
);
...
...
test/src/unit-msgpack.cpp
View file @
9e1abb48
...
...
@@ -33,6 +33,76 @@ using nlohmann::json;
#include <fstream>
class
SaxCountdown
:
public
nlohmann
::
json
::
json_sax_t
{
public:
explicit
SaxCountdown
(
const
int
count
)
:
events_left
(
count
)
{}
bool
null
()
override
{
return
events_left
--
>
0
;
}
bool
boolean
(
bool
)
override
{
return
events_left
--
>
0
;
}
bool
number_integer
(
json
::
number_integer_t
)
override
{
return
events_left
--
>
0
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
)
override
{
return
events_left
--
>
0
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
override
{
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&&
)
override
{
return
events_left
--
>
0
;
}
bool
start_object
(
std
::
size_t
)
override
{
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&&
)
override
{
return
events_left
--
>
0
;
}
bool
end_object
()
override
{
return
events_left
--
>
0
;
}
bool
start_array
(
std
::
size_t
)
override
{
return
events_left
--
>
0
;
}
bool
end_array
()
override
{
return
events_left
--
>
0
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
{
return
false
;
}
private:
int
events_left
=
0
;
};
TEST_CASE
(
"MessagePack"
)
{
SECTION
(
"individual values"
)
...
...
@@ -1200,6 +1270,30 @@ TEST_CASE("MessagePack")
}
}
}
SECTION
(
"SAX aborts"
)
{
SECTION
(
"start_array(len)"
)
{
std
::
vector
<
uint8_t
>
v
=
{
0x93
,
0x01
,
0x02
,
0x03
};
SaxCountdown
scp
(
0
);
CHECK
(
not
json
::
sax_parse
(
v
,
&
scp
,
json
::
input_format_t
::
msgpack
));
}
SECTION
(
"start_object(len)"
)
{
std
::
vector
<
uint8_t
>
v
=
{
0x81
,
0xa3
,
0x66
,
0x6F
,
0x6F
,
0xc2
};
SaxCountdown
scp
(
0
);
CHECK
(
not
json
::
sax_parse
(
v
,
&
scp
,
json
::
input_format_t
::
msgpack
));
}
SECTION
(
"key()"
)
{
std
::
vector
<
uint8_t
>
v
=
{
0x81
,
0xa3
,
0x66
,
0x6F
,
0x6F
,
0xc2
};
SaxCountdown
scp
(
1
);
CHECK
(
not
json
::
sax_parse
(
v
,
&
scp
,
json
::
input_format_t
::
msgpack
));
}
}
}
...
...
test/src/unit-ubjson.cpp
View file @
9e1abb48
...
...
@@ -33,6 +33,76 @@ using nlohmann::json;
#include <fstream>
class
SaxCountdown
:
public
nlohmann
::
json
::
json_sax_t
{
public:
explicit
SaxCountdown
(
const
int
count
)
:
events_left
(
count
)
{}
bool
null
()
override
{
return
events_left
--
>
0
;
}
bool
boolean
(
bool
)
override
{
return
events_left
--
>
0
;
}
bool
number_integer
(
json
::
number_integer_t
)
override
{
return
events_left
--
>
0
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
)
override
{
return
events_left
--
>
0
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
override
{
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&&
)
override
{
return
events_left
--
>
0
;
}
bool
start_object
(
std
::
size_t
)
override
{
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&&
)
override
{
return
events_left
--
>
0
;
}
bool
end_object
()
override
{
return
events_left
--
>
0
;
}
bool
start_array
(
std
::
size_t
)
override
{
return
events_left
--
>
0
;
}
bool
end_array
()
override
{
return
events_left
--
>
0
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
{
return
false
;
}
private:
int
events_left
=
0
;
};
TEST_CASE
(
"UBJSON"
)
{
SECTION
(
"individual values"
)
...
...
@@ -1241,6 +1311,51 @@ TEST_CASE("UBJSON")
}
}
SECTION
(
"SAX aborts"
)
{
SECTION
(
"start_array()"
)
{
std
::
vector
<
uint8_t
>
v
=
{
'['
,
'T'
,
'F'
,
']'
};
SaxCountdown
scp
(
0
);
CHECK
(
not
json
::
sax_parse
(
v
,
&
scp
,
json
::
input_format_t
::
ubjson
));
}
SECTION
(
"start_object()"
)
{
std
::
vector
<
uint8_t
>
v
=
{
'{'
,
'i'
,
3
,
'f'
,
'o'
,
'o'
,
'F'
,
'}'
};
SaxCountdown
scp
(
0
);
CHECK
(
not
json
::
sax_parse
(
v
,
&
scp
,
json
::
input_format_t
::
ubjson
));
}
SECTION
(
"key() in object"
)
{
std
::
vector
<
uint8_t
>
v
=
{
'{'
,
'i'
,
3
,
'f'
,
'o'
,
'o'
,
'F'
,
'}'
};
SaxCountdown
scp
(
1
);
CHECK
(
not
json
::
sax_parse
(
v
,
&
scp
,
json
::
input_format_t
::
ubjson
));
}
SECTION
(
"start_array(len)"
)
{
std
::
vector
<
uint8_t
>
v
=
{
'['
,
'#'
,
'i'
,
'2'
,
'T'
,
'F'
};
SaxCountdown
scp
(
0
);
CHECK
(
not
json
::
sax_parse
(
v
,
&
scp
,
json
::
input_format_t
::
ubjson
));
}
SECTION
(
"start_object(len)"
)
{
std
::
vector
<
uint8_t
>
v
=
{
'{'
,
'#'
,
'i'
,
'1'
,
3
,
'f'
,
'o'
,
'o'
,
'F'
};
SaxCountdown
scp
(
0
);
CHECK
(
not
json
::
sax_parse
(
v
,
&
scp
,
json
::
input_format_t
::
ubjson
));
}
SECTION
(
"key() in object with length"
)
{
std
::
vector
<
uint8_t
>
v
=
{
'{'
,
'i'
,
3
,
'f'
,
'o'
,
'o'
,
'F'
,
'}'
};
SaxCountdown
scp
(
1
);
CHECK
(
not
json
::
sax_parse
(
v
,
&
scp
,
json
::
input_format_t
::
ubjson
));
}
}
SECTION
(
"parsing values"
)
{
SECTION
(
"strings"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment