mysql_common/binlog/events/
update_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 UpdateRowsEventV1<'a>(RowsEvent<'a>);
28
29impl<'a> UpdateRowsEventV1<'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_before_image(&'a self) -> &'a BitSlice<u8> {
44 self.0.columns_before_image().expect("must be here")
45 }
46
47 pub fn columns_after_image(&'a self) -> &'a BitSlice<u8> {
51 self.0.columns_after_image().expect("must be here")
52 }
53
54 pub fn rows_data(&'a self) -> &'a [u8] {
56 self.0.rows_data()
57 }
58
59 pub fn flags(&'a self) -> RowsEventFlags {
61 self.0.flags()
62 }
63
64 pub fn flags_raw(&'a self) -> u16 {
66 self.0.flags_raw()
67 }
68
69 pub fn rows(&'a self, table_map_event: &'a TableMapEvent<'a>) -> RowsEventRows<'a> {
71 RowsEventRows::new(&self.0, table_map_event, ParseBuf(self.rows_data()))
72 }
73
74 pub fn into_owned(self) -> UpdateRowsEventV1<'static> {
75 UpdateRowsEventV1(self.0.into_owned())
76 }
77}
78
79impl<'de> MyDeserialize<'de> for UpdateRowsEventV1<'de> {
80 const SIZE: Option<usize> = RowsEvent::SIZE;
81 type Ctx = BinlogCtx<'de>;
82
83 fn deserialize(ctx: Self::Ctx, buf: &mut ParseBuf<'de>) -> io::Result<Self> {
84 let ctx = RowsEventCtx {
85 event_type: Self::EVENT_TYPE,
86 binlog_ctx: ctx,
87 };
88 buf.parse(ctx).map(Self)
89 }
90}
91
92impl MySerialize for UpdateRowsEventV1<'_> {
93 fn serialize(&self, buf: &mut Vec<u8>) {
94 self.0.serialize(&mut *buf);
95 }
96}
97
98impl<'a> BinlogStruct<'a> for UpdateRowsEventV1<'a> {
99 fn len(&self, version: BinlogVersion) -> usize {
100 self.0.len(version)
101 }
102}
103
104impl<'a> BinlogEvent<'a> for UpdateRowsEventV1<'a> {
105 const EVENT_TYPE: EventType = EventType::UPDATE_ROWS_EVENT_V1;
106}