falco_event/types/primitive/
bool.rs

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