summaryrefslogtreecommitdiff
path: root/examples/15-transient-0/output/rust/src/data.rs
blob: 2b890c2aed9f4a303be3477d00bee1b004c974b3 (plain)
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
include!("./gen/data.rs");

#[derive(Clone, Debug, Hash, PartialEq)]
pub struct Native {
    pub a: i32,
    pub b: i32,
}

#[derive(Clone, Debug, Hash, PartialEq)]
pub struct GenericNative<A, B> {
    pub a: A,
    pub b: B,
}


pub mod transient_0 {
    use ::std::any::Any;
    use ::std::sync::Arc;
    use ::std::vec::Vec;
    use crate::transient_0::{Decode, Encode};
    use super::{GenericNative, Native};

    include!("./gen/data/transient_0.rs");

    pub fn encode_native(
        value: &Native,
        writer: &mut impl std::io::Write,
        shared_values: &mut ::std::collections::HashMap::<usize, i64>,
    ) -> std::io::Result<()> {
        crate::transient_0::encode_int_32(&value.a, writer, shared_values)?;
        crate::transient_0::encode_int_32(&value.b, writer, shared_values)?;
        Ok(())
    }

    pub fn decode_native(
        reader: &mut impl std::io::Read,
        shared_values: &mut Vec<Arc::<dyn Any + Sync + Send>>,
    ) -> std::io::Result<Native> {
        let a = crate::transient_0::decode_int_32(reader, shared_values)?;
        let b = crate::transient_0::decode_int_32(reader, shared_values)?;
        Ok(Native { a, b })
    }

    pub fn encode_generic_native<TWrite: std::io::Write, A, B>(
        value: &GenericNative<A, B>,
        writer: &mut TWrite,
        shared_values: &mut ::std::collections::HashMap::<usize, i64>,
        encode_a: Encode<A, TWrite>,
        encode_b: Encode<B, TWrite>,
    ) -> std::io::Result<()> {
        encode_a(&value.a, writer, shared_values)?;
        encode_b(&value.b, writer, shared_values)?;
        Ok(())
    }

    pub fn decode_generic_native<TRead: std::io::Read, A, B>(
        reader: &mut TRead,
        shared_values: &mut Vec<Arc::<dyn Any + Sync + Send>>,
        decode_a: Decode<TRead, A>,
        decode_b: Decode<TRead, B>,
    ) -> std::io::Result<GenericNative<A, B>> {
        let a = decode_a(reader, shared_values)?;
        let b = decode_b(reader, shared_values)?;
        Ok(GenericNative { a, b })
    }
}