godot_binary_serialization/encoder/
bool.rs1use byteorder::{ByteOrder, LittleEndian};
2
3use crate::types::{primitive::GodotBool, SerializeFlag, GodotTypeIndex};
4
5use super::Encoder;
6
7impl Encoder {
8 pub fn encode_bool(r#bool: &GodotBool) -> anyhow::Result<Vec<u8>> {
10 Ok(Self::encode_raw_bool(r#bool.value))
11 }
12
13 pub fn encode_raw_bool(r#bool: bool) -> Vec<u8> {
15 let bytes: &mut [u8] = &mut [0; 8];
16 LittleEndian::write_i16(&mut bytes[0..2], GodotTypeIndex::Bool as i16);
17 LittleEndian::write_i16(&mut bytes[2..4], SerializeFlag::None as i16);
18 LittleEndian::write_i32(&mut bytes[4..8], r#bool as i32);
19
20 bytes.to_vec()
21 }
22}