Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mtxclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
mtxclient
Commits
79b67668
Commit
79b67668
authored
7 years ago
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Simplify some calls
parent
71f3ac1a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/client.hpp
+11
-20
11 additions, 20 deletions
src/client.hpp
src/utils.cpp
+2
-0
2 additions, 0 deletions
src/utils.cpp
with
13 additions
and
20 deletions
src/client.hpp
+
11
−
20
View file @
79b67668
...
...
@@ -297,12 +297,7 @@ template<class T>
inline
T
deserialize
(
const
std
::
string
&
data
)
{
T
res
;
nlohmann
::
json
j
=
json
::
parse
(
data
);
res
=
j
;
return
res
;
return
json
::
parse
(
data
);
}
template
<
>
...
...
@@ -316,8 +311,7 @@ template<class T>
inline
std
::
string
serialize
(
const
T
&
obj
)
{
nlohmann
::
json
j
=
obj
;
return
j
.
dump
();
return
json
(
obj
).
dump
();
}
template
<
>
...
...
@@ -441,17 +435,18 @@ mtx::client::Client::create_session(
Response
response_data
;
mtx
::
client
::
errors
::
ClientError
client_error
;
const
auto
header
=
response
.
base
();
if
(
err_code
)
{
client_error
.
error_code
=
err_code
;
return
callback
(
response_data
,
response
.
base
()
,
client_error
);
return
callback
(
response_data
,
header
,
client_error
);
}
// Decompress the response.
const
auto
encoding
=
response
.
base
()[
"Content-Encoding"
].
to_string
();
const
auto
body
=
utils
::
decompress
(
const
auto
body
=
utils
::
decompress
(
boost
::
iostreams
::
array_source
{
response
.
body
().
data
(),
response
.
body
().
size
()},
encoding
);
header
[
"Content-Encoding"
].
to_string
()
);
if
(
response
.
result
()
!=
boost
::
beast
::
http
::
status
::
ok
)
{
client_error
.
status_code
=
response
.
result
();
...
...
@@ -469,27 +464,23 @@ mtx::client::Client::create_session(
mtx
::
errors
::
Error
matrix_error
=
json_error
;
client_error
.
matrix_error
=
matrix_error
;
return
callback
(
response_data
,
response
.
base
(),
client_error
);
return
callback
(
response_data
,
header
,
client_error
);
}
catch
(
const
nlohmann
::
json
::
exception
&
e
)
{
client_error
.
parse_error
=
std
::
string
(
e
.
what
())
+
": "
+
body
;
return
callback
(
response_data
,
response
.
base
(),
client_error
);
return
callback
(
response_data
,
header
,
client_error
);
}
}
// If we reach that point we most likely have a valid output from the
// homeserver.
try
{
response_data
=
deserialize
<
Response
>
(
body
);
callback
(
deserialize
<
Response
>
(
body
)
,
header
,
{})
;
}
catch
(
const
nlohmann
::
json
::
exception
&
e
)
{
client_error
.
parse_error
=
std
::
string
(
e
.
what
())
+
": "
+
body
;
return
callback
(
response_data
,
response
.
base
()
,
client_error
);
callback
(
response_data
,
header
,
client_error
);
}
callback
(
response_data
,
response
.
base
(),
{});
});
},
[
callback
](
RequestID
,
const
boost
::
system
::
error_code
ec
)
{
...
...
This diff is collapsed.
Click to expand it.
src/utils.cpp
+
2
−
0
View file @
79b67668
...
...
@@ -57,6 +57,8 @@ std::string
mtx
::
client
::
utils
::
decompress
(
const
boost
::
iostreams
::
array_source
&
src
,
const
std
::
string
&
type
)
{
boost
::
iostreams
::
filtering_istream
is
;
is
.
set_auto_close
(
true
);
std
::
stringstream
decompressed
;
if
(
type
==
"deflate"
)
...
...
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