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
use crate::prelude::*;
use crate::internal::encodings::packed_bool::*;

impl Primitive for bool {
    fn id() -> PrimitiveId {
        PrimitiveId::Boolean
    }
    fn from_dyn_branch(branch: DynBranch) -> OneOrMany<Self> {
        match branch {
            DynBranch::Boolean(v) => v,
            _ => todo!("schema mismatch"),
        }
    }
}

impl BatchData for bool {
    fn read_batch(bytes: &[u8]) -> Vec<Self> {
        decode_packed_bool(bytes)
    }
    fn write_batch(items: &[Self], bytes: &mut Vec<u8>) {
        encode_packed_bool(items, bytes);
    }
    fn read_one(bytes: &[u8], offset: &mut usize) -> Self {
        // TODO: Performance
        Self::read_batch(read_bytes(bytes, 1, offset))[0]
    }
}