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
c5ef0231
Commit
c5ef0231
authored
Sep 15, 2018
by
Julian Becker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BSON: support objects with null members
parent
6c447de0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
0 deletions
+63
-0
include/nlohmann/detail/input/binary_reader.hpp
include/nlohmann/detail/input/binary_reader.hpp
+8
-0
include/nlohmann/detail/output/binary_writer.hpp
include/nlohmann/detail/output/binary_writer.hpp
+12
-0
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+20
-0
test/src/unit-bson.cpp
test/src/unit-bson.cpp
+23
-0
No files found.
include/nlohmann/detail/input/binary_reader.hpp
View file @
c5ef0231
...
...
@@ -203,6 +203,14 @@ class binary_reader
sax
->
boolean
(
static_cast
<
bool
>
(
get
()));
}
break
;
case
0x0A
:
// null
{
string_t
key
;
get_bson_cstr
(
key
);
sax
->
key
(
key
);
sax
->
null
();
}
break
;
}
}
...
...
include/nlohmann/detail/output/binary_writer.hpp
View file @
c5ef0231
...
...
@@ -711,6 +711,16 @@ class binary_writer
return
/*id*/
1ul
+
name
.
size
()
+
1ul
+
sizeof
(
std
::
int32_t
)
+
j
.
m_value
.
string
->
size
()
+
1ul
;
}
std
::
size_t
write_bson_null
(
const
typename
BasicJsonType
::
string_t
&
name
,
const
BasicJsonType
&
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
0x0A
));
// null
oa
->
write_characters
(
reinterpret_cast
<
const
CharType
*>
(
name
.
c_str
()),
name
.
size
()
+
1u
);
return
/*id*/
1ul
+
name
.
size
()
+
1ul
;
}
std
::
size_t
write_bson_object_entry
(
const
typename
BasicJsonType
::
string_t
&
name
,
const
BasicJsonType
&
j
)
{
switch
(
j
.
type
())
...
...
@@ -724,6 +734,8 @@ class binary_writer
return
write_bson_double
(
name
,
j
);
case
value_t
:
:
string
:
return
write_bson_string
(
name
,
j
);
case
value_t
:
:
null
:
return
write_bson_null
(
name
,
j
);
};
return
0ul
;
...
...
single_include/nlohmann/json.hpp
View file @
c5ef0231
...
...
@@ -6187,6 +6187,14 @@ class binary_reader
sax
->
boolean
(
static_cast
<
bool
>
(
get
()));
}
break
;
case
0x0A
:
// null
{
string_t
key
;
get_bson_cstr
(
key
);
sax
->
key
(
key
);
sax
->
null
();
}
break
;
}
}
...
...
@@ -8517,6 +8525,16 @@ class binary_writer
return
/*id*/
1ul
+
name
.
size
()
+
1ul
+
sizeof
(
std
::
int32_t
)
+
j
.
m_value
.
string
->
size
()
+
1ul
;
}
std
::
size_t
write_bson_null
(
const
typename
BasicJsonType
::
string_t
&
name
,
const
BasicJsonType
&
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
0x0A
));
// null
oa
->
write_characters
(
reinterpret_cast
<
const
CharType
*>
(
name
.
c_str
()),
name
.
size
()
+
1u
);
return
/*id*/
1ul
+
name
.
size
()
+
1ul
;
}
std
::
size_t
write_bson_object_entry
(
const
typename
BasicJsonType
::
string_t
&
name
,
const
BasicJsonType
&
j
)
{
switch
(
j
.
type
())
...
...
@@ -8530,6 +8548,8 @@ class binary_writer
return
write_bson_double
(
name
,
j
);
case
value_t
:
:
string
:
return
write_bson_string
(
name
,
j
);
case
value_t
:
:
null
:
return
write_bson_null
(
name
,
j
);
};
return
0ul
;
...
...
test/src/unit-bson.cpp
View file @
c5ef0231
...
...
@@ -208,6 +208,29 @@ TEST_CASE("BSON")
CHECK
(
json
::
from_bson
(
result
,
true
,
false
)
==
j
);
}
SECTION
(
"non-empty object with null member"
)
{
json
j
=
{
{
"entry"
,
nullptr
}
};
std
::
vector
<
uint8_t
>
expected
=
{
0x0C
,
0x00
,
0x00
,
0x00
,
// size (little endian)
0x0A
,
/// entry: null
'e'
,
'n'
,
't'
,
'r'
,
'y'
,
'\x00'
,
0x00
// end marker
};
const
auto
result
=
json
::
to_bson
(
j
);
CHECK
(
result
==
expected
);
// roundtrip
CHECK
(
json
::
from_bson
(
result
)
==
j
);
CHECK
(
json
::
from_bson
(
result
,
true
,
false
)
==
j
);
}
}
}
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