use std::io;
use crate::{
binlog::{
BinlogCtx, BinlogEvent, BinlogStruct,
consts::{BinlogVersion, EventType, IntvarEventType},
},
io::ParseBuf,
misc::raw::{Const, int::*},
proto::{MyDeserialize, MySerialize},
};
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct IntvarEvent {
subtype: Const<IntvarEventType, u8>,
value: RawInt<LeU64>,
}
impl IntvarEvent {
pub fn new(subtype: IntvarEventType, value: u64) -> Self {
Self {
subtype: Const::new(subtype),
value: RawInt::new(value),
}
}
pub fn subtype(&self) -> IntvarEventType {
self.subtype.0
}
pub fn value(&self) -> u64 {
self.value.0
}
pub fn with_subtype(mut self, subtype: IntvarEventType) -> Self {
self.subtype = Const::new(subtype);
self
}
pub fn with_value(mut self, value: u64) -> Self {
self.value = RawInt::new(value);
self
}
}
impl<'de> MyDeserialize<'de> for IntvarEvent {
const SIZE: Option<usize> = Some(9);
type Ctx = BinlogCtx<'de>;
fn deserialize(_ctx: Self::Ctx, buf: &mut ParseBuf<'de>) -> io::Result<Self> {
Ok(Self {
subtype: buf.parse_unchecked(())?,
value: buf.parse_unchecked(())?,
})
}
}
impl MySerialize for IntvarEvent {
fn serialize(&self, buf: &mut Vec<u8>) {
self.subtype.serialize(&mut *buf);
self.value.serialize(&mut *buf);
}
}
impl<'a> BinlogEvent<'a> for IntvarEvent {
const EVENT_TYPE: EventType = EventType::INTVAR_EVENT;
}
impl<'a> BinlogStruct<'a> for IntvarEvent {
fn len(&self, _version: BinlogVersion) -> usize {
9
}
}