1// Copyright (c) 2021 Anatoly Ikorsky
2//
3// Licensed under the Apache License, Version 2.0
4// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
5// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. All files in the project carrying such notice may not be copied,
7// modified, or distributed except according to those terms.
89use std::io::{self};
1011use crate::{
12 binlog::{
13 consts::{BinlogVersion, EventType},
14 BinlogCtx, BinlogEvent, BinlogStruct,
15 },
16 io::ParseBuf,
17 misc::raw::{int::LeU64, RawInt},
18 proto::{MyDeserialize, MySerialize},
19};
2021/// Rand event.
22///
23/// Logs random seed used by the next `RAND()`, and by `PASSWORD()` in 4.1.0. 4.1.1 does not need
24/// it (it's repeatable again) so this event needn't be written in 4.1.1 for `PASSWORD()`
25/// (but the fact that it is written is just a waste, it does not cause bugs).
26///
27/// The state of the random number generation consists of 128 bits, which are stored internally
28/// as two 64-bit numbers.
29#[derive(Debug, Clone, Eq, PartialEq, Hash)]
30pub struct RandEvent {
31pub seed1: RawInt<LeU64>,
32pub seed2: RawInt<LeU64>,
33}
3435impl<'de> MyDeserialize<'de> for RandEvent {
36const SIZE: Option<usize> = Some(16);
37type Ctx = BinlogCtx<'de>;
3839fn deserialize(_: Self::Ctx, buf: &mut ParseBuf<'de>) -> io::Result<Self> {
40Ok(Self {
41 seed1: buf.parse_unchecked(())?,
42 seed2: buf.parse_unchecked(())?,
43 })
44 }
45}
4647impl MySerialize for RandEvent {
48fn serialize(&self, buf: &mut Vec<u8>) {
49self.seed1.serialize(&mut *buf);
50self.seed2.serialize(&mut *buf);
51 }
52}
5354impl<'a> BinlogEvent<'a> for RandEvent {
55const EVENT_TYPE: EventType = EventType::RAND_EVENT;
56}
5758impl<'a> BinlogStruct<'a> for RandEvent {
59fn len(&self, _version: BinlogVersion) -> usize {
608
61}
62}