use crate::frame::{
frame_errors::CqlRequestSerializationError,
request::{RequestOpcode, SerializableRequest},
server_event_type::{EventType, EventTypeV2},
types,
};
pub use crate::frame::frame_errors::RegisterSerializationError;
pub struct Register {
pub event_types_to_register_for: Vec<EventType>,
}
pub struct RegisterV2 {
pub event_types_to_register_for: Vec<EventTypeV2>,
}
impl SerializableRequest for Register {
const OPCODE: RequestOpcode = RequestOpcode::Register;
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError> {
let event_types_list = self
.event_types_to_register_for
.iter()
.map(|event| event.to_string())
.collect::<Vec<_>>();
types::write_string_list(&event_types_list, buf)
.map_err(RegisterSerializationError::EventTypesSerialization)?;
Ok(())
}
}
impl SerializableRequest for RegisterV2 {
const OPCODE: RequestOpcode = RequestOpcode::Register;
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), CqlRequestSerializationError> {
let event_types_list = self
.event_types_to_register_for
.iter()
.map(|event| event.to_string())
.collect::<Vec<_>>();
types::write_string_list(&event_types_list, buf)
.map_err(RegisterSerializationError::EventTypesSerialization)?;
Ok(())
}
}