Skip to main content

nautilus_binance/spot/sbe/generated/
list_status_event_codec.rs

1pub use decoder::ListStatusEventDecoder;
2pub use encoder::ListStatusEventEncoder;
3
4use super::*;
5pub use super::{SBE_SCHEMA_ID, SBE_SCHEMA_VERSION, SBE_SEMANTIC_VERSION};
6
7pub const SBE_BLOCK_LENGTH: u16 = 29;
8pub const SBE_TEMPLATE_ID: u16 = 606;
9
10pub mod encoder {
11    use message_header_codec::*;
12
13    use super::*;
14
15    #[derive(Debug, Default)]
16    pub struct ListStatusEventEncoder<'a> {
17        buf: WriteBuf<'a>,
18        initial_offset: usize,
19        offset: usize,
20        limit: usize,
21    }
22
23    impl<'a> Writer<'a> for ListStatusEventEncoder<'a> {
24        #[inline]
25        fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
26            &mut self.buf
27        }
28    }
29
30    impl<'a> Encoder<'a> for ListStatusEventEncoder<'a> {
31        #[inline]
32        fn get_limit(&self) -> usize {
33            self.limit
34        }
35
36        #[inline]
37        fn set_limit(&mut self, limit: usize) {
38            self.limit = limit;
39        }
40    }
41
42    impl<'a> ListStatusEventEncoder<'a> {
43        pub fn wrap(mut self, buf: WriteBuf<'a>, offset: usize) -> Self {
44            let limit = offset + SBE_BLOCK_LENGTH as usize;
45            self.buf = buf;
46            self.initial_offset = offset;
47            self.offset = offset;
48            self.limit = limit;
49            self
50        }
51
52        #[inline]
53        pub fn encoded_length(&self) -> usize {
54            self.limit - self.offset
55        }
56
57        pub fn header(self, offset: usize) -> MessageHeaderEncoder<Self> {
58            let mut header = MessageHeaderEncoder::default().wrap(self, offset);
59            header.block_length(SBE_BLOCK_LENGTH);
60            header.template_id(SBE_TEMPLATE_ID);
61            header.schema_id(SBE_SCHEMA_ID);
62            header.version(SBE_SCHEMA_VERSION);
63            header
64        }
65
66        /// primitive field 'eventTime'
67        /// - min value: -9223372036854775807
68        /// - max value: 9223372036854775807
69        /// - null value: -9223372036854775808_i64
70        /// - characterEncoding: null
71        /// - semanticType: null
72        /// - encodedOffset: 0
73        /// - encodedLength: 8
74        /// - version: 0
75        #[inline]
76        pub fn event_time(&mut self, value: i64) {
77            let offset = self.offset;
78            self.get_buf_mut().put_i64_at(offset, value);
79        }
80
81        /// primitive field 'transactTime'
82        /// - min value: -9223372036854775807
83        /// - max value: 9223372036854775807
84        /// - null value: -9223372036854775808_i64
85        /// - characterEncoding: null
86        /// - semanticType: null
87        /// - encodedOffset: 8
88        /// - encodedLength: 8
89        /// - version: 0
90        #[inline]
91        pub fn transact_time(&mut self, value: i64) {
92            let offset = self.offset + 8;
93            self.get_buf_mut().put_i64_at(offset, value);
94        }
95
96        /// primitive field 'orderListId'
97        /// - min value: -9223372036854775807
98        /// - max value: 9223372036854775807
99        /// - null value: -9223372036854775808_i64
100        /// - characterEncoding: null
101        /// - semanticType: null
102        /// - encodedOffset: 16
103        /// - encodedLength: 8
104        /// - version: 0
105        #[inline]
106        pub fn order_list_id(&mut self, value: i64) {
107            let offset = self.offset + 16;
108            self.get_buf_mut().put_i64_at(offset, value);
109        }
110
111        /// REQUIRED enum
112        #[inline]
113        pub fn contingency_type(&mut self, value: contingency_type::ContingencyType) {
114            let offset = self.offset + 24;
115            self.get_buf_mut().put_u8_at(offset, value as u8)
116        }
117
118        /// REQUIRED enum
119        #[inline]
120        pub fn list_status_type(&mut self, value: list_status_type::ListStatusType) {
121            let offset = self.offset + 25;
122            self.get_buf_mut().put_u8_at(offset, value as u8)
123        }
124
125        /// REQUIRED enum
126        #[inline]
127        pub fn list_order_status(&mut self, value: list_order_status::ListOrderStatus) {
128            let offset = self.offset + 26;
129            self.get_buf_mut().put_u8_at(offset, value as u8)
130        }
131
132        /// primitive field 'subscriptionId'
133        /// - min value: 0
134        /// - max value: 65534
135        /// - null value: 0xffff_u16
136        /// - characterEncoding: null
137        /// - semanticType: null
138        /// - encodedOffset: 27
139        /// - encodedLength: 2
140        /// - version: 1
141        #[inline]
142        pub fn subscription_id(&mut self, value: u16) {
143            let offset = self.offset + 27;
144            self.get_buf_mut().put_u16_at(offset, value);
145        }
146
147        /// GROUP ENCODER (id=100)
148        #[inline]
149        pub fn orders_encoder(
150            self,
151            count: u16,
152            orders_encoder: OrdersEncoder<Self>,
153        ) -> OrdersEncoder<Self> {
154            orders_encoder.wrap(self, count)
155        }
156
157        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
158        #[inline]
159        pub fn symbol(&mut self, value: &str) {
160            let limit = self.get_limit();
161            let data_length = value.len();
162            self.set_limit(limit + 1 + data_length);
163            self.get_buf_mut().put_u8_at(limit, data_length as u8);
164            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
165        }
166
167        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
168        #[inline]
169        pub fn list_client_order_id(&mut self, value: &str) {
170            let limit = self.get_limit();
171            let data_length = value.len();
172            self.set_limit(limit + 1 + data_length);
173            self.get_buf_mut().put_u8_at(limit, data_length as u8);
174            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
175        }
176
177        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
178        #[inline]
179        pub fn reject_reason(&mut self, value: &str) {
180            let limit = self.get_limit();
181            let data_length = value.len();
182            self.set_limit(limit + 1 + data_length);
183            self.get_buf_mut().put_u8_at(limit, data_length as u8);
184            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
185        }
186    }
187
188    #[derive(Debug, Default)]
189    pub struct OrdersEncoder<P> {
190        parent: Option<P>,
191        count: u16,
192        index: usize,
193        offset: usize,
194        initial_limit: usize,
195    }
196
197    impl<'a, P> Writer<'a> for OrdersEncoder<P>
198    where
199        P: Writer<'a> + Default,
200    {
201        #[inline]
202        fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
203            if let Some(parent) = self.parent.as_mut() {
204                parent.get_buf_mut()
205            } else {
206                panic!("parent was None")
207            }
208        }
209    }
210
211    impl<'a, P> Encoder<'a> for OrdersEncoder<P>
212    where
213        P: Encoder<'a> + Default,
214    {
215        #[inline]
216        fn get_limit(&self) -> usize {
217            self.parent.as_ref().expect("parent missing").get_limit()
218        }
219
220        #[inline]
221        fn set_limit(&mut self, limit: usize) {
222            self.parent
223                .as_mut()
224                .expect("parent missing")
225                .set_limit(limit);
226        }
227    }
228
229    impl<'a, P> OrdersEncoder<P>
230    where
231        P: Encoder<'a> + Default,
232    {
233        #[inline]
234        pub fn wrap(mut self, mut parent: P, count: u16) -> Self {
235            let initial_limit = parent.get_limit();
236            parent.set_limit(initial_limit + 4);
237            parent
238                .get_buf_mut()
239                .put_u16_at(initial_limit, Self::block_length());
240            parent.get_buf_mut().put_u16_at(initial_limit + 2, count);
241            self.parent = Some(parent);
242            self.count = count;
243            self.index = usize::MAX;
244            self.offset = usize::MAX;
245            self.initial_limit = initial_limit;
246            self
247        }
248
249        #[inline]
250        pub fn block_length() -> u16 {
251            8
252        }
253
254        #[inline]
255        pub fn parent(&mut self) -> SbeResult<P> {
256            self.parent.take().ok_or(SbeErr::ParentNotSet)
257        }
258
259        /// will return Some(current index) when successful otherwise None
260        #[inline]
261        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
262            let index = self.index.wrapping_add(1);
263            if index >= self.count as usize {
264                return Ok(None);
265            }
266
267            if let Some(parent) = self.parent.as_mut() {
268                self.offset = parent.get_limit();
269                parent.set_limit(self.offset + Self::block_length() as usize);
270                self.index = index;
271                Ok(Some(index))
272            } else {
273                Err(SbeErr::ParentNotSet)
274            }
275        }
276
277        /// primitive field 'orderId'
278        /// - min value: -9223372036854775807
279        /// - max value: 9223372036854775807
280        /// - null value: -9223372036854775808_i64
281        /// - characterEncoding: null
282        /// - semanticType: null
283        /// - encodedOffset: 0
284        /// - encodedLength: 8
285        /// - version: 0
286        #[inline]
287        pub fn order_id(&mut self, value: i64) {
288            let offset = self.offset;
289            self.get_buf_mut().put_i64_at(offset, value);
290        }
291
292        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
293        #[inline]
294        pub fn symbol(&mut self, value: &str) {
295            let limit = self.get_limit();
296            let data_length = value.len();
297            self.set_limit(limit + 1 + data_length);
298            self.get_buf_mut().put_u8_at(limit, data_length as u8);
299            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
300        }
301
302        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
303        #[inline]
304        pub fn client_order_id(&mut self, value: &str) {
305            let limit = self.get_limit();
306            let data_length = value.len();
307            self.set_limit(limit + 1 + data_length);
308            self.get_buf_mut().put_u8_at(limit, data_length as u8);
309            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
310        }
311    }
312} // end encoder
313
314pub mod decoder {
315    use message_header_codec::*;
316
317    use super::*;
318
319    #[derive(Clone, Copy, Debug, Default)]
320    pub struct ListStatusEventDecoder<'a> {
321        buf: ReadBuf<'a>,
322        initial_offset: usize,
323        offset: usize,
324        limit: usize,
325        pub acting_block_length: u16,
326        pub acting_version: u16,
327    }
328
329    impl ActingVersion for ListStatusEventDecoder<'_> {
330        #[inline]
331        fn acting_version(&self) -> u16 {
332            self.acting_version
333        }
334    }
335
336    impl<'a> Reader<'a> for ListStatusEventDecoder<'a> {
337        #[inline]
338        fn get_buf(&self) -> &ReadBuf<'a> {
339            &self.buf
340        }
341    }
342
343    impl<'a> Decoder<'a> for ListStatusEventDecoder<'a> {
344        #[inline]
345        fn get_limit(&self) -> usize {
346            self.limit
347        }
348
349        #[inline]
350        fn set_limit(&mut self, limit: usize) {
351            self.limit = limit;
352        }
353    }
354
355    impl<'a> ListStatusEventDecoder<'a> {
356        pub fn wrap(
357            mut self,
358            buf: ReadBuf<'a>,
359            offset: usize,
360            acting_block_length: u16,
361            acting_version: u16,
362        ) -> Self {
363            let limit = offset + acting_block_length as usize;
364            self.buf = buf;
365            self.initial_offset = offset;
366            self.offset = offset;
367            self.limit = limit;
368            self.acting_block_length = acting_block_length;
369            self.acting_version = acting_version;
370            self
371        }
372
373        #[inline]
374        pub fn encoded_length(&self) -> usize {
375            self.limit - self.offset
376        }
377
378        pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
379            debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
380            let acting_block_length = header.block_length();
381            let acting_version = header.version();
382
383            self.wrap(
384                header.parent().unwrap(),
385                offset + message_header_codec::ENCODED_LENGTH,
386                acting_block_length,
387                acting_version,
388            )
389        }
390
391        /// primitive field - 'REQUIRED'
392        #[inline]
393        pub fn event_time(&self) -> i64 {
394            self.get_buf().get_i64_at(self.offset)
395        }
396
397        /// primitive field - 'REQUIRED'
398        #[inline]
399        pub fn transact_time(&self) -> i64 {
400            self.get_buf().get_i64_at(self.offset + 8)
401        }
402
403        /// primitive field - 'REQUIRED'
404        #[inline]
405        pub fn order_list_id(&self) -> i64 {
406            self.get_buf().get_i64_at(self.offset + 16)
407        }
408
409        /// REQUIRED enum
410        #[inline]
411        pub fn contingency_type(&self) -> contingency_type::ContingencyType {
412            self.get_buf().get_u8_at(self.offset + 24).into()
413        }
414
415        /// REQUIRED enum
416        #[inline]
417        pub fn list_status_type(&self) -> list_status_type::ListStatusType {
418            self.get_buf().get_u8_at(self.offset + 25).into()
419        }
420
421        /// REQUIRED enum
422        #[inline]
423        pub fn list_order_status(&self) -> list_order_status::ListOrderStatus {
424            self.get_buf().get_u8_at(self.offset + 26).into()
425        }
426
427        /// primitive field - 'OPTIONAL' { null_value: '0xffff_u16' }
428        #[inline]
429        pub fn subscription_id(&self) -> Option<u16> {
430            if self.acting_version() < 1 {
431                return None;
432            }
433
434            let value = self.get_buf().get_u16_at(self.offset + 27);
435            if value == 0xffff_u16 {
436                None
437            } else {
438                Some(value)
439            }
440        }
441
442        /// GROUP DECODER (id=100)
443        #[inline]
444        pub fn orders_decoder(self) -> OrdersDecoder<Self> {
445            OrdersDecoder::default().wrap(self)
446        }
447
448        /// VAR_DATA DECODER - character encoding: 'UTF-8'
449        #[inline]
450        pub fn symbol_decoder(&mut self) -> (usize, usize) {
451            let offset = self.get_limit();
452            let data_length = self.get_buf().get_u8_at(offset) as usize;
453            self.set_limit(offset + 1 + data_length);
454            (offset + 1, data_length)
455        }
456
457        #[inline]
458        pub fn symbol_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
459            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
460            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
461        }
462
463        /// VAR_DATA DECODER - character encoding: 'UTF-8'
464        #[inline]
465        pub fn list_client_order_id_decoder(&mut self) -> (usize, usize) {
466            let offset = self.get_limit();
467            let data_length = self.get_buf().get_u8_at(offset) as usize;
468            self.set_limit(offset + 1 + data_length);
469            (offset + 1, data_length)
470        }
471
472        #[inline]
473        pub fn list_client_order_id_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
474            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
475            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
476        }
477
478        /// VAR_DATA DECODER - character encoding: 'UTF-8'
479        #[inline]
480        pub fn reject_reason_decoder(&mut self) -> (usize, usize) {
481            let offset = self.get_limit();
482            let data_length = self.get_buf().get_u8_at(offset) as usize;
483            self.set_limit(offset + 1 + data_length);
484            (offset + 1, data_length)
485        }
486
487        #[inline]
488        pub fn reject_reason_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
489            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
490            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
491        }
492    }
493
494    #[derive(Debug, Default)]
495    pub struct OrdersDecoder<P> {
496        parent: Option<P>,
497        block_length: u16,
498        count: u16,
499        index: usize,
500        offset: usize,
501    }
502
503    impl<'a, P> ActingVersion for OrdersDecoder<P>
504    where
505        P: Reader<'a> + ActingVersion + Default,
506    {
507        #[inline]
508        fn acting_version(&self) -> u16 {
509            self.parent.as_ref().unwrap().acting_version()
510        }
511    }
512
513    impl<'a, P> Reader<'a> for OrdersDecoder<P>
514    where
515        P: Reader<'a> + Default,
516    {
517        #[inline]
518        fn get_buf(&self) -> &ReadBuf<'a> {
519            self.parent.as_ref().expect("parent missing").get_buf()
520        }
521    }
522
523    impl<'a, P> Decoder<'a> for OrdersDecoder<P>
524    where
525        P: Decoder<'a> + ActingVersion + Default,
526    {
527        #[inline]
528        fn get_limit(&self) -> usize {
529            self.parent.as_ref().expect("parent missing").get_limit()
530        }
531
532        #[inline]
533        fn set_limit(&mut self, limit: usize) {
534            self.parent
535                .as_mut()
536                .expect("parent missing")
537                .set_limit(limit);
538        }
539    }
540
541    impl<'a, P> OrdersDecoder<P>
542    where
543        P: Decoder<'a> + ActingVersion + Default,
544    {
545        pub fn wrap(mut self, mut parent: P) -> Self {
546            let initial_offset = parent.get_limit();
547            let block_length = parent.get_buf().get_u16_at(initial_offset);
548            let count = parent.get_buf().get_u16_at(initial_offset + 2);
549            parent.set_limit(initial_offset + 4);
550            self.parent = Some(parent);
551            self.block_length = block_length;
552            self.count = count;
553            self.index = usize::MAX;
554            self.offset = 0;
555            self
556        }
557
558        /// group token - Token{signal=BEGIN_GROUP, name='orders', referencedName='null', description='null', packageName='null', id=100, version=0, deprecated=0, encodedLength=8, offset=29, componentTokenCount=21, encoding=Encoding{presence=REQUIRED, primitiveType=null, byteOrder=LITTLE_ENDIAN, minValue=null, maxValue=null, nullValue=null, constValue=null, characterEncoding='null', epoch='null', timeUnit=null, semanticType='null'}}
559        #[inline]
560        pub fn parent(&mut self) -> SbeResult<P> {
561            self.parent.take().ok_or(SbeErr::ParentNotSet)
562        }
563
564        #[inline]
565        pub fn acting_version(&mut self) -> u16 {
566            self.parent.as_ref().unwrap().acting_version()
567        }
568
569        #[inline]
570        pub fn count(&self) -> u16 {
571            self.count
572        }
573
574        /// will return Some(current index) when successful otherwise None
575        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
576            let index = self.index.wrapping_add(1);
577            if index >= self.count as usize {
578                return Ok(None);
579            }
580
581            if let Some(parent) = self.parent.as_mut() {
582                self.offset = parent.get_limit();
583                parent.set_limit(self.offset + self.block_length as usize);
584                self.index = index;
585                Ok(Some(index))
586            } else {
587                Err(SbeErr::ParentNotSet)
588            }
589        }
590
591        /// primitive field - 'REQUIRED'
592        #[inline]
593        pub fn order_id(&self) -> i64 {
594            self.get_buf().get_i64_at(self.offset)
595        }
596
597        /// VAR_DATA DECODER - character encoding: 'UTF-8'
598        #[inline]
599        pub fn symbol_decoder(&mut self) -> (usize, usize) {
600            let offset = self.parent.as_ref().expect("parent missing").get_limit();
601            let data_length = self.get_buf().get_u8_at(offset) as usize;
602            self.parent
603                .as_mut()
604                .unwrap()
605                .set_limit(offset + 1 + data_length);
606            (offset + 1, data_length)
607        }
608
609        #[inline]
610        pub fn symbol_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
611            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
612            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
613        }
614
615        /// VAR_DATA DECODER - character encoding: 'UTF-8'
616        #[inline]
617        pub fn client_order_id_decoder(&mut self) -> (usize, usize) {
618            let offset = self.parent.as_ref().expect("parent missing").get_limit();
619            let data_length = self.get_buf().get_u8_at(offset) as usize;
620            self.parent
621                .as_mut()
622                .unwrap()
623                .set_limit(offset + 1 + data_length);
624            (offset + 1, data_length)
625        }
626
627        #[inline]
628        pub fn client_order_id_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
629            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
630            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
631        }
632    }
633} // end decoder