pub use decoder::WebSocketSessionSubscriptionsResponseDecoder;
pub use encoder::WebSocketSessionSubscriptionsResponseEncoder;
use super::*;
pub use super::{SBE_SCHEMA_ID, SBE_SCHEMA_VERSION, SBE_SEMANTIC_VERSION};
pub const SBE_BLOCK_LENGTH: u16 = 0;
pub const SBE_TEMPLATE_ID: u16 = 54;
pub mod encoder {
use message_header_codec::*;
use super::*;
#[derive(Debug, Default)]
pub struct WebSocketSessionSubscriptionsResponseEncoder<'a> {
buf: WriteBuf<'a>,
initial_offset: usize,
offset: usize,
limit: usize,
}
impl<'a> Writer<'a> for WebSocketSessionSubscriptionsResponseEncoder<'a> {
#[inline]
fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
&mut self.buf
}
}
impl<'a> Encoder<'a> for WebSocketSessionSubscriptionsResponseEncoder<'a> {
#[inline]
fn get_limit(&self) -> usize {
self.limit
}
#[inline]
fn set_limit(&mut self, limit: usize) {
self.limit = limit;
}
}
impl<'a> WebSocketSessionSubscriptionsResponseEncoder<'a> {
pub fn wrap(mut self, buf: WriteBuf<'a>, offset: usize) -> Self {
let limit = offset + SBE_BLOCK_LENGTH as usize;
self.buf = buf;
self.initial_offset = offset;
self.offset = offset;
self.limit = limit;
self
}
#[inline]
pub fn encoded_length(&self) -> usize {
self.limit - self.offset
}
pub fn header(self, offset: usize) -> MessageHeaderEncoder<Self> {
let mut header = MessageHeaderEncoder::default().wrap(self, offset);
header.block_length(SBE_BLOCK_LENGTH);
header.template_id(SBE_TEMPLATE_ID);
header.schema_id(SBE_SCHEMA_ID);
header.version(SBE_SCHEMA_VERSION);
header
}
#[inline]
pub fn subscriptions_encoder(
self,
count: u32,
subscriptions_encoder: SubscriptionsEncoder<Self>,
) -> SubscriptionsEncoder<Self> {
subscriptions_encoder.wrap(self, count)
}
}
#[derive(Debug, Default)]
pub struct SubscriptionsEncoder<P> {
parent: Option<P>,
count: u32,
index: usize,
offset: usize,
initial_limit: usize,
}
impl<'a, P> Writer<'a> for SubscriptionsEncoder<P>
where
P: Writer<'a> + Default,
{
#[inline]
fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
if let Some(parent) = self.parent.as_mut() {
parent.get_buf_mut()
} else {
panic!("parent was None")
}
}
}
impl<'a, P> Encoder<'a> for SubscriptionsEncoder<P>
where
P: Encoder<'a> + Default,
{
#[inline]
fn get_limit(&self) -> usize {
self.parent.as_ref().expect("parent missing").get_limit()
}
#[inline]
fn set_limit(&mut self, limit: usize) {
self.parent
.as_mut()
.expect("parent missing")
.set_limit(limit);
}
}
impl<'a, P> SubscriptionsEncoder<P>
where
P: Encoder<'a> + Default,
{
#[inline]
pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
let initial_limit = parent.get_limit();
parent.set_limit(initial_limit + 6);
parent
.get_buf_mut()
.put_u16_at(initial_limit, Self::block_length());
parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
self.parent = Some(parent);
self.count = count;
self.index = usize::MAX;
self.offset = usize::MAX;
self.initial_limit = initial_limit;
self
}
#[inline]
pub fn block_length() -> u16 {
10
}
#[inline]
pub fn parent(&mut self) -> SbeResult<P> {
self.parent.take().ok_or(SbeErr::ParentNotSet)
}
#[inline]
pub fn advance(&mut self) -> SbeResult<Option<usize>> {
let index = self.index.wrapping_add(1);
if index >= self.count as usize {
return Ok(None);
}
if let Some(parent) = self.parent.as_mut() {
self.offset = parent.get_limit();
parent.set_limit(self.offset + Self::block_length() as usize);
self.index = index;
Ok(Some(index))
} else {
Err(SbeErr::ParentNotSet)
}
}
#[inline]
pub fn subscription_id(&mut self, value: u16) {
let offset = self.offset;
self.get_buf_mut().put_u16_at(offset, value);
}
#[inline]
pub fn expiration_time(&mut self, value: i64) {
let offset = self.offset + 2;
self.get_buf_mut().put_i64_at(offset, value);
}
}
}
pub mod decoder {
use message_header_codec::*;
use super::*;
#[derive(Clone, Copy, Debug, Default)]
pub struct WebSocketSessionSubscriptionsResponseDecoder<'a> {
buf: ReadBuf<'a>,
initial_offset: usize,
offset: usize,
limit: usize,
pub acting_block_length: u16,
pub acting_version: u16,
}
impl ActingVersion for WebSocketSessionSubscriptionsResponseDecoder<'_> {
#[inline]
fn acting_version(&self) -> u16 {
self.acting_version
}
}
impl<'a> Reader<'a> for WebSocketSessionSubscriptionsResponseDecoder<'a> {
#[inline]
fn get_buf(&self) -> &ReadBuf<'a> {
&self.buf
}
}
impl<'a> Decoder<'a> for WebSocketSessionSubscriptionsResponseDecoder<'a> {
#[inline]
fn get_limit(&self) -> usize {
self.limit
}
#[inline]
fn set_limit(&mut self, limit: usize) {
self.limit = limit;
}
}
impl<'a> WebSocketSessionSubscriptionsResponseDecoder<'a> {
pub fn wrap(
mut self,
buf: ReadBuf<'a>,
offset: usize,
acting_block_length: u16,
acting_version: u16,
) -> Self {
let limit = offset + acting_block_length as usize;
self.buf = buf;
self.initial_offset = offset;
self.offset = offset;
self.limit = limit;
self.acting_block_length = acting_block_length;
self.acting_version = acting_version;
self
}
#[inline]
pub fn encoded_length(&self) -> usize {
self.limit - self.offset
}
pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
let acting_block_length = header.block_length();
let acting_version = header.version();
self.wrap(
header.parent().unwrap(),
offset + message_header_codec::ENCODED_LENGTH,
acting_block_length,
acting_version,
)
}
#[inline]
pub fn subscriptions_decoder(self) -> SubscriptionsDecoder<Self> {
SubscriptionsDecoder::default().wrap(self)
}
}
#[derive(Debug, Default)]
pub struct SubscriptionsDecoder<P> {
parent: Option<P>,
block_length: u16,
count: u32,
index: usize,
offset: usize,
}
impl<'a, P> ActingVersion for SubscriptionsDecoder<P>
where
P: Reader<'a> + ActingVersion + Default,
{
#[inline]
fn acting_version(&self) -> u16 {
self.parent.as_ref().unwrap().acting_version()
}
}
impl<'a, P> Reader<'a> for SubscriptionsDecoder<P>
where
P: Reader<'a> + Default,
{
#[inline]
fn get_buf(&self) -> &ReadBuf<'a> {
self.parent.as_ref().expect("parent missing").get_buf()
}
}
impl<'a, P> Decoder<'a> for SubscriptionsDecoder<P>
where
P: Decoder<'a> + ActingVersion + Default,
{
#[inline]
fn get_limit(&self) -> usize {
self.parent.as_ref().expect("parent missing").get_limit()
}
#[inline]
fn set_limit(&mut self, limit: usize) {
self.parent
.as_mut()
.expect("parent missing")
.set_limit(limit);
}
}
impl<'a, P> SubscriptionsDecoder<P>
where
P: Decoder<'a> + ActingVersion + Default,
{
pub fn wrap(mut self, mut parent: P) -> Self {
let initial_offset = parent.get_limit();
let block_length = parent.get_buf().get_u16_at(initial_offset);
let count = parent.get_buf().get_u32_at(initial_offset + 2);
parent.set_limit(initial_offset + 6);
self.parent = Some(parent);
self.block_length = block_length;
self.count = count;
self.index = usize::MAX;
self.offset = 0;
self
}
#[inline]
pub fn parent(&mut self) -> SbeResult<P> {
self.parent.take().ok_or(SbeErr::ParentNotSet)
}
#[inline]
pub fn acting_version(&mut self) -> u16 {
self.parent.as_ref().unwrap().acting_version()
}
#[inline]
pub fn count(&self) -> u32 {
self.count
}
pub fn advance(&mut self) -> SbeResult<Option<usize>> {
let index = self.index.wrapping_add(1);
if index >= self.count as usize {
return Ok(None);
}
if let Some(parent) = self.parent.as_mut() {
self.offset = parent.get_limit();
parent.set_limit(self.offset + self.block_length as usize);
self.index = index;
Ok(Some(index))
} else {
Err(SbeErr::ParentNotSet)
}
}
#[inline]
pub fn subscription_id(&self) -> u16 {
self.get_buf().get_u16_at(self.offset)
}
#[inline]
pub fn expiration_time(&self) -> Option<i64> {
let value = self.get_buf().get_i64_at(self.offset + 2);
if value == -9223372036854775808_i64 {
None
} else {
Some(value)
}
}
}
}