godot_binary_serialization/decoder/
bool.rs1use anyhow::anyhow;
2use byteorder::{ByteOrder, LittleEndian};
3
4use crate::types::{primitive::GodotBool, SerializeFlag, TYPE_PADDING};
5
6use super::Decoder;
7
8impl Decoder {
9 pub fn decode_bool(bytes: &[u8], flag: &SerializeFlag) -> anyhow::Result<GodotBool> {
11 let length = GodotBool::BIT_SIZE;
12 if bytes.len() < TYPE_PADDING as usize + length {
13 return Err(anyhow!(
14 "Byte slice too short to decode int with flag {flag:?}"
15 ));
16 }
17
18 let value = LittleEndian::read_i32(&bytes[TYPE_PADDING as usize..]) == 1;
19
20 Ok(GodotBool { value })
21 }
22}