Skip to main content

nautilus_binance/common/sbe/spot/
mod.rs

1//! Generated SBE codecs for Binance Spot API (schema 3:2).
2//!
3//! This code is auto-generated by Real Logic's SBE generator from Binance's
4//! official XML schema. Do not edit manually.
5
6#![forbid(unsafe_code)]
7#![allow(clippy::all)]
8#![allow(clippy::missing_errors_doc)]
9#![allow(clippy::missing_panics_doc)]
10#![allow(clippy::return_self_not_must_use)]
11#![allow(clippy::semicolon_if_nothing_returned)]
12#![allow(clippy::use_self)]
13#![allow(missing_docs)]
14#![allow(non_camel_case_types)]
15#![allow(ambiguous_glob_reexports)]
16#![allow(unused_imports)]
17#![allow(dead_code)]
18
19use ::core::convert::TryInto;
20
21pub mod account_commission_response_codec;
22pub mod account_order_rate_limit_response_codec;
23pub mod account_response_codec;
24pub mod account_trades_response_codec;
25pub mod account_type;
26pub mod agg_trades_response_codec;
27pub mod allowed_self_trade_prevention_modes;
28pub mod average_price_response_codec;
29pub mod balance_update_event_codec;
30pub mod book_ticker_response_codec;
31pub mod book_ticker_symbol_response_codec;
32pub mod bool_enum;
33pub mod cancel_open_orders_response_codec;
34pub mod cancel_order_list_response_codec;
35pub mod cancel_order_response_codec;
36pub mod cancel_replace_order_response_codec;
37pub mod cancel_replace_status;
38pub mod contingency_type;
39pub mod depth_response_codec;
40pub mod error_response_codec;
41pub mod exchange_info_response_codec;
42pub mod exchange_max_num_algo_orders_filter_codec;
43pub mod exchange_max_num_iceberg_orders_filter_codec;
44pub mod exchange_max_num_order_lists_filter_codec;
45pub mod exchange_max_num_orders_filter_codec;
46pub mod execution_report_event_codec;
47pub mod execution_type;
48pub mod filter_type;
49pub mod floor;
50pub mod group_size_16_encoding_codec;
51pub mod group_size_encoding_codec;
52pub mod iceberg_parts_filter_codec;
53pub mod klines_response_codec;
54pub mod list_order_status;
55pub mod list_status_event_codec;
56pub mod list_status_type;
57pub mod lot_size_filter_codec;
58pub mod market_lot_size_filter_codec;
59pub mod match_type;
60pub mod max_asset_filter_codec;
61pub mod max_num_algo_orders_filter_codec;
62pub mod max_num_iceberg_orders_filter_codec;
63pub mod max_num_order_lists_filter_codec;
64pub mod max_num_orders_filter_codec;
65pub mod max_position_filter_codec;
66pub mod message_data_16_codec;
67pub mod message_data_8_codec;
68pub mod message_data_codec;
69pub mod message_header_codec;
70pub mod min_notional_filter_codec;
71pub mod new_order_ack_response_codec;
72pub mod new_order_full_response_codec;
73pub mod new_order_list_ack_response_codec;
74pub mod new_order_list_full_response_codec;
75pub mod new_order_list_result_response_codec;
76pub mod new_order_result_response_codec;
77pub mod notional_filter_codec;
78pub mod optional_message_data_16_codec;
79pub mod optional_message_data_codec;
80pub mod optional_var_string_8_codec;
81pub mod optional_var_string_codec;
82pub mod order_capacity;
83pub mod order_list_response_codec;
84pub mod order_lists_response_codec;
85pub mod order_response_codec;
86pub mod order_side;
87pub mod order_status;
88pub mod order_test_response_codec;
89pub mod order_test_with_commissions_response_codec;
90pub mod order_type;
91pub mod order_types;
92pub mod orders_response_codec;
93pub mod outbound_account_position_event_codec;
94pub mod peg_offset_type;
95pub mod peg_price_type;
96pub mod percent_price_by_side_filter_codec;
97pub mod percent_price_filter_codec;
98pub mod ping_response_codec;
99pub mod price_filter_codec;
100pub mod price_ticker_response_codec;
101pub mod price_ticker_symbol_response_codec;
102pub mod rate_limit_interval;
103pub mod rate_limit_type;
104pub mod self_trade_prevention_mode;
105pub mod server_time_response_codec;
106pub mod symbol_status;
107pub mod ticker_24_hf_ull_response_codec;
108pub mod ticker_24_hm_ini_response_codec;
109pub mod ticker_24_hs_ymbol_full_response_codec;
110pub mod ticker_24_hs_ymbol_mini_response_codec;
111pub mod ticker_full_response_codec;
112pub mod ticker_mini_response_codec;
113pub mod ticker_symbol_full_response_codec;
114pub mod ticker_symbol_mini_response_codec;
115pub mod time_in_force;
116pub mod tp_lus_sell_filter_codec;
117pub mod trades_response_codec;
118pub mod trailing_delta_filter_codec;
119pub mod var_string_8_codec;
120pub mod var_string_codec;
121pub mod web_socket_response_codec;
122pub mod web_socket_session_logon_response_codec;
123pub mod web_socket_session_logout_response_codec;
124pub mod web_socket_session_status_response_codec;
125pub mod web_socket_session_subscriptions_response_codec;
126
127pub const SBE_SCHEMA_ID: u16 = 3;
128pub const SBE_SCHEMA_VERSION: u16 = 2;
129pub const SBE_SEMANTIC_VERSION: &str = "5.2";
130
131pub type SbeResult<T> = core::result::Result<T, SbeErr>;
132
133#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
134pub enum SbeErr {
135    ParentNotSet,
136}
137impl core::fmt::Display for SbeErr {
138    #[inline]
139    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
140        write!(f, "{self:?}")
141    }
142}
143impl std::error::Error for SbeErr {}
144
145#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
146pub enum Either<L, R> {
147    Left(L),
148    Right(R),
149}
150
151pub trait Writer<'a>: Sized {
152    fn get_buf_mut(&mut self) -> &mut WriteBuf<'a>;
153}
154
155pub trait Encoder<'a>: Writer<'a> {
156    fn get_limit(&self) -> usize;
157    fn set_limit(&mut self, limit: usize);
158}
159
160pub trait ActingVersion {
161    fn acting_version(&self) -> u16;
162}
163
164pub trait Reader<'a>: Sized {
165    fn get_buf(&self) -> &ReadBuf<'a>;
166}
167
168pub trait Decoder<'a>: Reader<'a> {
169    fn get_limit(&self) -> usize;
170    fn set_limit(&mut self, limit: usize);
171}
172
173#[derive(Clone, Copy, Debug, Default)]
174pub struct ReadBuf<'a> {
175    data: &'a [u8],
176}
177impl<'a> Reader<'a> for ReadBuf<'a> {
178    #[inline]
179    fn get_buf(&self) -> &ReadBuf<'a> {
180        self
181    }
182}
183#[allow(dead_code)]
184impl<'a> ReadBuf<'a> {
185    #[inline]
186    pub fn new(data: &'a [u8]) -> Self {
187        Self { data }
188    }
189
190    #[inline]
191    pub(crate) fn get_bytes_at<const N: usize>(slice: &[u8], index: usize) -> [u8; N] {
192        slice[index..index + N]
193            .try_into()
194            .expect("slice with incorrect length")
195    }
196
197    #[inline]
198    pub fn get_u8_at(&self, index: usize) -> u8 {
199        self.data[index]
200    }
201
202    #[inline]
203    pub fn get_i8_at(&self, index: usize) -> i8 {
204        i8::from_le_bytes(Self::get_bytes_at(self.data, index))
205    }
206
207    #[inline]
208    pub fn get_i16_at(&self, index: usize) -> i16 {
209        i16::from_le_bytes(Self::get_bytes_at(self.data, index))
210    }
211
212    #[inline]
213    pub fn get_i32_at(&self, index: usize) -> i32 {
214        i32::from_le_bytes(Self::get_bytes_at(self.data, index))
215    }
216
217    #[inline]
218    pub fn get_i64_at(&self, index: usize) -> i64 {
219        i64::from_le_bytes(Self::get_bytes_at(self.data, index))
220    }
221
222    #[inline]
223    pub fn get_u16_at(&self, index: usize) -> u16 {
224        u16::from_le_bytes(Self::get_bytes_at(self.data, index))
225    }
226
227    #[inline]
228    pub fn get_u32_at(&self, index: usize) -> u32 {
229        u32::from_le_bytes(Self::get_bytes_at(self.data, index))
230    }
231
232    #[inline]
233    pub fn get_u64_at(&self, index: usize) -> u64 {
234        u64::from_le_bytes(Self::get_bytes_at(self.data, index))
235    }
236
237    #[inline]
238    pub fn get_f32_at(&self, index: usize) -> f32 {
239        f32::from_le_bytes(Self::get_bytes_at(self.data, index))
240    }
241
242    #[inline]
243    pub fn get_f64_at(&self, index: usize) -> f64 {
244        f64::from_le_bytes(Self::get_bytes_at(self.data, index))
245    }
246
247    #[inline]
248    pub fn get_slice_at(&self, index: usize, len: usize) -> &[u8] {
249        &self.data[index..index + len]
250    }
251}
252
253#[derive(Debug, Default)]
254pub struct WriteBuf<'a> {
255    data: &'a mut [u8],
256}
257impl<'a> WriteBuf<'a> {
258    pub fn new(data: &'a mut [u8]) -> Self {
259        Self { data }
260    }
261
262    #[inline]
263    pub fn put_bytes_at<const COUNT: usize>(&mut self, index: usize, bytes: &[u8; COUNT]) -> usize {
264        self.data[index..index + COUNT].copy_from_slice(bytes);
265        COUNT
266    }
267
268    #[inline]
269    pub fn put_u8_at(&mut self, index: usize, value: u8) {
270        self.data[index] = value;
271    }
272
273    #[inline]
274    pub fn put_i8_at(&mut self, index: usize, value: i8) {
275        self.put_bytes_at(index, &i8::to_le_bytes(value));
276    }
277
278    #[inline]
279    pub fn put_i16_at(&mut self, index: usize, value: i16) {
280        self.put_bytes_at(index, &i16::to_le_bytes(value));
281    }
282
283    #[inline]
284    pub fn put_i32_at(&mut self, index: usize, value: i32) {
285        self.put_bytes_at(index, &i32::to_le_bytes(value));
286    }
287
288    #[inline]
289    pub fn put_i64_at(&mut self, index: usize, value: i64) {
290        self.put_bytes_at(index, &i64::to_le_bytes(value));
291    }
292
293    #[inline]
294    pub fn put_u16_at(&mut self, index: usize, value: u16) {
295        self.put_bytes_at(index, &u16::to_le_bytes(value));
296    }
297
298    #[inline]
299    pub fn put_u32_at(&mut self, index: usize, value: u32) {
300        self.put_bytes_at(index, &u32::to_le_bytes(value));
301    }
302
303    #[inline]
304    pub fn put_u64_at(&mut self, index: usize, value: u64) {
305        self.put_bytes_at(index, &u64::to_le_bytes(value));
306    }
307
308    #[inline]
309    pub fn put_f32_at(&mut self, index: usize, value: f32) {
310        self.put_bytes_at(index, &f32::to_le_bytes(value));
311    }
312
313    #[inline]
314    pub fn put_f64_at(&mut self, index: usize, value: f64) {
315        self.put_bytes_at(index, &f64::to_le_bytes(value));
316    }
317
318    #[inline]
319    pub fn put_slice_at(&mut self, index: usize, src: &[u8]) -> usize {
320        let len = src.len();
321        let dest = self.data.split_at_mut(index).1.split_at_mut(len).0;
322        dest.clone_from_slice(src);
323        len
324    }
325}
326impl<'a> From<&'a mut WriteBuf<'a>> for &'a mut [u8] {
327    #[inline]
328    fn from(buf: &'a mut WriteBuf<'a>) -> &'a mut [u8] {
329        buf.data
330    }
331}