falco_event/types/primitive/
bool.rs

1use crate::fields::{FromBytes, FromBytesError, ToBytes};
2use crate::types::primitive::bool;
3use std::io::Write;
4
5impl FromBytes<'_> for bool {
6    #[inline]
7    fn from_bytes(buf: &mut &[u8]) -> Result<Self, FromBytesError> {
8        let val = u32::from_bytes(buf)?;
9        Ok(val != 0)
10    }
11}
12
13impl ToBytes for bool {
14    #[inline]
15    fn binary_size(&self) -> usize {
16        std::mem::size_of::<u32>()
17    }
18
19    #[inline]
20    fn write<W: Write>(&self, writer: W) -> std::io::Result<()> {
21        let val: u32 = if *self { 1 } else { 0 };
22        val.write(writer)
23    }
24
25    #[inline]
26    fn default_repr() -> impl ToBytes {
27        0u32
28    }
29}