Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dunitrust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nodes
rust
Dunitrust
Merge requests
!242
[ref]
#168
: Externalize the PKSTL crate in its own repository
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
[ref]
#168
: Externalize the PKSTL crate in its own repository
elois/ext-pkstl
into
dev
Overview
0
Commits
1
Pipelines
0
Changes
27
Merged
Éloïs
requested to merge
elois/ext-pkstl
into
dev
5 years ago
Overview
0
Commits
1
Pipelines
0
Changes
27
Expand
Closes
#168 (closed)
0
0
Merge request reports
Compare
dev
dev (base)
and
latest version
latest version
84e2dfa9
1 commit,
5 years ago
27 files
+
0
−
4665
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
27
Search (e.g. *.vue) (Ctrl+P)
lib/tools/pkstl/src/complete/serde/deserializer.rs deleted
100644 → 0
+
0
−
106
Options
// Copyright (C) 2019 Eloïs SANCHEZ.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Define PKSTL deserializer.
use
super
::
SerdeError
;
use
super
::{
IncomingMessage
,
HEADER_FORMAT_LEN
};
use
crate
::
format
::
MessageFormat
;
use
crate
::{
Error
,
IncomingBinaryMessage
,
Result
,
SecureLayer
};
use
serde
::
de
::
DeserializeOwned
;
use
std
::
convert
::
TryFrom
;
use
std
::
fmt
::
Debug
;
pub
(
crate
)
fn
read
<
M
>
(
sl
:
&
mut
SecureLayer
,
incoming_datas
:
&
[
u8
],
)
->
Result
<
Vec
<
IncomingMessage
<
M
>>>
where
M
:
Debug
+
DeserializeOwned
,
{
let
bin_msgs
=
sl
.read_bin
(
incoming_datas
)
?
;
let
mut
msgs
=
Vec
::
new
();
for
bin_msg
in
bin_msgs
{
match
bin_msg
{
IncomingBinaryMessage
::
Connect
{
custom_datas
,
peer_sig_public_key
,
}
=>
msgs
.push
(
IncomingMessage
::
Connect
{
custom_datas
:
if
let
Some
(
custom_datas
)
=
custom_datas
{
Some
(
deserialize
(
&
custom_datas
)
?
)
}
else
{
None
},
peer_sig_public_key
,
}),
IncomingBinaryMessage
::
Ack
{
custom_datas
}
=>
msgs
.push
(
IncomingMessage
::
Ack
{
custom_datas
:
if
let
Some
(
custom_datas
)
=
custom_datas
{
Some
(
deserialize
(
&
custom_datas
)
?
)
}
else
{
None
},
}),
IncomingBinaryMessage
::
Message
{
datas
}
=>
msgs
.push
(
IncomingMessage
::
Message
{
datas
:
if
let
Some
(
datas
)
=
datas
{
Some
(
deserialize
(
&
datas
)
?
)
}
else
{
None
},
}),
};
}
Ok
(
msgs
)
}
#[inline]
fn
deserialize
<
M
:
Debug
+
DeserializeOwned
>
(
binary_message
:
&
[
u8
])
->
Result
<
M
>
{
if
binary_message
.len
()
<
HEADER_FORMAT_LEN
{
return
Err
(
Error
::
RecvInvalidMsg
(
crate
::
errors
::
IncomingMsgErr
::
MessageTooShort
,
));
}
// Read format
let
message_format
=
MessageFormat
::
try_from
(
&
binary_message
[
..
HEADER_FORMAT_LEN
])
?
;
deserialize_inner
(
&
binary_message
[
HEADER_FORMAT_LEN
..
],
message_format
)
.map_err
(
Error
::
SerdeError
)
}
pub
fn
deserialize_inner
<
M
>
(
binary_message
:
&
[
u8
],
message_format
:
MessageFormat
,
)
->
std
::
result
::
Result
<
M
,
SerdeError
>
where
M
:
Debug
+
DeserializeOwned
,
{
match
message_format
{
MessageFormat
::
RawBinary
=>
Err
(
SerdeError
::
UseSuffixedBinFunctions
),
#[cfg(feature
=
"bin"
)]
MessageFormat
::
Bincode
=>
Ok
(
bincode
::
deserialize
::
<
M
>
(
binary_message
)
.map_err
(|
e
|
SerdeError
::
BincodeError
(
format!
(
"{}"
,
e
)))
?
),
#[cfg(feature
=
"cbor"
)]
MessageFormat
::
Cbor
=>
{
Ok
(
serde_cbor
::
from_slice
::
<
M
>
(
binary_message
)
.map_err
(
SerdeError
::
CborError
)
?
)
}
#[cfg(feature
=
"json"
)]
MessageFormat
::
Utf8Json
=>
{
Ok
(
serde_json
::
from_slice
::
<
M
>
(
binary_message
)
.map_err
(
SerdeError
::
JsonError
)
?
)
}
_
=>
unimplemented!
(),
}
}
Loading