Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
26c2e16a
Commit
26c2e16a
authored
Dec 14, 2019
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
value: optimize json parsing
parent
e8b385c2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/opendht/value.h
+1
-1
1 addition, 1 deletion
include/opendht/value.h
src/base64.cpp
+2
-2
2 additions, 2 deletions
src/base64.cpp
src/base64.h
+1
-1
1 addition, 1 deletion
src/base64.h
src/value.cpp
+25
-28
25 additions, 28 deletions
src/value.cpp
with
29 additions
and
32 deletions
include/opendht/value.h
+
1
−
1
View file @
26c2e16a
...
@@ -390,7 +390,7 @@ struct OPENDHT_PUBLIC Value
...
@@ -390,7 +390,7 @@ struct OPENDHT_PUBLIC Value
* Build a value from a json object
* Build a value from a json object
* @param json
* @param json
*/
*/
Value
(
Json
::
Value
&
json
);
Value
(
const
Json
::
Value
&
json
);
#endif
#endif
template
<
typename
Type
>
template
<
typename
Type
>
...
...
This diff is collapsed.
Click to expand it.
src/base64.cpp
+
2
−
2
View file @
26c2e16a
...
@@ -131,7 +131,7 @@ base64_encode(const std::vector<unsigned char>& str)
...
@@ -131,7 +131,7 @@ base64_encode(const std::vector<unsigned char>& str)
return
base64_encode
(
str
.
cbegin
(),
str
.
cend
());
return
base64_encode
(
str
.
cbegin
(),
str
.
cend
());
}
}
std
::
string
std
::
vector
<
unsigned
char
>
base64_decode
(
const
std
::
string
&
str
)
base64_decode
(
const
std
::
string
&
str
)
{
{
size_t
output_length
=
str
.
length
()
/
4
*
3
+
2
;
size_t
output_length
=
str
.
length
()
/
4
*
3
+
2
;
...
@@ -139,5 +139,5 @@ base64_decode(const std::string& str)
...
@@ -139,5 +139,5 @@ base64_decode(const std::string& str)
output
.
resize
(
output_length
);
output
.
resize
(
output_length
);
base64_decode
(
str
.
data
(),
str
.
size
(),
output
.
data
(),
&
output_length
);
base64_decode
(
str
.
data
(),
str
.
size
(),
output
.
data
(),
&
output_length
);
output
.
resize
(
output_length
);
output
.
resize
(
output_length
);
return
std
::
string
(
output
.
begin
(),
output
.
end
())
;
return
output
;
}
}
This diff is collapsed.
Click to expand it.
src/base64.h
+
1
−
1
View file @
26c2e16a
...
@@ -33,4 +33,4 @@ std::string base64_encode(const std::vector<unsigned char>& str);
...
@@ -33,4 +33,4 @@ std::string base64_encode(const std::vector<unsigned char>& str);
* @param str the input buffer
* @param str the input buffer
* @return a base64-decoded buffer
* @return a base64-decoded buffer
*/
*/
std
::
string
base64_decode
(
const
std
::
string
&
str
);
std
::
vector
<
unsigned
char
>
base64_decode
(
const
std
::
string
&
str
);
This diff is collapsed.
Click to expand it.
src/value.cpp
+
25
−
28
View file @
26c2e16a
...
@@ -165,39 +165,36 @@ Value::msgpack_unpack_body(const msgpack::object& o)
...
@@ -165,39 +165,36 @@ Value::msgpack_unpack_body(const msgpack::object& o)
}
}
#ifdef OPENDHT_JSONCPP
#ifdef OPENDHT_JSONCPP
Value
::
Value
(
Json
::
Value
&
json
)
Value
::
Value
(
const
Json
::
Value
&
json
)
{
{
id
=
Value
::
Id
(
unpackId
(
json
,
"id"
));
id
=
Value
::
Id
(
unpackId
(
json
,
"id"
));
if
(
json
.
isMember
(
"cypher"
))
{
const
auto
&
jcypher
=
json
[
"cypher"
];
auto
cypherStr
=
json
[
"cypher"
].
asString
();
if
(
jcypher
.
isString
())
cypherStr
=
base64_decode
(
cypherStr
);
cypher
=
base64_decode
(
jcypher
.
asString
());
cypher
=
std
::
vector
<
unsigned
char
>
(
cypherStr
.
begin
(),
cypherStr
.
end
());
const
auto
&
jsig
=
json
[
"sig"
];
}
if
(
jsig
.
isString
())
if
(
json
.
isMember
(
"sig"
))
{
signature
=
base64_decode
(
jsig
.
asString
());
auto
sigStr
=
json
[
"sig"
].
asString
();
const
auto
&
jseq
=
json
[
"seq"
];
sigStr
=
base64_decode
(
sigStr
);
if
(
!
jseq
.
isNull
())
signature
=
std
::
vector
<
unsigned
char
>
(
sigStr
.
begin
(),
sigStr
.
end
());
seq
=
jseq
.
asInt
();
}
const
auto
&
jowner
=
json
[
"owner"
];
if
(
json
.
isMember
(
"seq"
))
if
(
jowner
.
isString
())
{
seq
=
json
[
"seq"
].
asInt
();
auto
ownerStr
=
jowner
.
asString
();
if
(
json
.
isMember
(
"owner"
))
{
auto
ownerStr
=
json
[
"owner"
].
asString
();
auto
ownerBlob
=
std
::
vector
<
unsigned
char
>
(
ownerStr
.
begin
(),
ownerStr
.
end
());
auto
ownerBlob
=
std
::
vector
<
unsigned
char
>
(
ownerStr
.
begin
(),
ownerStr
.
end
());
owner
=
std
::
make_shared
<
const
crypto
::
PublicKey
>
(
ownerBlob
);
owner
=
std
::
make_shared
<
const
crypto
::
PublicKey
>
(
ownerBlob
);
}
}
if
(
json
.
isMember
(
"to"
))
{
const
auto
&
jto
=
json
[
"to"
];
auto
toStr
=
json
[
"to"
].
asString
();
if
(
jto
.
isString
())
recipient
=
InfoHash
(
toStr
);
recipient
=
InfoHash
(
jto
.
asString
());
}
const
auto
&
jtype
=
json
[
"type"
];
if
(
json
.
isMember
(
"type"
))
if
(
!
jtype
.
isNull
())
type
=
json
[
"type"
].
asInt
();
type
=
jtype
.
asInt
();
if
(
json
.
isMember
(
"data"
)){
const
auto
&
jdata
=
json
[
"data"
];
auto
dataStr
=
json
[
"data"
].
asString
();
if
(
jdata
.
isString
())
dataStr
=
base64_decode
(
dataStr
);
data
=
base64_decode
(
jdata
.
asString
());
data
=
std
::
vector
<
unsigned
char
>
(
dataStr
.
begin
(),
dataStr
.
end
());
const
auto
&
jutype
=
json
[
"utype"
];
}
if
(
jutype
.
isString
())
if
(
json
.
isMember
(
"utype"
))
user_type
=
jutype
.
asString
();
user_type
=
json
[
"utype"
].
asString
();
}
}
Json
::
Value
Json
::
Value
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment