mysql_common/binlog/events/
intvar_event.rs1use std::io;
10
11use crate::{
12 binlog::{
13 consts::{BinlogVersion, EventType, IntvarEventType},
14 BinlogCtx, BinlogEvent, BinlogStruct,
15 },
16 io::ParseBuf,
17 misc::raw::{int::*, Const},
18 proto::{MyDeserialize, MySerialize},
19};
20
21#[derive(Debug, Clone, Eq, PartialEq, Hash)]
28pub struct IntvarEvent {
29 subtype: Const<IntvarEventType, u8>,
31 value: RawInt<LeU64>,
33}
34
35impl IntvarEvent {
36 pub fn new(subtype: IntvarEventType, value: u64) -> Self {
38 Self {
39 subtype: Const::new(subtype),
40 value: RawInt::new(value),
41 }
42 }
43
44 pub fn subtype(&self) -> IntvarEventType {
48 self.subtype.0
49 }
50
51 pub fn value(&self) -> u64 {
55 self.value.0
56 }
57
58 pub fn with_subtype(mut self, subtype: IntvarEventType) -> Self {
60 self.subtype = Const::new(subtype);
61 self
62 }
63
64 pub fn with_value(mut self, value: u64) -> Self {
66 self.value = RawInt::new(value);
67 self
68 }
69}
70
71impl<'de> MyDeserialize<'de> for IntvarEvent {
72 const SIZE: Option<usize> = Some(9);
73 type Ctx = BinlogCtx<'de>;
74
75 fn deserialize(_ctx: Self::Ctx, buf: &mut ParseBuf<'de>) -> io::Result<Self> {
76 Ok(Self {
77 subtype: buf.parse_unchecked(())?,
78 value: buf.parse_unchecked(())?,
79 })
80 }
81}
82
83impl MySerialize for IntvarEvent {
84 fn serialize(&self, buf: &mut Vec<u8>) {
85 self.subtype.serialize(&mut *buf);
86 self.value.serialize(&mut *buf);
87 }
88}
89
90impl<'a> BinlogEvent<'a> for IntvarEvent {
91 const EVENT_TYPE: EventType = EventType::INTVAR_EVENT;
92}
93
94impl<'a> BinlogStruct<'a> for IntvarEvent {
95 fn len(&self, _version: BinlogVersion) -> usize {
96 9
97 }
98}