summaryrefslogtreecommitdiff
path: root/examples/10-transient-0/output/rust/src/gen/transient_0.rs
blob: 68aa0eb191568d33c20fae03200e1ccb34d3930d (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
// Generated by hobgoblin.

pub fn encode_bool(value: &::core::primitive::bool, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> {
    if *value {
        writer.write_all(&1u8.to_le_bytes())?;
    } else {
        writer.write_all(&0u8.to_le_bytes())?;
    };
    ::std::io::Result::Ok(())
}

pub fn decode_bool(reader: &mut impl std::io::Read) -> ::std::io::Result::<::core::primitive::bool> {
    let int_value = {
        let bytes = {
            let mut bytes = [0; 1];
            reader.read_exact(&mut bytes)?;
            bytes
        };
        u8::from_le_bytes(bytes)
    };
    std::io::Result::Ok(if int_value == 0 {
        false
    } else {
        true
    })
}

pub fn encode_int_32(value: &::core::primitive::i32, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> {
    writer.write_all(&value.to_le_bytes())?;
    ::std::io::Result::Ok(())
}

pub fn decode_int_32(reader: &mut impl std::io::Read) -> ::std::io::Result::<::core::primitive::i32> {
    let bytes = {
        let mut bytes = [0; 4];
        reader.read_exact(&mut bytes)?;
        bytes
    };
    std::io::Result::Ok(::core::primitive::i32::from_le_bytes(bytes))
}

pub fn encode_int_64(value: &::core::primitive::i64, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> {
    writer.write_all(&value.to_le_bytes())?;
    ::std::io::Result::Ok(())
}

pub fn decode_int_64(reader: &mut impl std::io::Read) -> ::std::io::Result::<::core::primitive::i64> {
    let bytes = {
        let mut bytes = [0; 8];
        reader.read_exact(&mut bytes)?;
        bytes
    };
    std::io::Result::Ok(::core::primitive::i64::from_le_bytes(bytes))
}

pub fn encode_string(value: &::std::string::String, writer: &mut impl std::io::Write) -> ::std::io::Result::<()> {
    todo!();
    ::std::io::Result::Ok(())
}

pub fn decode_string(reader: &mut impl std::io::Read) -> ::std::io::Result::<::std::string::String> {
    std::io::Result::Ok(todo!())
}