pub use decoder::ExecutionRulesResponseDecoder;
pub use encoder::ExecutionRulesResponseEncoder;
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 = 104;
pub mod encoder {
use message_header_codec::*;
use super::*;
#[derive(Debug, Default)]
pub struct ExecutionRulesResponseEncoder<'a> {
buf: WriteBuf<'a>,
initial_offset: usize,
offset: usize,
limit: usize,
}
impl<'a> Writer<'a> for ExecutionRulesResponseEncoder<'a> {
#[inline]
fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
&mut self.buf
}
}
impl<'a> Encoder<'a> for ExecutionRulesResponseEncoder<'a> {
#[inline]
fn get_limit(&self) -> usize {
self.limit
}
#[inline]
fn set_limit(&mut self, limit: usize) {
self.limit = limit;
}
}
impl<'a> ExecutionRulesResponseEncoder<'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 symbol_rules_encoder(
self,
count: u32,
symbol_rules_encoder: SymbolRulesEncoder<Self>,
) -> SymbolRulesEncoder<Self> {
symbol_rules_encoder.wrap(self, count)
}
}
#[derive(Debug, Default)]
pub struct SymbolRulesEncoder<P> {
parent: Option<P>,
count: u32,
index: usize,
offset: usize,
initial_limit: usize,
}
impl<'a, P> Writer<'a> for SymbolRulesEncoder<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 SymbolRulesEncoder<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> SymbolRulesEncoder<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 {
0
}
#[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 rules_encoder(
self,
count: u32,
rules_encoder: RulesEncoder<Self>,
) -> RulesEncoder<Self> {
rules_encoder.wrap(self, count)
}
#[inline]
pub fn symbol(&mut self, value: &str) {
let limit = self.get_limit();
let data_length = value.len();
self.set_limit(limit + 1 + data_length);
self.get_buf_mut().put_u8_at(limit, data_length as u8);
self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
}
}
#[derive(Debug, Default)]
pub struct RulesEncoder<P> {
parent: Option<P>,
count: u32,
index: usize,
offset: usize,
initial_limit: usize,
}
impl<'a, P> Writer<'a> for RulesEncoder<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 RulesEncoder<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> RulesEncoder<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 {
0
}
#[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 rule(&mut self, value: &[u8]) {
let limit = self.get_limit();
let data_length = value.len();
self.set_limit(limit + 1 + data_length);
self.get_buf_mut().put_u8_at(limit, data_length as u8);
self.get_buf_mut().put_slice_at(limit + 1, value);
}
}
}
pub mod decoder {
use message_header_codec::*;
use super::*;
#[derive(Clone, Copy, Debug, Default)]
pub struct ExecutionRulesResponseDecoder<'a> {
buf: ReadBuf<'a>,
initial_offset: usize,
offset: usize,
limit: usize,
pub acting_block_length: u16,
pub acting_version: u16,
}
impl ActingVersion for ExecutionRulesResponseDecoder<'_> {
#[inline]
fn acting_version(&self) -> u16 {
self.acting_version
}
}
impl<'a> Reader<'a> for ExecutionRulesResponseDecoder<'a> {
#[inline]
fn get_buf(&self) -> &ReadBuf<'a> {
&self.buf
}
}
impl<'a> Decoder<'a> for ExecutionRulesResponseDecoder<'a> {
#[inline]
fn get_limit(&self) -> usize {
self.limit
}
#[inline]
fn set_limit(&mut self, limit: usize) {
self.limit = limit;
}
}
impl<'a> ExecutionRulesResponseDecoder<'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 symbol_rules_decoder(self) -> SymbolRulesDecoder<Self> {
SymbolRulesDecoder::default().wrap(self)
}
}
#[derive(Debug, Default)]
pub struct SymbolRulesDecoder<P> {
parent: Option<P>,
block_length: u16,
count: u32,
index: usize,
offset: usize,
}
impl<'a, P> ActingVersion for SymbolRulesDecoder<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 SymbolRulesDecoder<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 SymbolRulesDecoder<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> SymbolRulesDecoder<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 rules_decoder(self) -> RulesDecoder<Self> {
RulesDecoder::default().wrap(self)
}
#[inline]
pub fn symbol_decoder(&mut self) -> (usize, usize) {
let offset = self.parent.as_ref().expect("parent missing").get_limit();
let data_length = self.get_buf().get_u8_at(offset) as usize;
self.parent
.as_mut()
.unwrap()
.set_limit(offset + 1 + data_length);
(offset + 1, data_length)
}
#[inline]
pub fn symbol_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
self.get_buf().get_slice_at(coordinates.0, coordinates.1)
}
}
#[derive(Debug, Default)]
pub struct RulesDecoder<P> {
parent: Option<P>,
block_length: u16,
count: u32,
index: usize,
offset: usize,
}
impl<'a, P> ActingVersion for RulesDecoder<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 RulesDecoder<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 RulesDecoder<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> RulesDecoder<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 rule_decoder(&mut self) -> (usize, usize) {
let offset = self.parent.as_ref().expect("parent missing").get_limit();
let data_length = self.get_buf().get_u8_at(offset) as usize;
self.parent
.as_mut()
.unwrap()
.set_limit(offset + 1 + data_length);
(offset + 1, data_length)
}
#[inline]
pub fn rule_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
self.get_buf().get_slice_at(coordinates.0, coordinates.1)
}
}
}