@@ -20,7 +20,21 @@ impl Clone for Inner {
2020 this
2121 }
2222}
23- impl ByteRepr for Inner { }
23+ impl ByteRepr for Inner {
24+ fn byte_size ( ) -> usize {
25+ 16
26+ }
27+ fn to_bytes ( & self , buf : & mut [ u8 ] ) {
28+ ( * self . v . borrow ( ) ) . to_bytes ( & mut buf[ 0 ..4 ] ) ;
29+ ( * self . name . borrow ( ) ) . to_bytes ( & mut buf[ 8 ..16 ] ) ;
30+ }
31+ fn from_bytes ( buf : & [ u8 ] ) -> Self {
32+ Self {
33+ v : Rc :: new ( RefCell :: new ( <i32 >:: from_bytes ( & buf[ 0 ..4 ] ) ) ) ,
34+ name : Rc :: new ( RefCell :: new ( <Ptr < u8 > >:: from_bytes ( & buf[ 8 ..16 ] ) ) ) ,
35+ }
36+ }
37+ }
2438#[ derive( ) ]
2539pub struct Outer {
2640 pub p1 : Value < Ptr < i32 > > ,
@@ -65,7 +79,35 @@ impl Default for Outer {
6579 }
6680 }
6781}
68- impl ByteRepr for Outer { }
82+ impl ByteRepr for Outer {
83+ fn byte_size ( ) -> usize {
84+ 88
85+ }
86+ fn to_bytes ( & self , buf : & mut [ u8 ] ) {
87+ ( * self . p1 . borrow ( ) ) . to_bytes ( & mut buf[ 0 ..8 ] ) ;
88+ ( * self . p2 . borrow ( ) ) . to_bytes ( & mut buf[ 8 ..16 ] ) ;
89+ ( * self . arr . borrow ( ) ) . to_bytes ( & mut buf[ 16 ..40 ] ) ;
90+ ( * self . cp . borrow ( ) ) . to_bytes ( & mut buf[ 40 ..48 ] ) ;
91+ ( * self . pp . borrow ( ) ) . to_bytes ( & mut buf[ 48 ..56 ] ) ;
92+ ( * self . inner . borrow ( ) ) . to_bytes ( & mut buf[ 56 ..72 ] ) ;
93+ ( * self . x . borrow ( ) ) . to_bytes ( & mut buf[ 72 ..76 ] ) ;
94+ ( * self . fn_ . borrow ( ) ) . to_bytes ( & mut buf[ 80 ..88 ] ) ;
95+ }
96+ fn from_bytes ( buf : & [ u8 ] ) -> Self {
97+ Self {
98+ p1 : Rc :: new ( RefCell :: new ( <Ptr < i32 > >:: from_bytes ( & buf[ 0 ..8 ] ) ) ) ,
99+ p2 : Rc :: new ( RefCell :: new ( <Ptr < i32 > >:: from_bytes ( & buf[ 8 ..16 ] ) ) ) ,
100+ arr : Rc :: new ( RefCell :: new ( <Box < [ Ptr < i32 > ] > >:: from_bytes ( & buf[ 16 ..40 ] ) ) ) ,
101+ cp : Rc :: new ( RefCell :: new ( <Ptr < u8 > >:: from_bytes ( & buf[ 40 ..48 ] ) ) ) ,
102+ pp : Rc :: new ( RefCell :: new ( <Ptr < Ptr < i32 > > >:: from_bytes ( & buf[ 48 ..56 ] ) ) ) ,
103+ inner : Rc :: new ( RefCell :: new ( <Inner >:: from_bytes ( & buf[ 56 ..72 ] ) ) ) ,
104+ x : Rc :: new ( RefCell :: new ( <i32 >:: from_bytes ( & buf[ 72 ..76 ] ) ) ) ,
105+ fn_ : Rc :: new ( RefCell :: new ( <FnPtr < fn ( i32 ) -> i32 > >:: from_bytes (
106+ & buf[ 80 ..88 ] ,
107+ ) ) ) ,
108+ }
109+ }
110+ }
69111#[ derive( ) ]
70112pub struct Foo {
71113 pub s1 : Value < Ptr < u8 > > ,
@@ -97,7 +139,31 @@ impl Default for Foo {
97139 }
98140 }
99141}
100- impl ByteRepr for Foo { }
142+ impl ByteRepr for Foo {
143+ fn byte_size ( ) -> usize {
144+ 40
145+ }
146+ fn to_bytes ( & self , buf : & mut [ u8 ] ) {
147+ ( * self . s1 . borrow ( ) ) . to_bytes ( & mut buf[ 0 ..8 ] ) ;
148+ ( * self . s2 . borrow ( ) ) . to_bytes ( & mut buf[ 8 ..16 ] ) ;
149+ ( * self . fn1 . borrow ( ) ) . to_bytes ( & mut buf[ 16 ..24 ] ) ;
150+ ( * self . fn2 . borrow ( ) ) . to_bytes ( & mut buf[ 24 ..32 ] ) ;
151+ ( * self . n . borrow ( ) ) . to_bytes ( & mut buf[ 32 ..36 ] ) ;
152+ }
153+ fn from_bytes ( buf : & [ u8 ] ) -> Self {
154+ Self {
155+ s1 : Rc :: new ( RefCell :: new ( <Ptr < u8 > >:: from_bytes ( & buf[ 0 ..8 ] ) ) ) ,
156+ s2 : Rc :: new ( RefCell :: new ( <Ptr < u8 > >:: from_bytes ( & buf[ 8 ..16 ] ) ) ) ,
157+ fn1 : Rc :: new ( RefCell :: new ( <FnPtr < fn ( i32 ) -> i32 > >:: from_bytes (
158+ & buf[ 16 ..24 ] ,
159+ ) ) ) ,
160+ fn2 : Rc :: new ( RefCell :: new ( <FnPtr < fn ( i32 ) -> i32 > >:: from_bytes (
161+ & buf[ 24 ..32 ] ,
162+ ) ) ) ,
163+ n : Rc :: new ( RefCell :: new ( <i32 >:: from_bytes ( & buf[ 32 ..36 ] ) ) ) ,
164+ }
165+ }
166+ }
101167thread_local ! (
102168 pub static static_fn_0: Value <FnPtr <fn ( i32 ) -> i32 >> = Rc :: new( RefCell :: new( FnPtr :: null( ) ) ) ;
103169) ;
0 commit comments