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
b7db1d68
Unverified
Commit
b7db1d68
authored
Aug 06, 2021
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
fix CBOR and BSON
parent
046df035
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
12 deletions
+48
-12
include/nlohmann/detail/output/binary_writer.hpp
include/nlohmann/detail/output/binary_writer.hpp
+21
-3
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+3
-3
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+24
-6
No files found.
include/nlohmann/detail/output/binary_writer.hpp
View file @
b7db1d68
...
...
@@ -282,8 +282,26 @@ class binary_writer
{
if
(
j
.
m_value
.
binary
->
has_subtype
())
{
write_number
(
static_cast
<
std
::
uint8_t
>
(
0xd8
));
write_number
(
j
.
m_value
.
binary
->
subtype
());
if
(
j
.
m_value
.
binary
->
subtype
()
<=
(
std
::
numeric_limits
<
std
::
uint8_t
>::
max
)())
{
write_number
(
static_cast
<
std
::
uint8_t
>
(
0xd8
));
write_number
(
static_cast
<
std
::
uint8_t
>
(
j
.
m_value
.
binary
->
subtype
()));
}
else
if
(
j
.
m_value
.
binary
->
subtype
()
<=
(
std
::
numeric_limits
<
std
::
uint16_t
>::
max
)())
{
write_number
(
static_cast
<
std
::
uint8_t
>
(
0xd9
));
write_number
(
static_cast
<
std
::
uint16_t
>
(
j
.
m_value
.
binary
->
subtype
()));
}
else
if
(
j
.
m_value
.
binary
->
subtype
()
<=
(
std
::
numeric_limits
<
std
::
uint32_t
>::
max
)())
{
write_number
(
static_cast
<
std
::
uint8_t
>
(
0xda
));
write_number
(
static_cast
<
std
::
uint32_t
>
(
j
.
m_value
.
binary
->
subtype
()));
}
else
if
(
j
.
m_value
.
binary
->
subtype
()
<=
(
std
::
numeric_limits
<
std
::
uint64_t
>::
max
)())
{
write_number
(
static_cast
<
std
::
uint8_t
>
(
0xdb
));
write_number
(
static_cast
<
std
::
uint64_t
>
(
j
.
m_value
.
binary
->
subtype
()));
}
}
// step 1: write control byte and the binary array size
...
...
@@ -1096,7 +1114,7 @@ class binary_writer
write_bson_entry_header
(
name
,
0x05
);
write_number
<
std
::
int32_t
,
true
>
(
static_cast
<
std
::
int32_t
>
(
value
.
size
()));
write_number
(
value
.
has_subtype
()
?
value
.
subtype
(
)
:
std
::
uint8_t
(
0x00
));
write_number
(
value
.
has_subtype
()
?
static_cast
<
std
::
uint8_t
>
(
value
.
subtype
()
)
:
std
::
uint8_t
(
0x00
));
oa
->
write_characters
(
reinterpret_cast
<
const
CharType
*>
(
value
.
data
()),
value
.
size
());
}
...
...
include/nlohmann/json.hpp
View file @
b7db1d68
...
...
@@ -1817,7 +1817,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 3.8.0
*/
JSON_HEDLEY_WARN_UNUSED_RESULT
static
basic_json
binary
(
const
typename
binary_t
::
container_type
&
init
,
std
::
uint8_t
subtype
)
static
basic_json
binary
(
const
typename
binary_t
::
container_type
&
init
,
typename
binary_t
::
subtype_type
subtype
)
{
auto
res
=
basic_json
();
res
.
m_type
=
value_t
::
binary
;
...
...
@@ -1835,9 +1835,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return
res
;
}
/// @copydoc binary(const typename binary_t::container_type&,
std::uint8_t
)
/// @copydoc binary(const typename binary_t::container_type&,
typename binary_t::subtype_type
)
JSON_HEDLEY_WARN_UNUSED_RESULT
static
basic_json
binary
(
typename
binary_t
::
container_type
&&
init
,
std
::
uint8_t
subtype
)
static
basic_json
binary
(
typename
binary_t
::
container_type
&&
init
,
typename
binary_t
::
subtype_type
subtype
)
{
auto
res
=
basic_json
();
res
.
m_type
=
value_t
::
binary
;
...
...
single_include/nlohmann/json.hpp
View file @
b7db1d68
...
...
@@ -13585,8 +13585,26 @@ class binary_writer
{
if
(
j
.
m_value
.
binary
->
has_subtype
())
{
write_number
(
static_cast
<
std
::
uint8_t
>
(
0xd8
));
write_number
(
j
.
m_value
.
binary
->
subtype
());
if
(
j
.
m_value
.
binary
->
subtype
()
<=
(
std
::
numeric_limits
<
std
::
uint8_t
>::
max
)())
{
write_number
(
static_cast
<
std
::
uint8_t
>
(
0xd8
));
write_number
(
static_cast
<
std
::
uint8_t
>
(
j
.
m_value
.
binary
->
subtype
()));
}
else
if
(
j
.
m_value
.
binary
->
subtype
()
<=
(
std
::
numeric_limits
<
std
::
uint16_t
>::
max
)())
{
write_number
(
static_cast
<
std
::
uint8_t
>
(
0xd9
));
write_number
(
static_cast
<
std
::
uint16_t
>
(
j
.
m_value
.
binary
->
subtype
()));
}
else
if
(
j
.
m_value
.
binary
->
subtype
()
<=
(
std
::
numeric_limits
<
std
::
uint32_t
>::
max
)())
{
write_number
(
static_cast
<
std
::
uint8_t
>
(
0xda
));
write_number
(
static_cast
<
std
::
uint32_t
>
(
j
.
m_value
.
binary
->
subtype
()));
}
else
if
(
j
.
m_value
.
binary
->
subtype
()
<=
(
std
::
numeric_limits
<
std
::
uint64_t
>::
max
)())
{
write_number
(
static_cast
<
std
::
uint8_t
>
(
0xdb
));
write_number
(
static_cast
<
std
::
uint64_t
>
(
j
.
m_value
.
binary
->
subtype
()));
}
}
// step 1: write control byte and the binary array size
...
...
@@ -14399,7 +14417,7 @@ class binary_writer
write_bson_entry_header
(
name
,
0x05
);
write_number
<
std
::
int32_t
,
true
>
(
static_cast
<
std
::
int32_t
>
(
value
.
size
()));
write_number
(
value
.
has_subtype
()
?
value
.
subtype
(
)
:
std
::
uint8_t
(
0x00
));
write_number
(
value
.
has_subtype
()
?
static_cast
<
std
::
uint8_t
>
(
value
.
subtype
()
)
:
std
::
uint8_t
(
0x00
));
oa
->
write_characters
(
reinterpret_cast
<
const
CharType
*>
(
value
.
data
()),
value
.
size
());
}
...
...
@@ -18911,7 +18929,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 3.8.0
*/
JSON_HEDLEY_WARN_UNUSED_RESULT
static
basic_json
binary
(
const
typename
binary_t
::
container_type
&
init
,
std
::
uint8_t
subtype
)
static
basic_json
binary
(
const
typename
binary_t
::
container_type
&
init
,
typename
binary_t
::
subtype_type
subtype
)
{
auto
res
=
basic_json
();
res
.
m_type
=
value_t
::
binary
;
...
...
@@ -18929,9 +18947,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return
res
;
}
/// @copydoc binary(const typename binary_t::container_type&,
std::uint8_t
)
/// @copydoc binary(const typename binary_t::container_type&,
typename binary_t::subtype_type
)
JSON_HEDLEY_WARN_UNUSED_RESULT
static
basic_json
binary
(
typename
binary_t
::
container_type
&&
init
,
std
::
uint8_t
subtype
)
static
basic_json
binary
(
typename
binary_t
::
container_type
&&
init
,
typename
binary_t
::
subtype_type
subtype
)
{
auto
res
=
basic_json
();
res
.
m_type
=
value_t
::
binary
;
...
...
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