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
c0d8921a
Commit
c0d8921a
authored
Sep 15, 2018
by
Julian Becker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BSON: support objects with int64 members
parent
7ee361f7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
12 deletions
+83
-12
include/nlohmann/detail/input/binary_reader.hpp
include/nlohmann/detail/input/binary_reader.hpp
+10
-0
include/nlohmann/detail/output/binary_writer.hpp
include/nlohmann/detail/output/binary_writer.hpp
+20
-6
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+30
-6
test/src/unit-bson.cpp
test/src/unit-bson.cpp
+23
-0
No files found.
include/nlohmann/detail/input/binary_reader.hpp
View file @
c0d8921a
...
...
@@ -213,6 +213,16 @@ class binary_reader
sax
->
number_integer
(
static_cast
<
std
::
int32_t
>
(
value
));
}
break
;
case
0x12
:
// int64
{
string_t
key
;
get_bson_cstr
(
key
);
sax
->
key
(
key
);
std
::
int64_t
value
;
get_number_little_endian
(
value
);
sax
->
number_integer
(
static_cast
<
std
::
int64_t
>
(
value
));
}
break
;
case
0x0A
:
// null
{
string_t
key
;
...
...
include/nlohmann/detail/output/binary_writer.hpp
View file @
c0d8921a
...
...
@@ -722,6 +722,8 @@ class binary_writer
}
std
::
size_t
write_bson_integer
(
const
typename
BasicJsonType
::
string_t
&
name
,
const
BasicJsonType
&
j
)
{
if
(
j
.
m_value
.
number_integer
<=
static_cast
<
uint64_t
>
((
std
::
numeric_limits
<
int32_t
>::
max
)()))
{
oa
->
write_character
(
static_cast
<
CharType
>
(
0x10
));
// int32
oa
->
write_characters
(
...
...
@@ -732,6 +734,18 @@ class binary_writer
return
/*id*/
1ul
+
name
.
size
()
+
1ul
+
sizeof
(
std
::
int32_t
);
}
else
{
oa
->
write_character
(
static_cast
<
CharType
>
(
0x12
));
// int64
oa
->
write_characters
(
reinterpret_cast
<
const
CharType
*>
(
name
.
c_str
()),
name
.
size
()
+
1u
);
write_number_little_endian
(
static_cast
<
std
::
int64_t
>
(
j
.
m_value
.
number_integer
));
return
/*id*/
1ul
+
name
.
size
()
+
1ul
+
sizeof
(
std
::
int64_t
);
}
}
std
::
size_t
write_bson_object_entry
(
const
typename
BasicJsonType
::
string_t
&
name
,
const
BasicJsonType
&
j
)
{
...
...
single_include/nlohmann/json.hpp
View file @
c0d8921a
...
...
@@ -6197,6 +6197,16 @@ class binary_reader
sax
->
number_integer
(
static_cast
<
std
::
int32_t
>
(
value
));
}
break
;
case
0x12
:
// int64
{
string_t
key
;
get_bson_cstr
(
key
);
sax
->
key
(
key
);
std
::
int64_t
value
;
get_number_little_endian
(
value
);
sax
->
number_integer
(
static_cast
<
std
::
int64_t
>
(
value
));
}
break
;
case
0x0A
:
// null
{
string_t
key
;
...
...
@@ -8546,6 +8556,8 @@ class binary_writer
}
std
::
size_t
write_bson_integer
(
const
typename
BasicJsonType
::
string_t
&
name
,
const
BasicJsonType
&
j
)
{
if
(
j
.
m_value
.
number_integer
<=
static_cast
<
uint64_t
>
((
std
::
numeric_limits
<
int32_t
>::
max
)()))
{
oa
->
write_character
(
static_cast
<
CharType
>
(
0x10
));
// int32
oa
->
write_characters
(
...
...
@@ -8556,6 +8568,18 @@ class binary_writer
return
/*id*/
1ul
+
name
.
size
()
+
1ul
+
sizeof
(
std
::
int32_t
);
}
else
{
oa
->
write_character
(
static_cast
<
CharType
>
(
0x12
));
// int64
oa
->
write_characters
(
reinterpret_cast
<
const
CharType
*>
(
name
.
c_str
()),
name
.
size
()
+
1u
);
write_number_little_endian
(
static_cast
<
std
::
int64_t
>
(
j
.
m_value
.
number_integer
));
return
/*id*/
1ul
+
name
.
size
()
+
1ul
+
sizeof
(
std
::
int64_t
);
}
}
std
::
size_t
write_bson_object_entry
(
const
typename
BasicJsonType
::
string_t
&
name
,
const
BasicJsonType
&
j
)
{
...
...
test/src/unit-bson.cpp
View file @
c0d8921a
...
...
@@ -255,6 +255,29 @@ TEST_CASE("BSON")
CHECK
(
json
::
from_bson
(
result
,
true
,
false
)
==
j
);
}
SECTION
(
"non-empty object with integer (64-bit) member"
)
{
json
j
=
{
{
"entry"
,
std
::
int64_t
{
0x1234567804030201
}
}
};
std
::
vector
<
uint8_t
>
expected
=
{
0x14
,
0x00
,
0x00
,
0x00
,
// size (little endian)
0x12
,
/// entry: int64
'e'
,
'n'
,
't'
,
'r'
,
'y'
,
'\x00'
,
0x01
,
0x02
,
0x03
,
0x04
,
0x78
,
0x56
,
0x34
,
0x12
,
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