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
df0f612d
Commit
df0f612d
authored
Oct 07, 2018
by
Julian Becker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BSON: allow and discard values and object entries of type `value_t::discarded`
parent
062aeaf7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
2 deletions
+33
-2
binary_writer.hpp
include/nlohmann/detail/output/binary_writer.hpp
+4
-1
json.hpp
single_include/nlohmann/json.hpp
+4
-1
unit-bson.cpp
test/src/unit-bson.cpp
+25
-0
No files found.
include/nlohmann/detail/output/binary_writer.hpp
View file @
df0f612d
...
...
@@ -9,7 +9,6 @@
#include <nlohmann/detail/input/binary_reader.hpp>
#include <nlohmann/detail/output/output_adapters.hpp>
namespace
nlohmann
{
namespace
detail
...
...
@@ -864,6 +863,8 @@ class binary_writer
assert
(
false
);
return
0ul
;
// LCOV_EXCL_STOP
case
value_t
:
:
discarded
:
return
0ul
;
case
value_t
:
:
object
:
return
header_size
+
calc_bson_object_size
(
*
j
.
m_value
.
object
);
case
value_t
:
:
array
:
...
...
@@ -898,6 +899,8 @@ class binary_writer
assert
(
false
);
return
;
// LCOV_EXCL_STOP
case
value_t
:
:
discarded
:
return
;
case
value_t
:
:
object
:
return
write_bson_object_entry
(
name
,
*
j
.
m_value
.
object
);
case
value_t
:
:
array
:
...
...
single_include/nlohmann/json.hpp
View file @
df0f612d
...
...
@@ -7853,7 +7853,6 @@ class binary_reader
// #include <nlohmann/detail/output/output_adapters.hpp>
namespace
nlohmann
{
namespace
detail
...
...
@@ -8708,6 +8707,8 @@ class binary_writer
assert
(
false
);
return
0ul
;
// LCOV_EXCL_STOP
case
value_t
:
:
discarded
:
return
0ul
;
case
value_t
:
:
object
:
return
header_size
+
calc_bson_object_size
(
*
j
.
m_value
.
object
);
case
value_t
:
:
array
:
...
...
@@ -8742,6 +8743,8 @@ class binary_writer
assert
(
false
);
return
;
// LCOV_EXCL_STOP
case
value_t
:
:
discarded
:
return
;
case
value_t
:
:
object
:
return
write_bson_object_entry
(
name
,
*
j
.
m_value
.
object
);
case
value_t
:
:
array
:
...
...
test/src/unit-bson.cpp
View file @
df0f612d
...
...
@@ -376,6 +376,31 @@ TEST_CASE("BSON")
CHECK
(
json
::
from_bson
(
result
,
true
,
false
)
==
j
);
}
SECTION
(
"discarded values are not serialized"
)
{
json
j
=
json
::
value_t
::
discarded
;
const
auto
result
=
json
::
to_bson
(
j
);
CHECK
(
result
.
empty
());
}
SECTION
(
"discarded members are not serialized"
)
{
json
j
=
{
{
"entry"
,
json
::
value_t
::
discarded
}
};
std
::
vector
<
uint8_t
>
expected
=
{
0x05
,
0x00
,
0x00
,
0x00
,
// size (little endian)
// no entries
0x00
// end marker
};
const
auto
result
=
json
::
to_bson
(
j
);
CHECK
(
result
==
expected
);
}
SECTION
(
"non-empty object with object member"
)
{
...
...
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