Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
畅游知识海洋
json
提交
757d2c6c
J
json
项目概览
畅游知识海洋
/
json
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
json
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
757d2c6c
编写于
3月 06, 2017
作者:
N
Niels Lohmann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🔨
replaced at() calls in msgpack/cbor
上级
54073332
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
24 deletion
+40
-24
src/json.hpp
src/json.hpp
+20
-12
src/json.hpp.re2c
src/json.hpp.re2c
+20
-12
未找到文件。
src/json.hpp
浏览文件 @
757d2c6c
...
...
@@ -7957,12 +7957,12 @@ class basic_json
*/
static
basic_json
from_msgpack_internal
(
const
std
::
vector
<
uint8_t
>&
v
,
size_t
&
idx
)
{
// make sure reading 1 byte is safe
check_length
(
v
.
size
(),
1
,
idx
);
// store and increment index
const
size_t
current_idx
=
idx
++
;
// make sure reading 1 byte is safe
check_length
(
v
.
size
(),
1
,
current_idx
);
if
(
v
[
current_idx
]
<=
0xbf
)
{
if
(
v
[
current_idx
]
<=
0x7f
)
// positive fixint
...
...
@@ -8026,9 +8026,10 @@ class basic_json
{
// copy bytes in reverse order into the double variable
float
res
;
check_length
(
v
.
size
(),
sizeof
(
float
),
current_idx
+
1
);
for
(
size_t
byte
=
0
;
byte
<
sizeof
(
float
);
++
byte
)
{
reinterpret_cast
<
uint8_t
*>
(
&
res
)[
sizeof
(
float
)
-
byte
-
1
]
=
v
.
at
(
current_idx
+
1
+
byte
)
;
reinterpret_cast
<
uint8_t
*>
(
&
res
)[
sizeof
(
float
)
-
byte
-
1
]
=
v
[
current_idx
+
1
+
byte
]
;
}
idx
+=
sizeof
(
float
);
// skip content bytes
return
res
;
...
...
@@ -8038,9 +8039,10 @@ class basic_json
{
// copy bytes in reverse order into the double variable
double
res
;
check_length
(
v
.
size
(),
sizeof
(
double
),
current_idx
+
1
);
for
(
size_t
byte
=
0
;
byte
<
sizeof
(
double
);
++
byte
)
{
reinterpret_cast
<
uint8_t
*>
(
&
res
)[
sizeof
(
double
)
-
byte
-
1
]
=
v
.
at
(
current_idx
+
1
+
byte
)
;
reinterpret_cast
<
uint8_t
*>
(
&
res
)[
sizeof
(
double
)
-
byte
-
1
]
=
v
[
current_idx
+
1
+
byte
]
;
}
idx
+=
sizeof
(
double
);
// skip content bytes
return
res
;
...
...
@@ -8198,7 +8200,10 @@ class basic_json
// store and increment index
const
size_t
current_idx
=
idx
++
;
switch
(
v
.
at
(
current_idx
))
// make sure reading 1 byte is safe
check_length
(
v
.
size
(),
1
,
current_idx
);
switch
(
v
[
current_idx
])
{
// Integer 0x00..0x17 (0..23)
case
0x00
:
...
...
@@ -8379,7 +8384,7 @@ class basic_json
case
0x7f
:
// UTF-8 string (indefinite length)
{
std
::
string
result
;
while
(
v
.
at
(
idx
)
!=
0xff
)
while
(
check_length
(
v
.
size
(),
1
,
idx
),
v
[
idx
]
!=
0xff
)
{
string_t
s
=
from_cbor_internal
(
v
,
idx
);
result
+=
s
;
...
...
@@ -8475,7 +8480,7 @@ class basic_json
case
0x9f
:
// array (indefinite length)
{
basic_json
result
=
value_t
::
array
;
while
(
v
.
at
(
idx
)
!=
0xff
)
while
(
check_length
(
v
.
size
(),
1
,
idx
),
v
[
idx
]
!=
0xff
)
{
result
.
push_back
(
from_cbor_internal
(
v
,
idx
));
}
...
...
@@ -8575,7 +8580,7 @@ class basic_json
case
0xbf
:
// map (indefinite length)
{
basic_json
result
=
value_t
::
object
;
while
(
v
.
at
(
idx
)
!=
0xff
)
while
(
check_length
(
v
.
size
(),
1
,
idx
),
v
[
idx
]
!=
0xff
)
{
std
::
string
key
=
from_cbor_internal
(
v
,
idx
);
result
[
key
]
=
from_cbor_internal
(
v
,
idx
);
...
...
@@ -8611,7 +8616,8 @@ class basic_json
// include at least decoding support for them even without such
// support. An example of a small decoder for half-precision
// floating-point numbers in the C language is shown in Fig. 3.
const
int
half
=
(
v
.
at
(
current_idx
+
1
)
<<
8
)
+
v
.
at
(
current_idx
+
2
);
check_length
(
v
.
size
(),
2
,
current_idx
+
1
);
const
int
half
=
(
v
[
current_idx
+
1
]
<<
8
)
+
v
[
current_idx
+
2
];
const
int
exp
=
(
half
>>
10
)
&
0x1f
;
const
int
mant
=
half
&
0x3ff
;
double
val
;
...
...
@@ -8636,9 +8642,10 @@ class basic_json
{
// copy bytes in reverse order into the float variable
float
res
;
check_length
(
v
.
size
(),
sizeof
(
float
),
current_idx
+
1
);
for
(
size_t
byte
=
0
;
byte
<
sizeof
(
float
);
++
byte
)
{
reinterpret_cast
<
uint8_t
*>
(
&
res
)[
sizeof
(
float
)
-
byte
-
1
]
=
v
.
at
(
current_idx
+
1
+
byte
)
;
reinterpret_cast
<
uint8_t
*>
(
&
res
)[
sizeof
(
float
)
-
byte
-
1
]
=
v
[
current_idx
+
1
+
byte
]
;
}
idx
+=
sizeof
(
float
);
// skip content bytes
return
res
;
...
...
@@ -8648,9 +8655,10 @@ class basic_json
{
// copy bytes in reverse order into the double variable
double
res
;
check_length
(
v
.
size
(),
sizeof
(
double
),
current_idx
+
1
);
for
(
size_t
byte
=
0
;
byte
<
sizeof
(
double
);
++
byte
)
{
reinterpret_cast
<
uint8_t
*>
(
&
res
)[
sizeof
(
double
)
-
byte
-
1
]
=
v
.
at
(
current_idx
+
1
+
byte
)
;
reinterpret_cast
<
uint8_t
*>
(
&
res
)[
sizeof
(
double
)
-
byte
-
1
]
=
v
[
current_idx
+
1
+
byte
]
;
}
idx
+=
sizeof
(
double
);
// skip content bytes
return
res
;
...
...
src/json.hpp.re2c
浏览文件 @
757d2c6c
...
...
@@ -7957,12 +7957,12 @@ class basic_json
*/
static basic_json from_msgpack_internal(const std::vector<uint8_t>& v, size_t& idx)
{
// make sure reading 1 byte is safe
check_length(v.size(), 1, idx);
// store and increment index
const size_t current_idx = idx++;
// make sure reading 1 byte is safe
check_length(v.size(), 1, current_idx);
if (v[current_idx] <= 0xbf)
{
if (v[current_idx] <= 0x7f) // positive fixint
...
...
@@ -8026,9 +8026,10 @@ class basic_json
{
// copy bytes in reverse order into the double variable
float res;
check_length(v.size(), sizeof(float), current_idx + 1);
for (size_t byte = 0; byte < sizeof(float); ++byte)
{
reinterpret_cast<uint8_t*>(&res)[sizeof(float) - byte - 1] = v
.at(current_idx + 1 + byte)
;
reinterpret_cast<uint8_t*>(&res)[sizeof(float) - byte - 1] = v
[current_idx + 1 + byte]
;
}
idx += sizeof(float); // skip content bytes
return res;
...
...
@@ -8038,9 +8039,10 @@ class basic_json
{
// copy bytes in reverse order into the double variable
double res;
check_length(v.size(), sizeof(double), current_idx + 1);
for (size_t byte = 0; byte < sizeof(double); ++byte)
{
reinterpret_cast<uint8_t*>(&res)[sizeof(double) - byte - 1] = v
.at(current_idx + 1 + byte)
;
reinterpret_cast<uint8_t*>(&res)[sizeof(double) - byte - 1] = v
[current_idx + 1 + byte]
;
}
idx += sizeof(double); // skip content bytes
return res;
...
...
@@ -8198,7 +8200,10 @@ class basic_json
// store and increment index
const size_t current_idx = idx++;
switch (v.at(current_idx))
// make sure reading 1 byte is safe
check_length(v.size(), 1, current_idx);
switch (v[current_idx])
{
// Integer 0x00..0x17 (0..23)
case 0x00:
...
...
@@ -8379,7 +8384,7 @@ class basic_json
case 0x7f: // UTF-8 string (indefinite length)
{
std::string result;
while (
v.at(idx)
!= 0xff)
while (
check_length(v.size(), 1, idx), v[idx]
!= 0xff)
{
string_t s = from_cbor_internal(v, idx);
result += s;
...
...
@@ -8475,7 +8480,7 @@ class basic_json
case 0x9f: // array (indefinite length)
{
basic_json result = value_t::array;
while (
v.at(idx)
!= 0xff)
while (
check_length(v.size(), 1, idx), v[idx]
!= 0xff)
{
result.push_back(from_cbor_internal(v, idx));
}
...
...
@@ -8575,7 +8580,7 @@ class basic_json
case 0xbf: // map (indefinite length)
{
basic_json result = value_t::object;
while (
v.at(idx)
!= 0xff)
while (
check_length(v.size(), 1, idx), v[idx]
!= 0xff)
{
std::string key = from_cbor_internal(v, idx);
result[key] = from_cbor_internal(v, idx);
...
...
@@ -8611,7 +8616,8 @@ class basic_json
// include at least decoding support for them even without such
// support. An example of a small decoder for half-precision
// floating-point numbers in the C language is shown in Fig. 3.
const int half = (v.at(current_idx + 1) << 8) + v.at(current_idx + 2);
check_length(v.size(), 2, current_idx + 1);
const int half = (v[current_idx + 1] << 8) + v[current_idx + 2];
const int exp = (half >> 10) & 0x1f;
const int mant = half & 0x3ff;
double val;
...
...
@@ -8636,9 +8642,10 @@ class basic_json
{
// copy bytes in reverse order into the float variable
float res;
check_length(v.size(), sizeof(float), current_idx + 1);
for (size_t byte = 0; byte < sizeof(float); ++byte)
{
reinterpret_cast<uint8_t*>(&res)[sizeof(float) - byte - 1] = v
.at(current_idx + 1 + byte)
;
reinterpret_cast<uint8_t*>(&res)[sizeof(float) - byte - 1] = v
[current_idx + 1 + byte]
;
}
idx += sizeof(float); // skip content bytes
return res;
...
...
@@ -8648,9 +8655,10 @@ class basic_json
{
// copy bytes in reverse order into the double variable
double res;
check_length(v.size(), sizeof(double), current_idx + 1);
for (size_t byte = 0; byte < sizeof(double); ++byte)
{
reinterpret_cast<uint8_t*>(&res)[sizeof(double) - byte - 1] = v
.at(current_idx + 1 + byte)
;
reinterpret_cast<uint8_t*>(&res)[sizeof(double) - byte - 1] = v
[current_idx + 1 + byte]
;
}
idx += sizeof(double); // skip content bytes
return res;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录