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