Skip to main content

nautilus_binance/spot/sbe/generated/
account_prevented_matches_response_codec.rs

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