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
97
98
99
100
101
102
103
pub mod ffi;
use std::sync::Arc;

pub use ffi::*;
#[cfg(feature = "ic-stable-structures")]
pub mod ic;
macro_rules! buffer_slice_impl {
    ($t:ty) => {
        impl R68da167712ddf1601aed7908c99972e62a41bdea1e28b241306a6b58d29e532d for $t {
            fn read8(&mut self, p0: u64) -> (u32) {
                return self[p0 as usize].into();
            }

            fn write8(&mut self, p0: u64, p1: u32) -> () {
                self[p0 as usize] = (p1 & 0xff) as u8;
            }

            fn size(&mut self) -> (u64) {
                return self.len().try_into().unwrap();
            }
        }
    };
}
buffer_slice_impl!(Vec<u8>);
buffer_slice_impl!(Box<[u8]>);
buffer_slice_impl!(&'static mut [u8]);
macro_rules! buffer_ro_slice_impl {
    ($t:ty) => {
        impl R68da167712ddf1601aed7908c99972e62a41bdea1e28b241306a6b58d29e532d for $t {
            fn read8(&mut self, p0: u64) -> (u32) {
                return self[p0 as usize].into();
            }

            fn write8(&mut self, p0: u64, p1: u32) -> () {
                
            }

            fn size(&mut self) -> (u64) {
                return self.len().try_into().unwrap();
            }
        }
    };
}
buffer_ro_slice_impl!(Arc<[u8]>);
buffer_ro_slice_impl!(&'static [u8]);
pub fn slice<'a>(
    x: &'a mut dyn R68da167712ddf1601aed7908c99972e62a41bdea1e28b241306a6b58d29e532d,
) -> impl Iterator<Item = u8> + 'a {
    return (0..x.size()).map(|a| (x.read8(a) & 0xff) as u8);
}
pub fn copy<'a, 'b>(
    a: &'a mut dyn R68da167712ddf1601aed7908c99972e62a41bdea1e28b241306a6b58d29e532d,
    ai: u64,
    b: &'b mut dyn R68da167712ddf1601aed7908c99972e62a41bdea1e28b241306a6b58d29e532d,
    bi: u64,
) {
    let l = (a.size() - ai).min(b.size() - bi);
    for i in 0..l {
        a.write8(ai + i, b.read8(bi + i));
    }
}
pub fn copy_slice_in<'a, 'b>(
    a: &'a mut dyn R68da167712ddf1601aed7908c99972e62a41bdea1e28b241306a6b58d29e532d,
    ai: u64,
    b: &'b [u8],
) {
    for (i, b) in b.iter().enumerate() {
        if (i as u64) + ai >= a.size() {
            return;
        }
        a.write8(ai + (i as u64), *b as u32)
    }
}
pub fn copy_slice_out<'a, 'b>(
    c: &'a mut [u8],
    b: &'b mut dyn R68da167712ddf1601aed7908c99972e62a41bdea1e28b241306a6b58d29e532d,
    bi: u64,
) {
    for (i, c) in c.iter_mut().enumerate() {
        if (i as u64) + bi >= b.size() {
            return;
        }
        *c = (b.read8(bi + (i as u64)) & 0xff) as u8;
    }
}
pub struct Slice<T>{
    pub wrapped: T,
    pub begin: u64,
    pub size: u64
}
impl<T: R68da167712ddf1601aed7908c99972e62a41bdea1e28b241306a6b58d29e532d> R68da167712ddf1601aed7908c99972e62a41bdea1e28b241306a6b58d29e532d for Slice<T>{
    fn read8(&mut self, p0: u64) -> (u32) {
        self.wrapped.read8(p0 + self.begin)
    }

    fn size(&mut self) -> (u64) {
        self.size
    }

    fn write8(&mut self, p0: u64, p1: u32) -> () {
        self.wrapped.write8(p0 + self.begin, p1)
    }
}