use std::ffi::CString;
use crate::command::flyweight::Flyweight;
use crate::concurrent::atomic_buffer::AtomicBuffer;
use crate::utils::bit_utils;
use crate::utils::types::{Index, I32_SIZE};
#[repr(C, packed(4))]
#[derive(Copy, Clone)]
pub(crate) struct ImageBuffersReadyDefn {
correlation_id: i64,
session_id: i32,
stream_id: i32,
subscription_registration_id: i64,
subscriber_position_id: i32,
}
pub const IMAGE_BUFFERS_READY_LENGTH: Index = std::mem::size_of::<ImageBuffersReadyDefn>() as Index;
pub(crate) struct ImageBuffersReadyFlyweight {
flyweight: Flyweight<ImageBuffersReadyDefn>,
}
impl ImageBuffersReadyFlyweight {
pub fn new(buffer: AtomicBuffer, offset: Index) -> Self {
Self {
flyweight: Flyweight::new(buffer, offset),
}
}
#[inline]
pub fn correlation_id(&self) -> i64 {
unsafe { (*self.flyweight.m_struct).correlation_id }
}
#[inline]
pub fn session_id(&self) -> i32 {
unsafe { (*self.flyweight.m_struct).session_id }
}
#[inline]
pub fn subscription_registration_id(&self) -> i64 {
unsafe { (*self.flyweight.m_struct).subscription_registration_id }
}
#[inline]
pub fn subscriber_position_id(&self) -> i32 {
unsafe { (*self.flyweight.m_struct).subscriber_position_id }
}
#[inline]
pub fn log_file_name(&self) -> CString {
self.flyweight.string_get(self.log_file_name_offset())
}
#[inline]
pub fn source_identity(&self) -> CString {
self.flyweight.string_get(self.source_identity_offset())
}
}
impl ImageBuffersReadyFlyweight {
#[inline]
const fn log_file_name_offset(&self) -> Index {
IMAGE_BUFFERS_READY_LENGTH
}
#[inline]
fn source_identity_offset(&self) -> Index {
let offset = self.log_file_name_offset();
let alignment = I32_SIZE;
let log_file_name_length = bit_utils::align(self.flyweight.string_get_length(offset), alignment);
offset + alignment + log_file_name_length
}
}