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
120d1d77
Commit
120d1d77
authored
6 years ago
by
Julian Becker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BSON: test case for a more complex document
parent
5ce7d6bd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
2 deletions
+34
-2
include/nlohmann/detail/output/binary_writer.hpp
include/nlohmann/detail/output/binary_writer.hpp
+1
-1
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+1
-1
test/src/unit-bson.cpp
test/src/unit-bson.cpp
+32
-0
No files found.
include/nlohmann/detail/output/binary_writer.hpp
View file @
120d1d77
...
@@ -792,7 +792,7 @@ class binary_writer
...
@@ -792,7 +792,7 @@ class binary_writer
switch
(
j
.
type
())
switch
(
j
.
type
())
{
{
default:
default:
JSON_THROW
(
type_error
::
create
(
317
,
"JSON value
cannot be serialized to requested format"
));
JSON_THROW
(
type_error
::
create
(
317
,
"JSON value
of type be serialized to requested format: "
+
std
::
to_string
((
int
)
j
.
type
())
));
break
;
break
;
case
value_t
:
:
object
:
case
value_t
:
:
object
:
return
write_bson_object_internal
(
name
,
j
);
return
write_bson_object_internal
(
name
,
j
);
...
...
This diff is collapsed.
Click to expand it.
single_include/nlohmann/json.hpp
View file @
120d1d77
...
@@ -8633,7 +8633,7 @@ class binary_writer
...
@@ -8633,7 +8633,7 @@ class binary_writer
switch (j.type())
switch (j.type())
{
{
default:
default:
JSON_THROW(type_error::create(317, "JSON value
cannot be serialized to requested format"
));
JSON_THROW(type_error::create(317, "JSON value
of type be serialized to requested format: " + std::to_string((int)j.type())
));
break;
break;
case value_t::object:
case value_t::object:
return write_bson_object_internal(name, j);
return write_bson_object_internal(name, j);
...
...
This diff is collapsed.
Click to expand it.
test/src/unit-bson.cpp
View file @
120d1d77
...
@@ -380,5 +380,37 @@ TEST_CASE("BSON")
...
@@ -380,5 +380,37 @@ TEST_CASE("BSON")
CHECK
(
json
::
from_bson
(
result
)
==
j
);
CHECK
(
json
::
from_bson
(
result
)
==
j
);
CHECK
(
json
::
from_bson
(
result
,
true
,
false
)
==
j
);
CHECK
(
json
::
from_bson
(
result
,
true
,
false
)
==
j
);
}
}
SECTION
(
"Some more complex document"
)
{
// directly encoding uint64 is not supported in bson (only for timestamp values)
json
j
=
{
{
"double"
,
42.5
},
{
"entry"
,
4.2
},
{
"number"
,
12345
},
{
"object"
,
{{
"string"
,
"value"
}}}
};
std
::
vector
<
uint8_t
>
expected
=
{
/*size */
0x4f
,
0x00
,
0x00
,
0x00
,
/*entry*/
0x01
,
'd'
,
'o'
,
'u'
,
'b'
,
'l'
,
'e'
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x40
,
0x45
,
0x40
,
/*entry*/
0x01
,
'e'
,
'n'
,
't'
,
'r'
,
'y'
,
0x00
,
0xcd
,
0xcc
,
0xcc
,
0xcc
,
0xcc
,
0xcc
,
0x10
,
0x40
,
/*entry*/
0x10
,
'n'
,
'u'
,
'm'
,
'b'
,
'e'
,
'r'
,
0x00
,
0x39
,
0x30
,
0x00
,
0x00
,
/*entry*/
0x03
,
'o'
,
'b'
,
'j'
,
'e'
,
'c'
,
't'
,
0x00
,
/*entry: obj-size */
0x17
,
0x00
,
0x00
,
0x00
,
/*entry: obj-entry*/
0x02
,
's'
,
't'
,
'r'
,
'i'
,
'n'
,
'g'
,
0x00
,
0x06
,
0x00
,
0x00
,
0x00
,
'v'
,
'a'
,
'l'
,
'u'
,
'e'
,
0
,
/*entry: obj-term.*/
0x00
,
/*obj-term*/
0x00
};
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
);
}
}
}
}
}
This diff is collapsed.
Click to expand it.
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