use zerocopy::big_endian::{I32 as BeI32, U16 as BeU16, U32 as BeU32};
use zerocopy::{FromBytes, Immutable, KnownLayout, Ref, Unaligned};
pub const TICK_FULL_SIZE: usize = 184;
pub const INDEX_QUOTE_SIZE: usize = 32;
pub const INST_HEADER_SIZE: usize = 64;
#[repr(C)]
#[derive(
Clone, Copy, Debug, Default, Unaligned, KnownLayout, Immutable, FromBytes,
)]
pub struct TickHeaderRaw {
pub instrument_token: BeU32, pub last_price: BeI32, pub last_traded_qty: BeU32, pub avg_traded_price: BeI32, pub volume_traded: BeU32, pub total_buy_qty: BeU32, pub total_sell_qty: BeU32, pub ohlc_be: [u8; 16], pub last_traded_ts: BeU32, pub oi: BeU32, pub oi_day_high: BeU32, pub oi_day_low: BeU32, pub exchange_ts: BeU32, }
#[repr(C)]
#[derive(
Clone, Copy, Debug, Default, Unaligned, KnownLayout, Immutable, FromBytes,
)]
pub struct DepthItemRaw {
pub qty: BeU32,
pub price: BeI32,
pub orders: BeU16,
pub _pad: BeU16, }
#[repr(C)]
#[derive(
Clone, Copy, Debug, Default, Unaligned, KnownLayout, Immutable, FromBytes,
)]
pub struct DepthRaw {
pub buy: [DepthItemRaw; 5],
pub sell: [DepthItemRaw; 5],
}
#[repr(C)]
#[derive(
Clone, Copy, Debug, Default, Unaligned, KnownLayout, Immutable, FromBytes,
)]
pub struct TickRaw {
pub header: TickHeaderRaw, pub depth: DepthRaw, }
#[inline]
pub fn as_184(slice: &[u8]) -> Option<&[u8; TICK_FULL_SIZE]> {
<&[u8; TICK_FULL_SIZE]>::try_from(slice).ok()
}
#[inline]
pub fn as_tick_raw(slice: &[u8]) -> Option<Ref<&[u8], TickRaw>> {
Ref::<_, TickRaw>::from_bytes(slice).ok()
}
#[repr(C)]
#[derive(
Clone, Copy, Debug, Default, Unaligned, KnownLayout, Immutable, FromBytes,
)]
pub struct IndexQuoteRaw32 {
pub token: BeU32, pub ltp: BeI32, pub high: BeI32, pub low: BeI32, pub open: BeI32, pub close: BeI32, pub price_change: BeI32, pub exch_ts: BeU32, }
#[inline]
pub fn as_index_quote_32(slice: &[u8]) -> Option<Ref<&[u8], IndexQuoteRaw32>> {
Ref::<_, IndexQuoteRaw32>::from_bytes(slice).ok()
}
#[repr(C)]
#[derive(
Clone, Copy, Debug, Default, Unaligned, KnownLayout, Immutable, FromBytes,
)]
pub struct InstHeaderRaw64 {
pub instrument_token: BeU32, pub ltp: BeI32, pub ltq: BeU32, pub atp: BeI32, pub vol: BeU32, pub tbq: BeU32, pub tsq: BeU32, pub open: BeI32, pub high: BeI32, pub low: BeI32, pub close: BeI32, pub last_traded_ts: BeU32, pub oi: BeU32, pub oi_day_high: BeU32, pub oi_day_low: BeU32, pub exch_ts: BeU32, }
#[inline]
pub fn as_inst_header_64(slice: &[u8]) -> Option<Ref<&[u8], InstHeaderRaw64>> {
Ref::<_, InstHeaderRaw64>::from_bytes(slice).ok()
}