use super::MessageHeader;
use super::TransportMessageV0;
use crate::codec::arrow::write_arrow_to_bytes;
use crate::codec::CodecError;
use re_chunk::TransportChunk;
impl MessageHeader {
pub(crate) fn encode(&self, write: &mut impl std::io::Write) -> Result<(), CodecError> {
write
.write_all(&[self.0])
.map_err(CodecError::HeaderEncoding)?;
Ok(())
}
}
impl TransportMessageV0 {
pub(crate) fn to_bytes(&self) -> Result<Vec<u8>, CodecError> {
match self {
Self::NoData => {
let mut data: Vec<u8> = Vec::new();
MessageHeader::NO_DATA.encode(&mut data)?;
Ok(data)
}
Self::RecordBatch(chunk) => {
let mut data: Vec<u8> = Vec::new();
MessageHeader::RECORD_BATCH.encode(&mut data)?;
write_arrow_to_bytes(&mut data, &chunk.schema, &chunk.data)?;
Ok(data)
}
}
}
}
pub fn no_data(version: re_protos::common::v0::EncoderVersion) -> Result<Vec<u8>, CodecError> {
match version {
re_protos::common::v0::EncoderVersion::V0 => TransportMessageV0::NoData.to_bytes(),
}
}
pub fn encode(
version: re_protos::common::v0::EncoderVersion,
chunk: TransportChunk,
) -> Result<Vec<u8>, CodecError> {
match version {
re_protos::common::v0::EncoderVersion::V0 => {
TransportMessageV0::RecordBatch(chunk).to_bytes()
}
}
}