|
| 1 | +extern crate libcc2rs; |
| 2 | +use libcc2rs::*; |
| 3 | +use std::cell::RefCell; |
| 4 | +use std::collections::BTreeMap; |
| 5 | +use std::io::prelude::*; |
| 6 | +use std::io::{Read, Seek, Write}; |
| 7 | +use std::os::fd::AsFd; |
| 8 | +use std::rc::{Rc, Weak}; |
| 9 | +#[derive(Default)] |
| 10 | +pub struct point { |
| 11 | + pub x: Value<i32>, |
| 12 | + pub y: Value<i32>, |
| 13 | +} |
| 14 | +impl ByteRepr for point { |
| 15 | + fn to_bytes(&self, buf: &mut [u8]) { |
| 16 | + (*self.x.borrow()).to_bytes(&mut buf[0..4]); |
| 17 | + (*self.y.borrow()).to_bytes(&mut buf[4..8]); |
| 18 | + } |
| 19 | + fn from_bytes(buf: &[u8]) -> Self { |
| 20 | + Self { |
| 21 | + x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))), |
| 22 | + y: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))), |
| 23 | + } |
| 24 | + } |
| 25 | +} |
| 26 | +pub fn main() { |
| 27 | + std::process::exit(main_0()); |
| 28 | +} |
| 29 | +fn main_0() -> i32 { |
| 30 | + let src: Value<point> = Rc::new(RefCell::new(point { |
| 31 | + x: Rc::new(RefCell::new(3)), |
| 32 | + y: Rc::new(RefCell::new(7)), |
| 33 | + })); |
| 34 | + let buf: Value<Box<[u8]>> = Rc::new(RefCell::new( |
| 35 | + (0..8).map(|_| <u8>::default()).collect::<Box<[u8]>>(), |
| 36 | + )); |
| 37 | + { |
| 38 | + ((buf.as_pointer() as Ptr<u8>) as Ptr<u8>).to_any().memcpy( |
| 39 | + &((src.as_pointer()) as Ptr<point>).to_any(), |
| 40 | + ::std::mem::size_of::<[u8; 8]>() as usize, |
| 41 | + ); |
| 42 | + ((buf.as_pointer() as Ptr<u8>) as Ptr<u8>).to_any().clone() |
| 43 | + }; |
| 44 | + let dst: Value<point> = <Value<point>>::default(); |
| 45 | + { |
| 46 | + ((dst.as_pointer()) as Ptr<point>).to_any().memcpy( |
| 47 | + &((buf.as_pointer() as Ptr<u8>) as Ptr<u8>).to_any(), |
| 48 | + ::std::mem::size_of::<point>() as usize, |
| 49 | + ); |
| 50 | + ((dst.as_pointer()) as Ptr<point>).to_any().clone() |
| 51 | + }; |
| 52 | + assert!(((((*(*dst.borrow()).x.borrow()) == 3) as i32) != 0)); |
| 53 | + assert!(((((*(*dst.borrow()).y.borrow()) == 7) as i32) != 0)); |
| 54 | + return 0; |
| 55 | +} |
0 commit comments