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
126ce2e5
Unverified
Commit
126ce2e5
authored
7 years ago
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
further UBJSON
parent
c9938ea8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
8 deletions
+83
-8
src/json.hpp
src/json.hpp
+79
-0
test/src/unit-ubjson.cpp
test/src/unit-ubjson.cpp
+4
-8
No files found.
src/json.hpp
View file @
126ce2e5
...
...
@@ -6395,6 +6395,85 @@ class binary_writer
}
}
char
ubjson_prefix
(
const
BasicJsonType
&
j
)
{
switch
(
j
.
type
())
{
case
value_t
:
:
null
:
return
'Z'
;
case
value_t
:
:
boolean
:
return
j
.
m_value
.
boolean
?
'T'
:
'F'
;
case
value_t
:
:
number_integer
:
{
if
((
std
::
numeric_limits
<
int8_t
>::
min
)()
<=
j
.
m_value
.
number_integer
and
j
.
m_value
.
number_integer
<=
(
std
::
numeric_limits
<
int8_t
>::
max
)())
{
return
'i'
;
}
else
if
((
std
::
numeric_limits
<
uint8_t
>::
min
)()
<=
j
.
m_value
.
number_integer
and
j
.
m_value
.
number_integer
<=
(
std
::
numeric_limits
<
uint8_t
>::
max
)())
{
return
'U'
;
}
else
if
((
std
::
numeric_limits
<
int16_t
>::
min
)()
<=
j
.
m_value
.
number_integer
and
j
.
m_value
.
number_integer
<=
(
std
::
numeric_limits
<
int16_t
>::
max
)())
{
return
'I'
;
}
else
if
(
-
(
std
::
numeric_limits
<
int32_t
>::
min
)()
<=
j
.
m_value
.
number_integer
and
j
.
m_value
.
number_integer
<=
(
std
::
numeric_limits
<
int32_t
>::
max
)())
{
return
'l'
;
}
else
if
((
std
::
numeric_limits
<
int64_t
>::
min
)()
<=
j
.
m_value
.
number_integer
and
j
.
m_value
.
number_integer
<=
(
std
::
numeric_limits
<
int64_t
>::
max
)())
{
return
'L'
;
}
break
;
}
case
value_t
:
:
number_unsigned
:
{
if
((
std
::
numeric_limits
<
int8_t
>::
min
)()
<=
j
.
m_value
.
number_unsigned
and
j
.
m_value
.
number_unsigned
<=
(
std
::
numeric_limits
<
int8_t
>::
max
)())
{
return
'i'
;
}
else
if
((
std
::
numeric_limits
<
uint8_t
>::
min
)()
<=
j
.
m_value
.
number_unsigned
and
j
.
m_value
.
number_unsigned
<=
(
std
::
numeric_limits
<
uint8_t
>::
max
)())
{
return
'U'
;
}
else
if
((
std
::
numeric_limits
<
int16_t
>::
min
)()
<=
j
.
m_value
.
number_unsigned
and
j
.
m_value
.
number_unsigned
<=
(
std
::
numeric_limits
<
int16_t
>::
max
)())
{
return
'I'
;
}
else
if
(
-
(
std
::
numeric_limits
<
int32_t
>::
min
)()
<=
j
.
m_value
.
number_unsigned
and
j
.
m_value
.
number_unsigned
<=
(
std
::
numeric_limits
<
int32_t
>::
max
)())
{
return
'l'
;
}
else
if
((
std
::
numeric_limits
<
int64_t
>::
min
)()
<=
j
.
m_value
.
number_unsigned
and
j
.
m_value
.
number_unsigned
<=
(
std
::
numeric_limits
<
int64_t
>::
max
)())
{
return
'L'
;
}
break
;
}
case
value_t
:
:
number_float
:
return
'D'
;
case
value_t
:
:
string
:
return
'S'
;
case
value_t
:
:
array
:
return
'['
;
case
value_t
:
:
object
:
return
'{'
;
default:
break
;
}
return
'\0'
;
}
private:
/// whether we can assume little endianess
const
bool
is_little_endian
=
binary_reader
<
BasicJsonType
>::
little_endianess
();
...
...
This diff is collapsed.
Click to expand it.
test/src/unit-ubjson.cpp
View file @
126ce2e5
...
...
@@ -414,10 +414,8 @@ TEST_CASE("UBJSON")
SECTION
(
"2147483648..9223372036854775807 (int64)"
)
{
for
(
uint64_t
i
:
{
2147483648ul
,
9223372036854775807ul
})
std
::
vector
<
uint64_t
>
v
=
{
2147483648ul
,
9223372036854775807ul
};
for
(
uint64_t
i
:
v
)
{
CAPTURE
(
i
);
...
...
@@ -605,10 +603,8 @@ TEST_CASE("UBJSON")
SECTION
(
"2147483648..9223372036854775807 (int64)"
)
{
for
(
uint64_t
i
:
{
2147483648ul
,
9223372036854775807ul
})
std
::
vector
<
uint64_t
>
v
=
{
2147483648ul
,
9223372036854775807ul
};
for
(
uint64_t
i
:
v
)
{
CAPTURE
(
i
);
...
...
This diff is collapsed.
Click to expand it.
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