Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
442886d0
Unverified
Commit
442886d0
authored
Jul 02, 2018
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use templates in the sax interface instead of virtuals
parent
f6febbe3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
146 additions
and
147 deletions
+146
-147
binary_reader.hpp
include/nlohmann/detail/input/binary_reader.hpp
+10
-10
json_sax.hpp
include/nlohmann/detail/input/json_sax.hpp
+39
-39
parser.hpp
include/nlohmann/detail/input/parser.hpp
+6
-6
json.hpp
include/nlohmann/json.hpp
+6
-7
json.hpp
single_include/nlohmann/json.hpp
+0
-0
unit-cbor.cpp
test/src/unit-cbor.cpp
+13
-13
unit-class_parser.cpp
test/src/unit-class_parser.cpp
+28
-28
unit-deserialization.cpp
test/src/unit-deserialization.cpp
+18
-18
unit-msgpack.cpp
test/src/unit-msgpack.cpp
+13
-13
unit-ubjson.cpp
test/src/unit-ubjson.cpp
+13
-13
No files found.
include/nlohmann/detail/input/binary_reader.hpp
View file @
442886d0
...
...
@@ -30,14 +30,14 @@ namespace detail
/*!
@brief deserialization of CBOR, MessagePack, and UBJSON values
*/
template
<
typename
BasicJsonType
>
template
<
typename
BasicJsonType
,
typename
SAX
=
json_sax_dom_parser
<
BasicJsonType
>
>
class
binary_reader
{
using
number_integer_t
=
typename
BasicJsonType
::
number_integer_t
;
using
number_unsigned_t
=
typename
BasicJsonType
::
number_unsigned_t
;
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
using
string_t
=
typename
BasicJsonType
::
string_t
;
using
json_sax_t
=
json_sax
<
BasicJsonType
>
;
using
json_sax_t
=
SAX
;
public
:
/*!
...
...
@@ -321,7 +321,7 @@ class binary_reader
}
case
0x9F
:
// array (indefinite length)
return
get_cbor_array
(
json_sax_t
::
no_limit
);
return
get_cbor_array
(
std
::
size_t
(
-
1
)
);
// map (0x00..0x17 pairs of data items follow)
case
0xA0
:
...
...
@@ -375,7 +375,7 @@ class binary_reader
}
case
0xBF
:
// map (indefinite length)
return
get_cbor_object
(
json_sax_t
::
no_limit
);
return
get_cbor_object
(
std
::
size_t
(
-
1
)
);
case
0xF4
:
// false
return
sax
->
boolean
(
false
);
...
...
@@ -1020,7 +1020,7 @@ class binary_reader
}
/*!
@param[in] len the length of the array or
json_sax_t::no_limit
for an
@param[in] len the length of the array or
std::size_t(-1)
for an
array of indefinite size
@return whether array creation completed
*/
...
...
@@ -1031,7 +1031,7 @@ class binary_reader
return
false
;
}
if
(
len
!=
json_sax_t
::
no_limit
)
if
(
len
!=
std
::
size_t
(
-
1
)
)
for
(
std
::
size_t
i
=
0
;
i
<
len
;
++
i
)
{
if
(
JSON_UNLIKELY
(
not
parse_cbor_internal
()))
...
...
@@ -1054,7 +1054,7 @@ class binary_reader
}
/*!
@param[in] len the length of the object or
json_sax_t::no_limit
for an
@param[in] len the length of the object or
std::size_t(-1)
for an
object of indefinite size
@return whether object creation completed
*/
...
...
@@ -1066,7 +1066,7 @@ class binary_reader
}
string_t
key
;
if
(
len
!=
json_sax_t
::
no_limit
)
if
(
len
!=
std
::
size_t
(
-
1
)
)
{
for
(
std
::
size_t
i
=
0
;
i
<
len
;
++
i
)
{
...
...
@@ -1558,7 +1558,7 @@ class binary_reader
}
else
{
if
(
JSON_UNLIKELY
(
not
sax
->
start_array
()))
if
(
JSON_UNLIKELY
(
not
sax
->
start_array
(
-
1
)))
{
return
false
;
}
...
...
@@ -1628,7 +1628,7 @@ class binary_reader
}
else
{
if
(
JSON_UNLIKELY
(
not
sax
->
start_object
()))
if
(
JSON_UNLIKELY
(
not
sax
->
start_object
(
-
1
)))
{
return
false
;
}
...
...
include/nlohmann/detail/input/json_sax.hpp
View file @
442886d0
...
...
@@ -136,7 +136,7 @@ constructor contains the parsed value.
@tparam BasicJsonType the JSON type
*/
template
<
typename
BasicJsonType
>
class
json_sax_dom_parser
:
public
json_sax
<
BasicJsonType
>
class
json_sax_dom_parser
{
public
:
using
number_integer_t
=
typename
BasicJsonType
::
number_integer_t
;
...
...
@@ -153,43 +153,43 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
:
root
(
r
),
allow_exceptions
(
allow_exceptions_
)
{}
bool
null
()
override
bool
null
()
{
handle_value
(
nullptr
);
return
true
;
}
bool
boolean
(
bool
val
)
override
bool
boolean
(
bool
val
)
{
handle_value
(
val
);
return
true
;
}
bool
number_integer
(
number_integer_t
val
)
override
bool
number_integer
(
number_integer_t
val
)
{
handle_value
(
val
);
return
true
;
}
bool
number_unsigned
(
number_unsigned_t
val
)
override
bool
number_unsigned
(
number_unsigned_t
val
)
{
handle_value
(
val
);
return
true
;
}
bool
number_float
(
number_float_t
val
,
const
string_t
&
)
override
bool
number_float
(
number_float_t
val
,
const
string_t
&
)
{
handle_value
(
val
);
return
true
;
}
bool
string
(
string_t
&
val
)
override
bool
string
(
string_t
&
val
)
{
handle_value
(
val
);
return
true
;
}
bool
start_object
(
std
::
size_t
len
)
override
bool
start_object
(
std
::
size_t
len
=
-
1
)
{
ref_stack
.
push_back
(
handle_value
(
BasicJsonType
::
value_t
::
object
));
...
...
@@ -202,20 +202,20 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
return
true
;
}
bool
key
(
string_t
&
val
)
override
bool
key
(
string_t
&
val
)
{
// add null at given key and store the reference for later
object_element
=
&
(
ref_stack
.
back
()
->
m_value
.
object
->
operator
[](
val
));
return
true
;
}
bool
end_object
()
override
bool
end_object
()
{
ref_stack
.
pop_back
();
return
true
;
}
bool
start_array
(
std
::
size_t
len
)
override
bool
start_array
(
std
::
size_t
len
=
-
1
)
{
ref_stack
.
push_back
(
handle_value
(
BasicJsonType
::
value_t
::
array
));
...
...
@@ -228,14 +228,14 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
return
true
;
}
bool
end_array
()
override
bool
end_array
()
{
ref_stack
.
pop_back
();
return
true
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
detail
::
exception
&
ex
)
override
const
detail
::
exception
&
ex
)
{
errored
=
true
;
if
(
allow_exceptions
)
...
...
@@ -310,7 +310,7 @@ class json_sax_dom_parser : public json_sax<BasicJsonType>
};
template
<
typename
BasicJsonType
>
class
json_sax_dom_callback_parser
:
public
json_sax
<
BasicJsonType
>
class
json_sax_dom_callback_parser
{
public
:
using
number_integer_t
=
typename
BasicJsonType
::
number_integer_t
;
...
...
@@ -328,43 +328,43 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
keep_stack
.
push_back
(
true
);
}
bool
null
()
override
bool
null
()
{
handle_value
(
nullptr
);
return
true
;
}
bool
boolean
(
bool
val
)
override
bool
boolean
(
bool
val
)
{
handle_value
(
val
);
return
true
;
}
bool
number_integer
(
number_integer_t
val
)
override
bool
number_integer
(
number_integer_t
val
)
{
handle_value
(
val
);
return
true
;
}
bool
number_unsigned
(
number_unsigned_t
val
)
override
bool
number_unsigned
(
number_unsigned_t
val
)
{
handle_value
(
val
);
return
true
;
}
bool
number_float
(
number_float_t
val
,
const
string_t
&
)
override
bool
number_float
(
number_float_t
val
,
const
string_t
&
)
{
handle_value
(
val
);
return
true
;
}
bool
string
(
string_t
&
val
)
override
bool
string
(
string_t
&
val
)
{
handle_value
(
val
);
return
true
;
}
bool
start_object
(
std
::
size_t
len
)
override
bool
start_object
(
std
::
size_t
len
=
-
1
)
{
// check callback for object start
const
bool
keep
=
callback
(
static_cast
<
int
>
(
ref_stack
.
size
()),
parse_event_t
::
object_start
,
discarded
);
...
...
@@ -386,7 +386,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
return
true
;
}
bool
key
(
string_t
&
val
)
override
bool
key
(
string_t
&
val
)
{
BasicJsonType
k
=
BasicJsonType
(
val
);
...
...
@@ -403,7 +403,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
return
true
;
}
bool
end_object
()
override
bool
end_object
()
{
if
(
ref_stack
.
back
())
{
...
...
@@ -438,7 +438,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
return
true
;
}
bool
start_array
(
std
::
size_t
len
)
override
bool
start_array
(
std
::
size_t
len
=
-
1
)
{
const
bool
keep
=
callback
(
static_cast
<
int
>
(
ref_stack
.
size
()),
parse_event_t
::
array_start
,
discarded
);
keep_stack
.
push_back
(
keep
);
...
...
@@ -459,7 +459,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
return
true
;
}
bool
end_array
()
override
bool
end_array
()
{
bool
keep
=
true
;
...
...
@@ -491,7 +491,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
detail
::
exception
&
ex
)
override
const
detail
::
exception
&
ex
)
{
errored
=
true
;
if
(
allow_exceptions
)
...
...
@@ -614,7 +614,7 @@ class json_sax_dom_callback_parser : public json_sax<BasicJsonType>
};
template
<
typename
BasicJsonType
>
class
json_sax_acceptor
:
public
json_sax
<
BasicJsonType
>
class
json_sax_acceptor
{
public
:
using
number_integer_t
=
typename
BasicJsonType
::
number_integer_t
;
...
...
@@ -622,62 +622,62 @@ class json_sax_acceptor : public json_sax<BasicJsonType>
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
using
string_t
=
typename
BasicJsonType
::
string_t
;
bool
null
()
override
bool
null
()
{
return
true
;
}
bool
boolean
(
bool
)
override
bool
boolean
(
bool
)
{
return
true
;
}
bool
number_integer
(
number_integer_t
)
override
bool
number_integer
(
number_integer_t
)
{
return
true
;
}
bool
number_unsigned
(
number_unsigned_t
)
override
bool
number_unsigned
(
number_unsigned_t
)
{
return
true
;
}
bool
number_float
(
number_float_t
,
const
string_t
&
)
override
bool
number_float
(
number_float_t
,
const
string_t
&
)
{
return
true
;
}
bool
string
(
string_t
&
)
override
bool
string
(
string_t
&
)
{
return
true
;
}
bool
start_object
(
std
::
size_t
)
override
bool
start_object
(
std
::
size_t
=
-
1
)
{
return
true
;
}
bool
key
(
string_t
&
)
override
bool
key
(
string_t
&
)
{
return
true
;
}
bool
end_object
()
override
bool
end_object
()
{
return
true
;
}
bool
start_array
(
std
::
size_t
)
override
bool
start_array
(
std
::
size_t
=
-
1
)
{
return
true
;
}
bool
end_array
()
override
bool
end_array
()
{
return
true
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
detail
::
exception
&
)
override
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
detail
::
exception
&
)
{
return
false
;
}
...
...
include/nlohmann/detail/input/parser.hpp
View file @
442886d0
...
...
@@ -54,8 +54,6 @@ class parser
value
};
using
json_sax_t
=
json_sax
<
BasicJsonType
>
;
using
parser_callback_t
=
std
::
function
<
bool
(
int
depth
,
parse_event_t
event
,
BasicJsonType
&
parsed
)
>
;
...
...
@@ -144,7 +142,8 @@ class parser
return
sax_parse
(
&
sax_acceptor
,
strict
);
}
bool
sax_parse
(
json_sax_t
*
sax
,
const
bool
strict
=
true
)
template
<
typename
SAX
>
bool
sax_parse
(
SAX
*
sax
,
const
bool
strict
=
true
)
{
const
bool
result
=
sax_parse_internal
(
sax
);
...
...
@@ -160,7 +159,8 @@ class parser
}
private
:
bool
sax_parse_internal
(
json_sax_t
*
sax
)
template
<
typename
SAX
>
bool
sax_parse_internal
(
SAX
*
sax
)
{
// stack to remember the hieararchy of structured values we are parsing
// true = array; false = object
...
...
@@ -177,7 +177,7 @@ class parser
{
case
token_type
:
:
begin_object
:
{
if
(
JSON_UNLIKELY
(
not
sax
->
start_object
()))
if
(
JSON_UNLIKELY
(
not
sax
->
start_object
(
-
1
)))
{
return
false
;
}
...
...
@@ -225,7 +225,7 @@ class parser
case
token_type
:
:
begin_array
:
{
if
(
JSON_UNLIKELY
(
not
sax
->
start_array
()))
if
(
JSON_UNLIKELY
(
not
sax
->
start_array
(
-
1
)))
{
return
false
;
}
...
...
include/nlohmann/json.hpp
View file @
442886d0
...
...
@@ -171,7 +171,7 @@ class basic_json
friend
class
::
nlohmann
::
detail
::
iter_impl
;
template
<
typename
BasicJsonType
,
typename
CharType
>
friend
class
::
nlohmann
::
detail
::
binary_writer
;
template
<
typename
BasicJsonType
>
template
<
typename
BasicJsonType
,
typename
SAX
>
friend
class
::
nlohmann
::
detail
::
binary_reader
;
template
<
typename
BasicJsonType
>
friend
class
::
nlohmann
::
detail
::
json_sax_dom_parser
;
...
...
@@ -1113,8 +1113,6 @@ class basic_json
*/
using
parser_callback_t
=
typename
parser
::
parser_callback_t
;
using
json_sax_t
=
typename
parser
::
json_sax_t
;
//////////////////
// constructors //
//////////////////
...
...
@@ -6014,7 +6012,8 @@ class basic_json
return
parser
(
i
).
accept
(
true
);
}
static
bool
sax_parse
(
detail
::
input_adapter
&&
i
,
json_sax_t
*
sax
,
template
<
typename
SAX
>
static
bool
sax_parse
(
detail
::
input_adapter
&&
i
,
SAX
*
sax
,
input_format_t
format
=
input_format_t
::
json
,
const
bool
strict
=
true
)
{
...
...
@@ -6024,7 +6023,7 @@ class basic_json
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
);
return
detail
::
binary_reader
<
basic_json
,
SAX
>
(
std
::
move
(
i
)).
sax_parse
(
format
,
sax
,
strict
);
}
}
...
...
@@ -6097,11 +6096,11 @@ class basic_json
return
parser
(
detail
::
input_adapter
(
first
,
last
)).
accept
(
true
);
}
template
<
class
IteratorType
,
typename
std
::
enable_if
<
template
<
class
IteratorType
,
class
SAX
,
typename
std
::
enable_if
<
std
::
is_base_of
<
std
::
random_access_iterator_tag
,
typename
std
::
iterator_traits
<
IteratorType
>::
iterator_category
>::
value
,
int
>::
type
=
0
>
static
bool
sax_parse
(
IteratorType
first
,
IteratorType
last
,
json_sax_t
*
sax
)
static
bool
sax_parse
(
IteratorType
first
,
IteratorType
last
,
SAX
*
sax
)
{
return
parser
(
detail
::
input_adapter
(
first
,
last
)).
sax_parse
(
sax
);
}
...
...
single_include/nlohmann/json.hpp
View file @
442886d0
This diff is collapsed.
Click to expand it.
test/src/unit-cbor.cpp
View file @
442886d0
...
...
@@ -34,68 +34,68 @@ using nlohmann::json;
#include <fstream>
class
SaxCountdown
:
public
nlohmann
::
json
::
json_sax_t
class
SaxCountdown
{
public
:
explicit
SaxCountdown
(
const
int
count
)
:
events_left
(
count
)
{}
bool
null
()
override
bool
null
()
{
return
events_left
--
>
0
;
}
bool
boolean
(
bool
)
override
bool
boolean
(
bool
)
{
return
events_left
--
>
0
;
}
bool
number_integer
(
json
::
number_integer_t
)
override
bool
number_integer
(
json
::
number_integer_t
)
{
return
events_left
--
>
0
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
)
override
bool
number_unsigned
(
json
::
number_unsigned_t
)
{
return
events_left
--
>
0
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
override
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&
)
override
bool
string
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
start_object
(
std
::
size_t
)
override
bool
start_object
(
std
::
size_t
)
{
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&
)
override
bool
key
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
end_object
()
override
bool
end_object
()
{
return
events_left
--
>
0
;
}
bool
start_array
(
std
::
size_t
)
override
bool
start_array
(
std
::
size_t
)
{
return
events_left
--
>
0
;
}
bool
end_array
()
override
bool
end_array
()
{
return
events_left
--
>
0
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
{
return
false
;
}
...
...
test/src/unit-class_parser.cpp
View file @
442886d0
...
...
@@ -35,48 +35,48 @@ using nlohmann::json;
#include <valarray>
class
SaxEventLogger
:
public
nlohmann
::
json
::
json_sax_t
class
SaxEventLogger
{
public
:
bool
null
()
override
bool
null
()
{
events
.
push_back
(
"null()"
);
return
true
;
}
bool
boolean
(
bool
val
)
override
bool
boolean
(
bool
val
)
{
events
.
push_back
(
val
?
"boolean(true)"
:
"boolean(false)"
);
return
true
;
}
bool
number_integer
(
json
::
number_integer_t
val
)
override
bool
number_integer
(
json
::
number_integer_t
val
)
{
events
.
push_back
(
"number_integer("
+
std
::
to_string
(
val
)
+
")"
);
return
true
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
val
)
override
bool
number_unsigned
(
json
::
number_unsigned_t
val
)
{
events
.
push_back
(
"number_unsigned("
+
std
::
to_string
(
val
)
+
")"
);
return
true
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
s
)
override
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
s
)
{
events
.
push_back
(
"number_float("
+
s
+
")"
);
return
true
;
}
bool
string
(
std
::
string
&
val
)
override
bool
string
(
std
::
string
&
val
)
{
events
.
push_back
(
"string("
+
val
+
")"
);
return
true
;
}
bool
start_object
(
std
::
size_t
elements
)
override
bool
start_object
(
std
::
size_t
elements
=
-
1
)
{
if
(
elements
==
no_limit
)
if
(
elements
==
std
::
size_t
(
-
1
)
)
{
events
.
push_back
(
"start_object()"
);
}
...
...
@@ -87,21 +87,21 @@ class SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
key
(
std
::
string
&
val
)
override
bool
key
(
std
::
string
&
val
)
{
events
.
push_back
(
"key("
+
val
+
")"
);
return
true
;
}
bool
end_object
()
override
bool
end_object
()
{
events
.
push_back
(
"end_object()"
);
return
true
;
}
bool
start_array
(
std
::
size_t
elements
)
override
bool
start_array
(
std
::
size_t
elements
=
-
1
)
{
if
(
elements
==
no_limit
)
if
(
elements
==
std
::
size_t
(
-
1
)
)
{
events
.
push_back
(
"start_array()"
);
}
...
...
@@ -112,13 +112,13 @@ class SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
end_array
()
override
bool
end_array
()
{
events
.
push_back
(
"end_array()"
);
return
true
;
}
bool
parse_error
(
std
::
size_t
position
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
bool
parse_error
(
std
::
size_t
position
,
const
std
::
string
&
,
const
json
::
exception
&
)
{
errored
=
true
;
events
.
push_back
(
"parse_error("
+
std
::
to_string
(
position
)
+
")"
);
...
...
@@ -129,68 +129,68 @@ class SaxEventLogger : public nlohmann::json::json_sax_t
bool
errored
=
false
;
};
class
SaxCountdown
:
public
nlohmann
::
json
::
json_sax_t
class
SaxCountdown
{
public
:
explicit
SaxCountdown
(
const
int
count
)
:
events_left
(
count
)
{}
bool
null
()
override
bool
null
()
{
return
events_left
--
>
0
;
}
bool
boolean
(
bool
)
override
bool
boolean
(
bool
)
{
return
events_left
--
>
0
;
}
bool
number_integer
(
json
::
number_integer_t
)
override
bool
number_integer
(
json
::
number_integer_t
)
{
return
events_left
--
>
0
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
)
override
bool
number_unsigned
(
json
::
number_unsigned_t
)
{
return
events_left
--
>
0
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
override
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&
)
override
bool
string
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
start_object
(
std
::
size_t
)
override
bool
start_object
(
std
::
size_t
=
-
1
)
{
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&
)
override
bool
key
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
end_object
()
override
bool
end_object
()
{
return
events_left
--
>
0
;
}
bool
start_array
(
std
::
size_t
)
override
bool
start_array
(
std
::
size_t
=
-
1
)
{
return
events_left
--
>
0
;
}
bool
end_array
()
override
bool
end_array
()
{
return
events_left
--
>
0
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
{
return
false
;
}
...
...
test/src/unit-deserialization.cpp
View file @
442886d0
...
...
@@ -35,45 +35,45 @@ using nlohmann::json;
#include <iostream>
#include <valarray>
struct
SaxEventLogger
:
public
nlohmann
::
json
::
json_sax_t
struct
SaxEventLogger
{
bool
null
()
override
bool
null
()
{
events
.
push_back
(
"null()"
);
return
true
;
}
bool
boolean
(
bool
val
)
override
bool
boolean
(
bool
val
)
{
events
.
push_back
(
val
?
"boolean(true)"
:
"boolean(false)"
);
return
true
;
}
bool
number_integer
(
json
::
number_integer_t
val
)
override
bool
number_integer
(
json
::
number_integer_t
val
)
{
events
.
push_back
(
"number_integer("
+
std
::
to_string
(
val
)
+
")"
);
return
true
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
val
)
override
bool
number_unsigned
(
json
::
number_unsigned_t
val
)
{
events
.
push_back
(
"number_unsigned("
+
std
::
to_string
(
val
)
+
")"
);
return
true
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
s
)
override
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
s
)
{
events
.
push_back
(
"number_float("
+
s
+
")"
);
return
true
;
}
bool
string
(
std
::
string
&
val
)
override
bool
string
(
std
::
string
&
val
)
{
events
.
push_back
(
"string("
+
val
+
")"
);
return
true
;
}
bool
start_object
(
std
::
size_t
elements
)
override
bool
start_object
(
std
::
size_t
elements
)
{
if
(
elements
==
std
::
size_t
(
-
1
))
{
...
...
@@ -86,19 +86,19 @@ struct SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
key
(
std
::
string
&
val
)
override
bool
key
(
std
::
string
&
val
)
{
events
.
push_back
(
"key("
+
val
+
")"
);
return
true
;
}
bool
end_object
()
override
bool
end_object
()
{
events
.
push_back
(
"end_object()"
);
return
true
;
}
bool
start_array
(
std
::
size_t
elements
)
override
bool
start_array
(
std
::
size_t
elements
)
{
if
(
elements
==
std
::
size_t
(
-
1
))
{
...
...
@@ -111,13 +111,13 @@ struct SaxEventLogger : public nlohmann::json::json_sax_t
return
true
;
}
bool
end_array
()
override
bool
end_array
()
{
events
.
push_back
(
"end_array()"
);
return
true
;
}
bool
parse_error
(
std
::
size_t
position
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
bool
parse_error
(
std
::
size_t
position
,
const
std
::
string
&
,
const
json
::
exception
&
)
{
events
.
push_back
(
"parse_error("
+
std
::
to_string
(
position
)
+
")"
);
return
false
;
...
...
@@ -128,9 +128,9 @@ struct SaxEventLogger : public nlohmann::json::json_sax_t
struct
SaxEventLoggerExitAfterStartObject
:
public
SaxEventLogger
{
bool
start_object
(
std
::
size_t
elements
)
override
bool
start_object
(
std
::
size_t
elements
)
{
if
(
elements
==
no_limit
)
if
(
elements
==
-
1
)
{
events
.
push_back
(
"start_object()"
);
}
...
...
@@ -144,7 +144,7 @@ struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger
struct
SaxEventLoggerExitAfterKey
:
public
SaxEventLogger
{
bool
key
(
std
::
string
&
val
)
override
bool
key
(
std
::
string
&
val
)
{
events
.
push_back
(
"key("
+
val
+
")"
);
return
false
;
...
...
@@ -153,9 +153,9 @@ struct SaxEventLoggerExitAfterKey : public SaxEventLogger
struct
SaxEventLoggerExitAfterStartArray
:
public
SaxEventLogger
{
bool
start_array
(
std
::
size_t
elements
)
override
bool
start_array
(
std
::
size_t
elements
)
{
if
(
elements
==
no_limit
)
if
(
elements
==
-
1
)
{
events
.
push_back
(
"start_array()"
);
}
...
...
test/src/unit-msgpack.cpp
View file @
442886d0
...
...
@@ -34,68 +34,68 @@ using nlohmann::json;
#include <fstream>
class
SaxCountdown
:
public
nlohmann
::
json
::
json_sax_t
class
SaxCountdown
{
public
:
explicit
SaxCountdown
(
const
int
count
)
:
events_left
(
count
)
{}
bool
null
()
override
bool
null
()
{
return
events_left
--
>
0
;
}
bool
boolean
(
bool
)
override
bool
boolean
(
bool
)
{
return
events_left
--
>
0
;
}
bool
number_integer
(
json
::
number_integer_t
)
override
bool
number_integer
(
json
::
number_integer_t
)
{
return
events_left
--
>
0
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
)
override
bool
number_unsigned
(
json
::
number_unsigned_t
)
{
return
events_left
--
>
0
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
override
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&
)
override
bool
string
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
start_object
(
std
::
size_t
)
override
bool
start_object
(
std
::
size_t
)
{
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&
)
override
bool
key
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
end_object
()
override
bool
end_object
()
{
return
events_left
--
>
0
;
}
bool
start_array
(
std
::
size_t
)
override
bool
start_array
(
std
::
size_t
)
{
return
events_left
--
>
0
;
}
bool
end_array
()
override
bool
end_array
()
{
return
events_left
--
>
0
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
{
return
false
;
}
...
...
test/src/unit-ubjson.cpp
View file @
442886d0
...
...
@@ -34,68 +34,68 @@ using nlohmann::json;
#include <fstream>
class
SaxCountdown
:
public
nlohmann
::
json
::
json_sax_t
class
SaxCountdown
{
public
:
explicit
SaxCountdown
(
const
int
count
)
:
events_left
(
count
)
{}
bool
null
()
override
bool
null
()
{
return
events_left
--
>
0
;
}
bool
boolean
(
bool
)
override
bool
boolean
(
bool
)
{
return
events_left
--
>
0
;
}
bool
number_integer
(
json
::
number_integer_t
)
override
bool
number_integer
(
json
::
number_integer_t
)
{
return
events_left
--
>
0
;
}
bool
number_unsigned
(
json
::
number_unsigned_t
)
override
bool
number_unsigned
(
json
::
number_unsigned_t
)
{
return
events_left
--
>
0
;
}
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
override
bool
number_float
(
json
::
number_float_t
,
const
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
string
(
std
::
string
&
)
override
bool
string
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
start_object
(
std
::
size_t
)
override
bool
start_object
(
std
::
size_t
=
-
1
)
{
return
events_left
--
>
0
;
}
bool
key
(
std
::
string
&
)
override
bool
key
(
std
::
string
&
)
{
return
events_left
--
>
0
;
}
bool
end_object
()
override
bool
end_object
()
{
return
events_left
--
>
0
;
}
bool
start_array
(
std
::
size_t
)
override
bool
start_array
(
std
::
size_t
=
-
1
)
{
return
events_left
--
>
0
;
}
bool
end_array
()
override
bool
end_array
()
{
return
events_left
--
>
0
;
}
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
override
bool
parse_error
(
std
::
size_t
,
const
std
::
string
&
,
const
json
::
exception
&
)
{
return
false
;
}
...
...
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