use bacnet_types::constructed::{AssignedLandingCall, BACnetAssignedLandingCalls};
use bacnet_types::enums::LiftCarDirection;
use bacnet_types::error::Error;
use bytes::BytesMut;
use super::floor_pairs::{decode_floor_pairs, encode_floor_pairs, PairNames};
const NAMES: PairNames = PairNames {
value: "assigned landing calls",
frame: "assigned landing calls landing-calls",
floor: "landing call floor-number",
second: "landing call direction",
second_oversized: "direction [1] exceeds 32 bits",
};
pub fn encode_assigned_landing_calls(buf: &mut BytesMut, value: &BACnetAssignedLandingCalls) {
encode_floor_pairs(
buf,
value
.landing_calls
.iter()
.map(|call| (call.floor_number, call.direction.to_raw())),
);
}
pub fn decode_assigned_landing_calls(
data: &[u8],
offset: usize,
) -> Result<(BACnetAssignedLandingCalls, usize), Error> {
let (pairs, end) = decode_floor_pairs(data, offset, &NAMES)?;
let landing_calls = pairs
.into_iter()
.map(|(floor_number, direction)| AssignedLandingCall {
floor_number,
direction: LiftCarDirection::from_raw(direction),
})
.collect();
Ok((BACnetAssignedLandingCalls { landing_calls }, end))
}