use bitvec::prelude::*;
use std::io::{self};
use crate::{
binlog::{
consts::{BinlogVersion, EventType},
BinlogCtx, BinlogEvent, BinlogStruct,
},
io::ParseBuf,
proto::{MyDeserialize, MySerialize},
};
use super::{rows_event::RowsEventCtx, RowsEvent, RowsEventRows, TableMapEvent};
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
#[repr(transparent)]
pub struct WriteRowsEvent<'a>(RowsEvent<'a>);
impl<'a> WriteRowsEvent<'a> {
pub fn table_id(&self) -> u64 {
self.0.table_id()
}
pub fn num_columns(&self) -> u64 {
self.0.num_columns()
}
pub fn columns_after_image(&'a self) -> &'a BitSlice<u8> {
self.0.columns_after_image().expect("must be here")
}
pub fn rows_data(&'a self) -> &'a [u8] {
self.0.rows_data()
}
pub fn rows(&'a self, table_map_event: &'a TableMapEvent<'a>) -> RowsEventRows<'a> {
RowsEventRows::new(&self.0, table_map_event, ParseBuf(self.rows_data()))
}
pub fn into_owned(self) -> WriteRowsEvent<'static> {
WriteRowsEvent(self.0.into_owned())
}
}
impl<'de> MyDeserialize<'de> for WriteRowsEvent<'de> {
const SIZE: Option<usize> = RowsEvent::SIZE;
type Ctx = BinlogCtx<'de>;
fn deserialize(ctx: Self::Ctx, buf: &mut ParseBuf<'de>) -> io::Result<Self> {
let ctx = RowsEventCtx {
event_type: Self::EVENT_TYPE,
binlog_ctx: ctx,
};
buf.parse(ctx).map(Self)
}
}
impl MySerialize for WriteRowsEvent<'_> {
fn serialize(&self, buf: &mut Vec<u8>) {
self.0.serialize(&mut *buf);
}
}
impl<'a> BinlogStruct<'a> for WriteRowsEvent<'a> {
fn len(&self, version: BinlogVersion) -> usize {
self.0.len(version)
}
}
impl<'a> BinlogEvent<'a> for WriteRowsEvent<'a> {
const EVENT_TYPE: EventType = EventType::WRITE_ROWS_EVENT;
}