mysql_common/binlog/events/
xid_event.rs
1use std::io::{self};
10
11use bytes::BufMut;
12
13use crate::{
14 binlog::{
15 consts::{BinlogVersion, EventType},
16 BinlogCtx, BinlogEvent, BinlogStruct,
17 },
18 io::ParseBuf,
19 misc::unexpected_buf_eof,
20 proto::{MyDeserialize, MySerialize},
21};
22
23#[derive(Debug, Clone, Eq, PartialEq, Hash)]
28pub struct XidEvent {
29 pub xid: u64,
30}
31
32impl<'de> MyDeserialize<'de> for XidEvent {
33 const SIZE: Option<usize> = None;
34 type Ctx = BinlogCtx<'de>;
35
36 fn deserialize(ctx: Self::Ctx, buf: &mut ParseBuf<'de>) -> io::Result<Self> {
37 let post_header_len = ctx.fde.get_event_type_header_length(Self::EVENT_TYPE);
38
39 if !buf.checked_skip(post_header_len as usize) {
40 return Err(unexpected_buf_eof());
41 }
42
43 let xid = buf.checked_eat_u64_le().ok_or_else(unexpected_buf_eof)?;
44
45 Ok(Self { xid })
46 }
47}
48
49impl MySerialize for XidEvent {
50 fn serialize(&self, buf: &mut Vec<u8>) {
51 buf.put_u64_le(self.xid);
52 }
53}
54
55impl<'a> BinlogEvent<'a> for XidEvent {
56 const EVENT_TYPE: EventType = EventType::XID_EVENT;
57}
58
59impl<'a> BinlogStruct<'a> for XidEvent {
60 fn len(&self, _version: BinlogVersion) -> usize {
61 8
62 }
63}