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
b64002bb
Unverified
Commit
b64002bb
authored
Jun 19, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
extract common code to function
parent
cd115cbc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
48 deletions
+46
-48
include/nlohmann/detail/output/binary_writer.hpp
include/nlohmann/detail/output/binary_writer.hpp
+23
-24
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+23
-24
No files found.
include/nlohmann/detail/output/binary_writer.hpp
View file @
b64002bb
...
...
@@ -28,6 +28,7 @@ class binary_writer
{
using
string_t
=
typename
BasicJsonType
::
string_t
;
using
binary_t
=
typename
BasicJsonType
::
binary_t
;
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
public:
/*!
...
...
@@ -194,18 +195,7 @@ class binary_writer
}
else
{
if
(
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
>=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
())
and
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
<=
static_cast
<
double
>
((
std
::
numeric_limits
<
float
>::
max
)())
and
static_cast
<
double
>
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
))
==
static_cast
<
double
>
(
j
.
m_value
.
number_float
))
{
oa
->
write_character
(
get_cbor_float_prefix
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
)));
write_number
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
));
}
else
{
oa
->
write_character
(
get_cbor_float_prefix
(
j
.
m_value
.
number_float
));
write_number
(
j
.
m_value
.
number_float
);
}
write_compact_float
(
j
.
m_value
.
number_float
,
detail
::
input_format_t
::
cbor
);
}
break
;
}
...
...
@@ -504,18 +494,7 @@ class binary_writer
case
value_t
:
:
number_float
:
{
if
(
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
>=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
())
and
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
<=
static_cast
<
double
>
((
std
::
numeric_limits
<
float
>::
max
)())
and
static_cast
<
double
>
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
))
==
static_cast
<
double
>
(
j
.
m_value
.
number_float
))
{
oa
->
write_character
(
get_msgpack_float_prefix
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
)));
write_number
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
));
}
else
{
oa
->
write_character
(
get_msgpack_float_prefix
(
j
.
m_value
.
number_float
));
write_number
(
j
.
m_value
.
number_float
);
}
write_compact_float
(
j
.
m_value
.
number_float
,
detail
::
input_format_t
::
msgpack
);
break
;
}
...
...
@@ -1528,6 +1507,26 @@ class binary_writer
oa
->
write_characters
(
vec
.
data
(),
sizeof
(
NumberType
));
}
void
write_compact_float
(
const
number_float_t
n
,
detail
::
input_format_t
format
)
{
if
(
static_cast
<
double
>
(
n
)
>=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
())
and
static_cast
<
double
>
(
n
)
<=
static_cast
<
double
>
((
std
::
numeric_limits
<
float
>::
max
)())
and
static_cast
<
double
>
(
static_cast
<
float
>
(
n
))
==
static_cast
<
double
>
(
n
))
{
oa
->
write_character
(
format
==
detail
::
input_format_t
::
cbor
?
get_cbor_float_prefix
(
static_cast
<
float
>
(
n
))
:
get_msgpack_float_prefix
(
static_cast
<
float
>
(
n
)));
write_number
(
static_cast
<
float
>
(
n
));
}
else
{
oa
->
write_character
(
format
==
detail
::
input_format_t
::
cbor
?
get_cbor_float_prefix
(
n
)
:
get_msgpack_float_prefix
(
n
));
write_number
(
n
);
}
}
public:
// The following to_char_type functions are implement the conversion
// between uint8_t and CharType. In case CharType is not unsigned,
...
...
single_include/nlohmann/json.hpp
View file @
b64002bb
...
...
@@ -12238,6 +12238,7 @@ class binary_writer
{
using
string_t
=
typename
BasicJsonType
::
string_t
;
using
binary_t
=
typename
BasicJsonType
::
binary_t
;
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
public:
/*!
...
...
@@ -12404,18 +12405,7 @@ class binary_writer
}
else
{
if
(
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
>=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
())
and
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
<=
static_cast
<
double
>
((
std
::
numeric_limits
<
float
>::
max
)())
and
static_cast
<
double
>
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
))
==
static_cast
<
double
>
(
j
.
m_value
.
number_float
))
{
oa
->
write_character
(
get_cbor_float_prefix
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
)));
write_number
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
));
}
else
{
oa
->
write_character
(
get_cbor_float_prefix
(
j
.
m_value
.
number_float
));
write_number
(
j
.
m_value
.
number_float
);
}
write_compact_float
(
j
.
m_value
.
number_float
,
detail
::
input_format_t
::
cbor
);
}
break
;
}
...
...
@@ -12714,18 +12704,7 @@ class binary_writer
case
value_t
:
:
number_float
:
{
if
(
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
>=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
())
and
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
<=
static_cast
<
double
>
((
std
::
numeric_limits
<
float
>::
max
)())
and
static_cast
<
double
>
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
))
==
static_cast
<
double
>
(
j
.
m_value
.
number_float
))
{
oa
->
write_character
(
get_msgpack_float_prefix
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
)));
write_number
(
static_cast
<
float
>
(
j
.
m_value
.
number_float
));
}
else
{
oa
->
write_character
(
get_msgpack_float_prefix
(
j
.
m_value
.
number_float
));
write_number
(
j
.
m_value
.
number_float
);
}
write_compact_float
(
j
.
m_value
.
number_float
,
detail
::
input_format_t
::
msgpack
);
break
;
}
...
...
@@ -13738,6 +13717,26 @@ class binary_writer
oa
->
write_characters
(
vec
.
data
(),
sizeof
(
NumberType
));
}
void
write_compact_float
(
const
number_float_t
n
,
detail
::
input_format_t
format
)
{
if
(
static_cast
<
double
>
(
n
)
>=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
())
and
static_cast
<
double
>
(
n
)
<=
static_cast
<
double
>
((
std
::
numeric_limits
<
float
>::
max
)())
and
static_cast
<
double
>
(
static_cast
<
float
>
(
n
))
==
static_cast
<
double
>
(
n
))
{
oa
->
write_character
(
format
==
detail
::
input_format_t
::
cbor
?
get_cbor_float_prefix
(
static_cast
<
float
>
(
n
))
:
get_msgpack_float_prefix
(
static_cast
<
float
>
(
n
)));
write_number
(
static_cast
<
float
>
(
n
));
}
else
{
oa
->
write_character
(
format
==
detail
::
input_format_t
::
cbor
?
get_cbor_float_prefix
(
n
)
:
get_msgpack_float_prefix
(
n
));
write_number
(
n
);
}
}
public:
// The following to_char_type functions are implement the conversion
// between uint8_t and CharType. In case CharType is not unsigned,
...
...
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