@@ -11,14 +11,49 @@ use rkyv::ser::serializers::{
11
11
BufferScratch , BufferSerializer , CompositeSerializer ,
12
12
} ;
13
13
use rkyv:: ser:: Serializer ;
14
- use rkyv:: { archived_root, Archive , Deserialize , Infallible , Serialize } ;
14
+ use rkyv:: validation:: validators:: DefaultValidator ;
15
+ use rkyv:: {
16
+ archived_root, check_archived_root, Archive , Deserialize , Infallible ,
17
+ Serialize ,
18
+ } ;
15
19
16
20
use crate :: types:: StandardBufSerializer ;
17
21
18
22
/// Wrap a call with its respective (de)serializers.
23
+ /// Checks integrity of the arguments.
19
24
///
20
25
/// Returns the length of result written to the buffer.
21
26
pub fn wrap_call < A , R , F > ( arg_len : u32 , f : F ) -> u32
27
+ where
28
+ A : Archive ,
29
+ A :: Archived : Deserialize < A , Infallible >
30
+ + for < ' b > bytecheck:: CheckBytes < DefaultValidator < ' b > > ,
31
+ R : for < ' a > Serialize < StandardBufSerializer < ' a > > ,
32
+ F : Fn ( A ) -> R ,
33
+ {
34
+ with_arg_buf ( |buf| {
35
+ let slice = & buf[ ..arg_len as usize ] ;
36
+
37
+ let aa: & A :: Archived = check_archived_root :: < A > ( slice)
38
+ . expect ( "Argument should correctly deserialize" ) ;
39
+ let a: A = aa. deserialize ( & mut Infallible ) . unwrap ( ) ;
40
+
41
+ let ret = f ( a) ;
42
+
43
+ let mut sbuf = [ 0u8 ; SCRATCH_BUF_BYTES ] ;
44
+ let scratch = BufferScratch :: new ( & mut sbuf) ;
45
+ let ser = BufferSerializer :: new ( buf) ;
46
+ let mut composite = CompositeSerializer :: new ( ser, scratch, Infallible ) ;
47
+ composite. serialize_value ( & ret) . expect ( "infallible" ) ;
48
+ composite. pos ( ) as u32
49
+ } )
50
+ }
51
+
52
+ /// Wrap a call with its respective (de)serializers.
53
+ /// Does not check the integrity of arguments.
54
+ ///
55
+ /// Returns the length of result written to the buffer.
56
+ pub fn wrap_call_unchecked < A , R , F > ( arg_len : u32 , f : F ) -> u32
22
57
where
23
58
A : Archive ,
24
59
A :: Archived : Deserialize < A , Infallible > ,
0 commit comments