use bitvec::prelude::*;
use std::io::{self};
use crate::{
binlog::{
consts::{BinlogVersion, EventType, RowsEventFlags},
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 DeleteRowsEventV1<'a>(RowsEvent<'a>);
impl<'a> DeleteRowsEventV1<'a> {
pub fn table_id(&self) -> u64 {
self.0.table_id()
}
pub fn num_columns(&self) -> u64 {
self.0.num_columns()
}
pub fn columns_before_image(&'a self) -> &'a BitSlice<u8> {
self.0.columns_before_image().expect("must be here")
}
pub fn rows_data(&'a self) -> &'a [u8] {
self.0.rows_data()
}
pub fn flags(&'a self) -> RowsEventFlags {
self.0.flags()
}
pub fn flags_raw(&'a self) -> u16 {
self.0.flags_raw()
}
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) -> DeleteRowsEventV1<'static> {
DeleteRowsEventV1(self.0.into_owned())
}
}
impl<'de> MyDeserialize<'de> for DeleteRowsEventV1<'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 DeleteRowsEventV1<'_> {
fn serialize(&self, buf: &mut Vec<u8>) {
self.0.serialize(&mut *buf);
}
}
impl<'a> BinlogStruct<'a> for DeleteRowsEventV1<'a> {
fn len(&self, version: BinlogVersion) -> usize {
self.0.len(version)
}
}
impl<'a> BinlogEvent<'a> for DeleteRowsEventV1<'a> {
const EVENT_TYPE: EventType = EventType::DELETE_ROWS_EVENT_V1;
}