use super::DeserializerState;
use crate::io::{ClickHouseBytesRead, ClickHouseBytesWrite, ClickHouseRead, ClickHouseWrite};
use crate::{Result, Type};
pub(crate) trait ProtocolData<Return, Deser: Default> {
type Options;
fn write_async<W: ClickHouseWrite>(
self,
writer: &mut W,
revision: u64,
header: Option<&[(String, Type)]>,
options: Self::Options,
) -> impl Future<Output = Result<()>> + Send;
fn write<W: ClickHouseBytesWrite>(
self,
_writer: &mut W,
_revision: u64,
_header: Option<&[(String, Type)]>,
_options: Self::Options,
) -> Result<()>
where
Self: Sized;
fn read_async<R: ClickHouseRead>(
reader: &mut R,
revision: u64,
options: Self::Options,
state: &mut DeserializerState<Deser>,
) -> impl Future<Output = Result<Return>> + Send;
fn read<R: ClickHouseBytesRead + 'static>(
_reader: &mut R,
_revision: u64,
_options: Self::Options,
_state: &mut DeserializerState<Deser>,
) -> Result<Return>;
}
pub(crate) trait EmptyBlock {
fn no_data(&self) -> bool;
fn into_option(self) -> Option<Self>
where
Self: Sized,
{
(!self.no_data()).then_some(self)
}
}
impl EmptyBlock for crate::native::block::Block {
fn no_data(&self) -> bool { self.column_data.is_empty() && self.column_types.is_empty() }
}
impl EmptyBlock for arrow::record_batch::RecordBatch {
fn no_data(&self) -> bool { self.num_rows() == 0 && self.num_columns() == 0 }
}