mysql_common/binlog/events/
update_rows_event.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)]
29#[repr(transparent)]
30pub struct UpdateRowsEvent<'a>(RowsEvent<'a>);
31
32impl<'a> UpdateRowsEvent<'a> {
33 pub fn table_id(&self) -> u64 {
35 self.0.table_id()
36 }
37
38 pub fn num_columns(&self) -> u64 {
40 self.0.num_columns()
41 }
42
43 pub fn columns_before_image(&'a self) -> &'a BitSlice<u8> {
47 self.0.columns_before_image().expect("must be here")
48 }
49
50 pub fn columns_after_image(&'a self) -> &'a BitSlice<u8> {
54 self.0.columns_after_image().expect("must be here")
55 }
56
57 pub fn rows_data(&'a self) -> &'a [u8] {
59 self.0.rows_data()
60 }
61
62 pub fn flags(&'a self) -> RowsEventFlags {
64 self.0.flags()
65 }
66
67 pub fn flags_raw(&'a self) -> u16 {
69 self.0.flags_raw()
70 }
71
72 pub fn rows(&'a self, table_map_event: &'a TableMapEvent<'a>) -> RowsEventRows<'a> {
74 RowsEventRows::new(&self.0, table_map_event, ParseBuf(self.rows_data()))
75 }
76
77 pub fn into_owned(self) -> UpdateRowsEvent<'static> {
78 UpdateRowsEvent(self.0.into_owned())
79 }
80}
81
82impl<'de> MyDeserialize<'de> for UpdateRowsEvent<'de> {
83 const SIZE: Option<usize> = RowsEvent::SIZE;
84 type Ctx = BinlogCtx<'de>;
85
86 fn deserialize(ctx: Self::Ctx, buf: &mut ParseBuf<'de>) -> io::Result<Self> {
87 let ctx = RowsEventCtx {
88 event_type: Self::EVENT_TYPE,
89 binlog_ctx: ctx,
90 };
91 buf.parse(ctx).map(Self)
92 }
93}
94
95impl MySerialize for UpdateRowsEvent<'_> {
96 fn serialize(&self, buf: &mut Vec<u8>) {
97 self.0.serialize(&mut *buf);
98 }
99}
100
101impl<'a> BinlogStruct<'a> for UpdateRowsEvent<'a> {
102 fn len(&self, version: BinlogVersion) -> usize {
103 self.0.len(version)
104 }
105}
106
107impl<'a> BinlogEvent<'a> for UpdateRowsEvent<'a> {
108 const EVENT_TYPE: EventType = EventType::UPDATE_ROWS_EVENT;
109}