mysql_common/binlog/events/
write_rows_event_v1.rs1use bitvec::prelude::*;
10
11use std::io::{self};
12
13use crate::{
14 binlog::{
15 consts::{BinlogVersion, EventType, RowsEventFlags},
16 BinlogCtx, BinlogEvent, BinlogStruct,
17 },
18 io::ParseBuf,
19 proto::{MyDeserialize, MySerialize},
20};
21
22use super::{rows_event::RowsEventCtx, RowsEvent, RowsEventRows, TableMapEvent};
23
24#[derive(Debug, Clone, Eq, PartialEq, Hash)]
26#[repr(transparent)]
27pub struct WriteRowsEventV1<'a>(RowsEvent<'a>);
28
29impl<'a> WriteRowsEventV1<'a> {
30 pub fn table_id(&self) -> u64 {
32 self.0.table_id()
33 }
34
35 pub fn num_columns(&self) -> u64 {
37 self.0.num_columns()
38 }
39
40 pub fn columns_after_image(&'a self) -> &'a BitSlice<u8> {
44 self.0.columns_after_image().expect("must be here")
45 }
46
47 pub fn rows_data(&'a self) -> &'a [u8] {
49 self.0.rows_data()
50 }
51
52 pub fn flags(&'a self) -> RowsEventFlags {
54 self.0.flags()
55 }
56
57 pub fn flags_raw(&'a self) -> u16 {
59 self.0.flags_raw()
60 }
61
62 pub fn rows(&'a self, table_map_event: &'a TableMapEvent<'a>) -> RowsEventRows<'a> {
64 RowsEventRows::new(&self.0, table_map_event, ParseBuf(self.rows_data()))
65 }
66
67 pub fn into_owned(self) -> WriteRowsEventV1<'static> {
68 WriteRowsEventV1(self.0.into_owned())
69 }
70}
71
72impl<'de> MyDeserialize<'de> for WriteRowsEventV1<'de> {
73 const SIZE: Option<usize> = RowsEvent::SIZE;
74 type Ctx = BinlogCtx<'de>;
75
76 fn deserialize(ctx: Self::Ctx, buf: &mut ParseBuf<'de>) -> io::Result<Self> {
77 let ctx = RowsEventCtx {
78 event_type: Self::EVENT_TYPE,
79 binlog_ctx: ctx,
80 };
81 buf.parse(ctx).map(Self)
82 }
83}
84
85impl MySerialize for WriteRowsEventV1<'_> {
86 fn serialize(&self, buf: &mut Vec<u8>) {
87 self.0.serialize(&mut *buf);
88 }
89}
90
91impl<'a> BinlogStruct<'a> for WriteRowsEventV1<'a> {
92 fn len(&self, version: BinlogVersion) -> usize {
93 self.0.len(version)
94 }
95}
96
97impl<'a> BinlogEvent<'a> for WriteRowsEventV1<'a> {
98 const EVENT_TYPE: EventType = EventType::WRITE_ROWS_EVENT_V1;
99}