fidl_next/protocol/
buffer.rsuse crate::protocol::{Transport, WireMessageHeader, FLAG_0_WIRE_FORMAT_V2_BIT, MAGIC_NUMBER};
use crate::{u32_le, u64_le, DecodeError, DecoderExt as _, EncodeError, EncoderExt as _};
pub fn encode_header<T: Transport>(
buffer: &mut T::SendBuffer,
txid: u32,
ordinal: u64,
) -> Result<(), EncodeError> {
let mut encoder = T::encoder(buffer);
encoder.encode_next(&mut WireMessageHeader {
txid: u32_le::from_native(txid),
flags: [FLAG_0_WIRE_FORMAT_V2_BIT, 0, 0],
magic_number: MAGIC_NUMBER,
ordinal: u64_le::from_native(ordinal),
})
}
pub fn decode_header<T: Transport>(buffer: &mut T::RecvBuffer) -> Result<(u32, u64), DecodeError> {
let (txid, ordinal) = {
let mut decoder = T::decoder(buffer);
let header = decoder.decode_next::<WireMessageHeader>()?;
(header.txid.to_native(), header.ordinal.to_native())
};
Ok((txid, ordinal))
}