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
40f279c5
Unverified
Commit
40f279c5
authored
Apr 08, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/issue1021' into develop
parents
83b14338
18a0271a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
22 deletions
+100
-22
include/nlohmann/detail/output/binary_writer.hpp
include/nlohmann/detail/output/binary_writer.hpp
+41
-11
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+41
-11
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+18
-0
No files found.
include/nlohmann/detail/output/binary_writer.hpp
View file @
40f279c5
...
...
@@ -149,9 +149,9 @@ class binary_writer
break
;
}
case
value_t
:
:
number_float
:
// Double-Precision Float
case
value_t
:
:
number_float
:
{
oa
->
write_character
(
static_cast
<
CharType
>
(
0xFB
));
oa
->
write_character
(
get_cbor_float_prefix
(
j
.
m_value
.
number_float
));
write_number
(
j
.
m_value
.
number_float
);
break
;
}
...
...
@@ -409,9 +409,9 @@ class binary_writer
break
;
}
case
value_t
:
:
number_float
:
// float 64
case
value_t
:
:
number_float
:
{
oa
->
write_character
(
static_cast
<
CharType
>
(
0xCB
));
oa
->
write_character
(
get_msgpack_float_prefix
(
j
.
m_value
.
number_float
));
write_number
(
j
.
m_value
.
number_float
);
break
;
}
...
...
@@ -588,7 +588,7 @@ class binary_writer
if
(
use_type
and
not
j
.
m_value
.
array
->
empty
())
{
assert
(
use_count
);
const
char
first_prefix
=
ubjson_prefix
(
j
.
front
());
const
CharType
first_prefix
=
ubjson_prefix
(
j
.
front
());
const
bool
same_prefix
=
std
::
all_of
(
j
.
begin
()
+
1
,
j
.
end
(),
[
this
,
first_prefix
](
const
BasicJsonType
&
v
)
{
...
...
@@ -599,7 +599,7 @@ class binary_writer
{
prefix_required
=
false
;
oa
->
write_character
(
static_cast
<
CharType
>
(
'$'
));
oa
->
write_character
(
static_cast
<
CharType
>
(
first_prefix
)
);
oa
->
write_character
(
first_prefix
);
}
}
...
...
@@ -633,7 +633,7 @@ class binary_writer
if
(
use_type
and
not
j
.
m_value
.
object
->
empty
())
{
assert
(
use_count
);
const
char
first_prefix
=
ubjson_prefix
(
j
.
front
());
const
CharType
first_prefix
=
ubjson_prefix
(
j
.
front
());
const
bool
same_prefix
=
std
::
all_of
(
j
.
begin
(),
j
.
end
(),
[
this
,
first_prefix
](
const
BasicJsonType
&
v
)
{
...
...
@@ -644,7 +644,7 @@ class binary_writer
{
prefix_required
=
false
;
oa
->
write_character
(
static_cast
<
CharType
>
(
'$'
));
oa
->
write_character
(
static_cast
<
CharType
>
(
first_prefix
)
);
oa
->
write_character
(
first_prefix
);
}
}
...
...
@@ -712,7 +712,7 @@ class binary_writer
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'D'
));
// float64
oa
->
write_character
(
get_ubjson_float_prefix
(
n
));
}
write_number
(
n
);
}
...
...
@@ -833,7 +833,7 @@ class binary_writer
write_number_with_ubjson_prefix. Therefore, we return 'L' for any
value that does not fit the previous limits.
*/
char
ubjson_prefix
(
const
BasicJsonType
&
j
)
const
noexcept
CharType
ubjson_prefix
(
const
BasicJsonType
&
j
)
const
noexcept
{
switch
(
j
.
type
())
{
...
...
@@ -892,7 +892,7 @@ class binary_writer
}
case
value_t
:
:
number_float
:
return
'D'
;
return
get_ubjson_float_prefix
(
j
.
m_value
.
number_float
)
;
case
value_t
:
:
string
:
return
'S'
;
...
...
@@ -908,6 +908,36 @@ class binary_writer
}
}
static
constexpr
CharType
get_cbor_float_prefix
(
float
)
{
return
static_cast
<
CharType
>
(
0xFA
);
// Single-Precision Float
}
static
constexpr
CharType
get_cbor_float_prefix
(
double
)
{
return
static_cast
<
CharType
>
(
0xFB
);
// Double-Precision Float
}
static
constexpr
CharType
get_msgpack_float_prefix
(
float
)
{
return
static_cast
<
CharType
>
(
0xCA
);
// float 32
}
static
constexpr
CharType
get_msgpack_float_prefix
(
double
)
{
return
static_cast
<
CharType
>
(
0xCB
);
// float 64
}
static
constexpr
CharType
get_ubjson_float_prefix
(
float
)
{
return
'd'
;
// float 32
}
static
constexpr
CharType
get_ubjson_float_prefix
(
double
)
{
return
'D'
;
// float 64
}
private:
/// whether we can assume little endianess
const
bool
is_little_endian
=
binary_reader
<
BasicJsonType
>::
little_endianess
();
...
...
single_include/nlohmann/json.hpp
View file @
40f279c5
...
...
@@ -6357,9 +6357,9 @@ class binary_writer
break
;
}
case
value_t
:
:
number_float
:
// Double-Precision Float
case
value_t
:
:
number_float
:
{
oa
->
write_character
(
static_cast
<
CharType
>
(
0xFB
));
oa
->
write_character
(
get_cbor_float_prefix
(
j
.
m_value
.
number_float
));
write_number
(
j
.
m_value
.
number_float
);
break
;
}
...
...
@@ -6617,9 +6617,9 @@ class binary_writer
break
;
}
case
value_t
:
:
number_float
:
// float 64
case
value_t
:
:
number_float
:
{
oa
->
write_character
(
static_cast
<
CharType
>
(
0xCB
));
oa
->
write_character
(
get_msgpack_float_prefix
(
j
.
m_value
.
number_float
));
write_number
(
j
.
m_value
.
number_float
);
break
;
}
...
...
@@ -6796,7 +6796,7 @@ class binary_writer
if
(
use_type
and
not
j
.
m_value
.
array
->
empty
())
{
assert
(
use_count
);
const
char
first_prefix
=
ubjson_prefix
(
j
.
front
());
const
CharType
first_prefix
=
ubjson_prefix
(
j
.
front
());
const
bool
same_prefix
=
std
::
all_of
(
j
.
begin
()
+
1
,
j
.
end
(),
[
this
,
first_prefix
](
const
BasicJsonType
&
v
)
{
...
...
@@ -6807,7 +6807,7 @@ class binary_writer
{
prefix_required
=
false
;
oa
->
write_character
(
static_cast
<
CharType
>
(
'$'
));
oa
->
write_character
(
static_cast
<
CharType
>
(
first_prefix
)
);
oa
->
write_character
(
first_prefix
);
}
}
...
...
@@ -6841,7 +6841,7 @@ class binary_writer
if
(
use_type
and
not
j
.
m_value
.
object
->
empty
())
{
assert
(
use_count
);
const
char
first_prefix
=
ubjson_prefix
(
j
.
front
());
const
CharType
first_prefix
=
ubjson_prefix
(
j
.
front
());
const
bool
same_prefix
=
std
::
all_of
(
j
.
begin
(),
j
.
end
(),
[
this
,
first_prefix
](
const
BasicJsonType
&
v
)
{
...
...
@@ -6852,7 +6852,7 @@ class binary_writer
{
prefix_required
=
false
;
oa
->
write_character
(
static_cast
<
CharType
>
(
'$'
));
oa
->
write_character
(
static_cast
<
CharType
>
(
first_prefix
)
);
oa
->
write_character
(
first_prefix
);
}
}
...
...
@@ -6920,7 +6920,7 @@ class binary_writer
{
if
(
add_prefix
)
{
oa
->
write_character
(
static_cast
<
CharType
>
(
'D'
));
// float64
oa
->
write_character
(
get_ubjson_float_prefix
(
n
));
}
write_number
(
n
);
}
...
...
@@ -7041,7 +7041,7 @@ class binary_writer
write_number_with_ubjson_prefix. Therefore, we return 'L' for any
value that does not fit the previous limits.
*/
char
ubjson_prefix
(
const
BasicJsonType
&
j
)
const
noexcept
CharType
ubjson_prefix
(
const
BasicJsonType
&
j
)
const
noexcept
{
switch
(
j
.
type
())
{
...
...
@@ -7100,7 +7100,7 @@ class binary_writer
}
case
value_t
:
:
number_float
:
return
'D'
;
return
get_ubjson_float_prefix
(
j
.
m_value
.
number_float
)
;
case
value_t
:
:
string
:
return
'S'
;
...
...
@@ -7116,6 +7116,36 @@ class binary_writer
}
}
static
constexpr
CharType
get_cbor_float_prefix
(
float
)
{
return
static_cast
<
CharType
>
(
0xFA
);
// Single-Precision Float
}
static
constexpr
CharType
get_cbor_float_prefix
(
double
)
{
return
static_cast
<
CharType
>
(
0xFB
);
// Double-Precision Float
}
static
constexpr
CharType
get_msgpack_float_prefix
(
float
)
{
return
static_cast
<
CharType
>
(
0xCA
);
// float 32
}
static
constexpr
CharType
get_msgpack_float_prefix
(
double
)
{
return
static_cast
<
CharType
>
(
0xCB
);
// float 64
}
static
constexpr
CharType
get_ubjson_float_prefix
(
float
)
{
return
'd'
;
// float 32
}
static
constexpr
CharType
get_ubjson_float_prefix
(
double
)
{
return
'D'
;
// float 64
}
private:
/// whether we can assume little endianess
const
bool
is_little_endian
=
binary_reader
<
BasicJsonType
>::
little_endianess
();
...
...
test/src/unit-regression.cpp
View file @
40f279c5
...
...
@@ -114,6 +114,13 @@ struct nocopy
};
}
/////////////////////////////////////////////////////////////////////
// for #1021
/////////////////////////////////////////////////////////////////////
using
float_json
=
nlohmann
::
basic_json
<
std
::
map
,
std
::
vector
,
std
::
string
,
bool
,
std
::
int64_t
,
std
::
uint64_t
,
float
>
;
TEST_CASE
(
"regression tests"
)
{
SECTION
(
"issue #60 - Double quotation mark is not parsed correctly"
)
...
...
@@ -1597,4 +1604,15 @@ TEST_CASE("regression tests")
auto
j
=
json
::
parse
(
geojsonExample
,
cb
,
true
);
CHECK
(
j
==
json
());
}
SECTION
(
"issue #1021 - to/from_msgpack only works with standard typization"
)
{
float_json
j
=
1000.0
;
CHECK
(
float_json
::
from_cbor
(
float_json
::
to_cbor
(
j
))
==
j
);
CHECK
(
float_json
::
from_msgpack
(
float_json
::
to_msgpack
(
j
))
==
j
);
CHECK
(
float_json
::
from_ubjson
(
float_json
::
to_ubjson
(
j
))
==
j
);
float_json
j2
=
{
1000.0
,
2000.0
,
3000.0
};
CHECK
(
float_json
::
from_ubjson
(
float_json
::
to_ubjson
(
j2
,
true
,
true
))
==
j2
);
}
}
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