1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use super::{permission_set_clone_from_repr_c, permission_set_into_repr_c, AppExchangeInfo};
use crate::ffi::ipc::req as ffi;
use crate::ipc::errors::IpcError;
use ffi_utils::{vec_into_raw_parts, ReprC};
use safe_nd::{MDataPermissionSet, XorName};
use serde::{Deserialize, Serialize};
use std::slice;
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct ShareMDataReq {
pub app: AppExchangeInfo,
pub mdata: Vec<ShareMData>,
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct ShareMData {
pub type_tag: u64,
pub name: XorName,
pub perms: MDataPermissionSet,
}
impl ShareMDataReq {
pub fn into_repr_c(self) -> Result<ffi::ShareMDataRequest, IpcError> {
let mdata_repr_c: Vec<_> = self
.mdata
.into_iter()
.map(ShareMData::into_repr_c)
.collect::<Result<_, _>>()?;
let (mdata, mdata_len) = vec_into_raw_parts(mdata_repr_c);
Ok(ffi::ShareMDataRequest {
app: self.app.into_repr_c()?,
mdata,
mdata_len,
})
}
}
impl ReprC for ShareMDataReq {
type C = *const ffi::ShareMDataRequest;
type Error = IpcError;
unsafe fn clone_from_repr_c(repr_c: Self::C) -> Result<Self, Self::Error> {
Ok(Self {
app: AppExchangeInfo::clone_from_repr_c(&(*repr_c).app)?,
mdata: {
let mdata = slice::from_raw_parts((*repr_c).mdata, (*repr_c).mdata_len);
mdata
.iter()
.map(|c| ShareMData::clone_from_repr_c(c))
.collect::<Result<_, _>>()?
},
})
}
}
impl ShareMData {
pub fn into_repr_c(self) -> Result<ffi::ShareMData, IpcError> {
Ok(ffi::ShareMData {
type_tag: self.type_tag,
name: self.name.0,
perms: permission_set_into_repr_c(self.perms),
})
}
}
impl ReprC for ShareMData {
type C = *const ffi::ShareMData;
type Error = IpcError;
unsafe fn clone_from_repr_c(repr_c: Self::C) -> Result<Self, Self::Error> {
Ok(Self {
type_tag: (*repr_c).type_tag,
name: XorName((*repr_c).name),
perms: permission_set_clone_from_repr_c((*repr_c).perms)?,
})
}
}