Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
48 deletions
+46
-48
binary_writer.hpp
include/nlohmann/detail/output/binary_writer.hpp
+23
-24
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
...
@@ -28,6 +28,7 @@ class binary_writer
{
{
using
string_t
=
typename
BasicJsonType
::
string_t
;
using
string_t
=
typename
BasicJsonType
::
string_t
;
using
binary_t
=
typename
BasicJsonType
::
binary_t
;
using
binary_t
=
typename
BasicJsonType
::
binary_t
;
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
public
:
public
:
/*!
/*!
...
@@ -194,18 +195,7 @@ class binary_writer
...
@@ -194,18 +195,7 @@ class binary_writer
}
}
else
else
{
{
if
(
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
>=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
())
and
write_compact_float
(
j
.
m_value
.
number_float
,
detail
::
input_format_t
::
cbor
);
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
);
}
}
}
break
;
break
;
}
}
...
@@ -504,18 +494,7 @@ class binary_writer
...
@@ -504,18 +494,7 @@ class binary_writer
case
value_t
:
:
number_float
:
case
value_t
:
:
number_float
:
{
{
if
(
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
>=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
())
and
write_compact_float
(
j
.
m_value
.
number_float
,
detail
::
input_format_t
::
msgpack
);
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
);
}
break
;
break
;
}
}
...
@@ -1528,6 +1507,26 @@ class binary_writer
...
@@ -1528,6 +1507,26 @@ class binary_writer
oa
->
write_characters
(
vec
.
data
(),
sizeof
(
NumberType
));
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
:
public
:
// The following to_char_type functions are implement the conversion
// The following to_char_type functions are implement the conversion
// between uint8_t and CharType. In case CharType is not unsigned,
// 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
...
@@ -12238,6 +12238,7 @@ class binary_writer
{
{
using
string_t
=
typename
BasicJsonType
::
string_t
;
using
string_t
=
typename
BasicJsonType
::
string_t
;
using
binary_t
=
typename
BasicJsonType
::
binary_t
;
using
binary_t
=
typename
BasicJsonType
::
binary_t
;
using
number_float_t
=
typename
BasicJsonType
::
number_float_t
;
public
:
public
:
/*!
/*!
...
@@ -12404,18 +12405,7 @@ class binary_writer
...
@@ -12404,18 +12405,7 @@ class binary_writer
}
}
else
else
{
{
if
(
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
>=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
())
and
write_compact_float
(
j
.
m_value
.
number_float
,
detail
::
input_format_t
::
cbor
);
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
);
}
}
}
break
;
break
;
}
}
...
@@ -12714,18 +12704,7 @@ class binary_writer
...
@@ -12714,18 +12704,7 @@ class binary_writer
case
value_t
:
:
number_float
:
case
value_t
:
:
number_float
:
{
{
if
(
static_cast
<
double
>
(
j
.
m_value
.
number_float
)
>=
static_cast
<
double
>
(
std
::
numeric_limits
<
float
>::
lowest
())
and
write_compact_float
(
j
.
m_value
.
number_float
,
detail
::
input_format_t
::
msgpack
);
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
);
}
break
;
break
;
}
}
...
@@ -13738,6 +13717,26 @@ class binary_writer
...
@@ -13738,6 +13717,26 @@ class binary_writer
oa
->
write_characters
(
vec
.
data
(),
sizeof
(
NumberType
));
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
:
public
:
// The following to_char_type functions are implement the conversion
// The following to_char_type functions are implement the conversion
// between uint8_t and CharType. In case CharType is not unsigned,
// 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