Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
畅游知识海洋
json
提交
5402458f
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,发现更多精彩内容 >>
提交
5402458f
编写于
12月 12, 2016
作者:
N
Niels Lohmann
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🚑
fixed an AddressSanitizer warning
上级
a25d5700
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
22 deletion
+28
-22
src/json.hpp
src/json.hpp
+14
-11
src/json.hpp.re2c
src/json.hpp.re2c
+14
-11
未找到文件。
src/json.hpp
浏览文件 @
5402458f
...
@@ -6271,7 +6271,7 @@ class basic_json
...
@@ -6271,7 +6271,7 @@ class basic_json
types.
types.
@param[in] vec byte vector to read from
@param[in] vec byte vector to read from
@param[in] current_index the psition in the vector after which to read
@param[in] current_index the p
o
sition in the vector after which to read
@return the next sizeof(T) bytes from @a vec, in reverse order as T
@return the next sizeof(T) bytes from @a vec, in reverse order as T
...
@@ -6280,20 +6280,24 @@ class basic_json
...
@@ -6280,20 +6280,24 @@ class basic_json
@throw std::out_of_range if there are less than sizeof(T)+1 bytes in the
@throw std::out_of_range if there are less than sizeof(T)+1 bytes in the
vector @a vec to read
vector @a vec to read
In the for loop, the bytes from the vector are copied in reverse order into
the return value. In the figures below, let sizeof(T)=4 and `i` be the loop
variable.
Precondition:
Precondition:
vec: | | | a | b | c | d |
| |
T: | | | | |
vec: | | | a | b | c | d | T: | | | | |
^
^
^ ^
^
^
^ ^
current_index
idx
ptr sizeof(T)
current_index
i
ptr sizeof(T)
Postcondition:
Postcondition:
vec: | | | a | b | c | d |
| |
T: | d | c | b | a |
vec: | | | a | b | c | d | T: | d | c | b | a |
^ ^
^
^ ^ ^
|
idx
ptr
|
i
ptr
current_index
current_index
@sa Code from <http://stackoverflow.com/a/41031865/266378>.
@sa Code
adapted
from <http://stackoverflow.com/a/41031865/266378>.
*/
*/
template
<
typename
T
>
template
<
typename
T
>
static
T
get_from_vector
(
const
std
::
vector
<
uint8_t
>&
vec
,
const
size_t
current_index
)
static
T
get_from_vector
(
const
std
::
vector
<
uint8_t
>&
vec
,
const
size_t
current_index
)
...
@@ -6305,10 +6309,9 @@ class basic_json
...
@@ -6305,10 +6309,9 @@ class basic_json
T
result
;
T
result
;
uint8_t
*
ptr
=
reinterpret_cast
<
uint8_t
*>
(
&
result
);
uint8_t
*
ptr
=
reinterpret_cast
<
uint8_t
*>
(
&
result
);
size_t
idx
=
current_index
+
1
+
sizeof
(
T
);
for
(
size_t
i
=
0
;
i
<
sizeof
(
T
);
++
i
)
while
(
idx
>
current_index
)
{
{
*
ptr
++
=
vec
[
--
idx
];
*
ptr
++
=
vec
[
current_index
+
sizeof
(
T
)
-
i
];
}
}
return
result
;
return
result
;
}
}
...
...
src/json.hpp.re2c
浏览文件 @
5402458f
...
@@ -6271,7 +6271,7 @@ class basic_json
...
@@ -6271,7 +6271,7 @@ class basic_json
types.
types.
@param[in] vec byte vector to read from
@param[in] vec byte vector to read from
@param[in] current_index the psition in the vector after which to read
@param[in] current_index the p
o
sition in the vector after which to read
@return the next sizeof(T) bytes from @a vec, in reverse order as T
@return the next sizeof(T) bytes from @a vec, in reverse order as T
...
@@ -6280,20 +6280,24 @@ class basic_json
...
@@ -6280,20 +6280,24 @@ class basic_json
@throw std::out_of_range if there are less than sizeof(T)+1 bytes in the
@throw std::out_of_range if there are less than sizeof(T)+1 bytes in the
vector @a vec to read
vector @a vec to read
In the for loop, the bytes from the vector are copied in reverse order into
the return value. In the figures below, let sizeof(T)=4 and `i` be the loop
variable.
Precondition:
Precondition:
vec: | | | a | b | c | d |
| |
T: | | | | |
vec: | | | a | b | c | d | T: | | | | |
^
^
^ ^
^
^
^ ^
current_index
idx
ptr sizeof(T)
current_index
i
ptr sizeof(T)
Postcondition:
Postcondition:
vec: | | | a | b | c | d |
| |
T: | d | c | b | a |
vec: | | | a | b | c | d | T: | d | c | b | a |
^ ^
^
^ ^ ^
|
idx
ptr
|
i
ptr
current_index
current_index
@sa Code from <http://stackoverflow.com/a/41031865/266378>.
@sa Code
adapted
from <http://stackoverflow.com/a/41031865/266378>.
*/
*/
template<typename T>
template<typename T>
static T get_from_vector(const std::vector<uint8_t>& vec, const size_t current_index)
static T get_from_vector(const std::vector<uint8_t>& vec, const size_t current_index)
...
@@ -6305,10 +6309,9 @@ class basic_json
...
@@ -6305,10 +6309,9 @@ class basic_json
T result;
T result;
uint8_t* ptr = reinterpret_cast<uint8_t*>(&result);
uint8_t* ptr = reinterpret_cast<uint8_t*>(&result);
size_t idx = current_index + 1 + sizeof(T);
for (size_t i = 0; i < sizeof(T); ++i)
while (idx > current_index)
{
{
*ptr++ = vec[
--idx
];
*ptr++ = vec[
current_index + sizeof(T) - i
];
}
}
return result;
return result;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录