Skip to main content

nautilus_binance/spot/sbe/generated/
ticker_24_hf_ull_response_codec.rs

1pub use decoder::Ticker24hFullResponseDecoder;
2pub use encoder::Ticker24hFullResponseEncoder;
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 = 206;
9
10pub mod encoder {
11    use message_header_codec::*;
12
13    use super::*;
14
15    #[derive(Debug, Default)]
16    pub struct Ticker24hFullResponseEncoder<'a> {
17        buf: WriteBuf<'a>,
18        initial_offset: usize,
19        offset: usize,
20        limit: usize,
21    }
22
23    impl<'a> Writer<'a> for Ticker24hFullResponseEncoder<'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 Ticker24hFullResponseEncoder<'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> Ticker24hFullResponseEncoder<'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 tickers_encoder(
69            self,
70            count: u32,
71            tickers_encoder: TickersEncoder<Self>,
72        ) -> TickersEncoder<Self> {
73            tickers_encoder.wrap(self, count)
74        }
75    }
76
77    #[derive(Debug, Default)]
78    pub struct TickersEncoder<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 TickersEncoder<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 TickersEncoder<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> TickersEncoder<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            182
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 'priceChange'
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 price_change(&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 'priceChangePercent'
212        /// - min value: -3.4028234663852886E38
213        /// - max value: 3.4028234663852886E38
214        /// - null value: f32::NAN
215        /// - characterEncoding: null
216        /// - semanticType: null
217        /// - encodedOffset: 10
218        /// - encodedLength: 4
219        /// - version: 0
220        #[inline]
221        pub fn price_change_percent(&mut self, value: f32) {
222            let offset = self.offset + 10;
223            self.get_buf_mut().put_f32_at(offset, value);
224        }
225
226        /// primitive field 'weightedAvgPrice'
227        /// - min value: -9223372036854775807
228        /// - max value: 9223372036854775807
229        /// - null value: -9223372036854775808_i64
230        /// - characterEncoding: null
231        /// - semanticType: null
232        /// - encodedOffset: 14
233        /// - encodedLength: 8
234        /// - version: 0
235        #[inline]
236        pub fn weighted_avg_price(&mut self, value: i64) {
237            let offset = self.offset + 14;
238            self.get_buf_mut().put_i64_at(offset, value);
239        }
240
241        /// primitive field 'prevClosePrice'
242        /// - min value: -9223372036854775807
243        /// - max value: 9223372036854775807
244        /// - null value: -9223372036854775808_i64
245        /// - characterEncoding: null
246        /// - semanticType: null
247        /// - encodedOffset: 22
248        /// - encodedLength: 8
249        /// - version: 0
250        #[inline]
251        pub fn prev_close_price(&mut self, value: i64) {
252            let offset = self.offset + 22;
253            self.get_buf_mut().put_i64_at(offset, value);
254        }
255
256        /// primitive field 'lastPrice'
257        /// - min value: -9223372036854775807
258        /// - max value: 9223372036854775807
259        /// - null value: -9223372036854775808_i64
260        /// - characterEncoding: null
261        /// - semanticType: null
262        /// - encodedOffset: 30
263        /// - encodedLength: 8
264        /// - version: 0
265        #[inline]
266        pub fn last_price(&mut self, value: i64) {
267            let offset = self.offset + 30;
268            self.get_buf_mut().put_i64_at(offset, value);
269        }
270
271        #[inline]
272        pub fn last_qty_at(&mut self, index: usize, value: u8) {
273            let offset = self.offset + 38;
274            let buf = self.get_buf_mut();
275            buf.put_u8_at(offset + index, value);
276        }
277
278        /// primitive array field 'lastQty'
279        /// - min value: 0
280        /// - max value: 254
281        /// - null value: 0xff_u8
282        /// - characterEncoding: null
283        /// - semanticType: null
284        /// - encodedOffset: 38
285        /// - encodedLength: 16
286        /// - version: 0
287        #[inline]
288        pub fn last_qty(&mut self, value: &[u8]) {
289            debug_assert_eq!(16, value.len());
290            let offset = self.offset + 38;
291            let buf = self.get_buf_mut();
292            buf.put_slice_at(offset, value);
293        }
294
295        /// primitive array field 'lastQty' from an Iterator
296        /// - min value: 0
297        /// - max value: 254
298        /// - null value: 0xff_u8
299        /// - characterEncoding: null
300        /// - semanticType: null
301        /// - encodedOffset: 38
302        /// - encodedLength: 16
303        /// - version: 0
304        #[inline]
305        pub fn last_qty_from_iter(&mut self, iter: impl Iterator<Item = u8>) {
306            let offset = self.offset + 38;
307            let buf = self.get_buf_mut();
308            for (i, v) in iter.enumerate() {
309                buf.put_u8_at(offset + i, v);
310            }
311        }
312
313        /// primitive array field 'lastQty' with zero padding
314        /// - min value: 0
315        /// - max value: 254
316        /// - null value: 0xff_u8
317        /// - characterEncoding: null
318        /// - semanticType: null
319        /// - encodedOffset: 38
320        /// - encodedLength: 16
321        /// - version: 0
322        #[inline]
323        pub fn last_qty_zero_padded(&mut self, value: &[u8]) {
324            let iter = value
325                .iter()
326                .copied()
327                .chain(std::iter::repeat(0_u8))
328                .take(16);
329            self.last_qty_from_iter(iter);
330        }
331
332        /// primitive field 'bidPrice'
333        /// - min value: -9223372036854775807
334        /// - max value: 9223372036854775807
335        /// - null value: -9223372036854775808_i64
336        /// - characterEncoding: null
337        /// - semanticType: null
338        /// - encodedOffset: 54
339        /// - encodedLength: 8
340        /// - version: 0
341        #[inline]
342        pub fn bid_price(&mut self, value: i64) {
343            let offset = self.offset + 54;
344            self.get_buf_mut().put_i64_at(offset, value);
345        }
346
347        /// primitive field 'bidQty'
348        /// - min value: -9223372036854775807
349        /// - max value: 9223372036854775807
350        /// - null value: -9223372036854775808_i64
351        /// - characterEncoding: null
352        /// - semanticType: null
353        /// - encodedOffset: 62
354        /// - encodedLength: 8
355        /// - version: 0
356        #[inline]
357        pub fn bid_qty(&mut self, value: i64) {
358            let offset = self.offset + 62;
359            self.get_buf_mut().put_i64_at(offset, value);
360        }
361
362        /// primitive field 'askPrice'
363        /// - min value: -9223372036854775807
364        /// - max value: 9223372036854775807
365        /// - null value: -9223372036854775808_i64
366        /// - characterEncoding: null
367        /// - semanticType: null
368        /// - encodedOffset: 70
369        /// - encodedLength: 8
370        /// - version: 0
371        #[inline]
372        pub fn ask_price(&mut self, value: i64) {
373            let offset = self.offset + 70;
374            self.get_buf_mut().put_i64_at(offset, value);
375        }
376
377        /// primitive field 'askQty'
378        /// - min value: -9223372036854775807
379        /// - max value: 9223372036854775807
380        /// - null value: -9223372036854775808_i64
381        /// - characterEncoding: null
382        /// - semanticType: null
383        /// - encodedOffset: 78
384        /// - encodedLength: 8
385        /// - version: 0
386        #[inline]
387        pub fn ask_qty(&mut self, value: i64) {
388            let offset = self.offset + 78;
389            self.get_buf_mut().put_i64_at(offset, value);
390        }
391
392        /// primitive field 'openPrice'
393        /// - min value: -9223372036854775807
394        /// - max value: 9223372036854775807
395        /// - null value: -9223372036854775808_i64
396        /// - characterEncoding: null
397        /// - semanticType: null
398        /// - encodedOffset: 86
399        /// - encodedLength: 8
400        /// - version: 0
401        #[inline]
402        pub fn open_price(&mut self, value: i64) {
403            let offset = self.offset + 86;
404            self.get_buf_mut().put_i64_at(offset, value);
405        }
406
407        /// primitive field 'highPrice'
408        /// - min value: -9223372036854775807
409        /// - max value: 9223372036854775807
410        /// - null value: -9223372036854775808_i64
411        /// - characterEncoding: null
412        /// - semanticType: null
413        /// - encodedOffset: 94
414        /// - encodedLength: 8
415        /// - version: 0
416        #[inline]
417        pub fn high_price(&mut self, value: i64) {
418            let offset = self.offset + 94;
419            self.get_buf_mut().put_i64_at(offset, value);
420        }
421
422        /// primitive field 'lowPrice'
423        /// - min value: -9223372036854775807
424        /// - max value: 9223372036854775807
425        /// - null value: -9223372036854775808_i64
426        /// - characterEncoding: null
427        /// - semanticType: null
428        /// - encodedOffset: 102
429        /// - encodedLength: 8
430        /// - version: 0
431        #[inline]
432        pub fn low_price(&mut self, value: i64) {
433            let offset = self.offset + 102;
434            self.get_buf_mut().put_i64_at(offset, value);
435        }
436
437        #[inline]
438        pub fn volume_at(&mut self, index: usize, value: u8) {
439            let offset = self.offset + 110;
440            let buf = self.get_buf_mut();
441            buf.put_u8_at(offset + index, value);
442        }
443
444        /// primitive array field 'volume'
445        /// - min value: 0
446        /// - max value: 254
447        /// - null value: 0xff_u8
448        /// - characterEncoding: null
449        /// - semanticType: null
450        /// - encodedOffset: 110
451        /// - encodedLength: 16
452        /// - version: 0
453        #[inline]
454        pub fn volume(&mut self, value: &[u8]) {
455            debug_assert_eq!(16, value.len());
456            let offset = self.offset + 110;
457            let buf = self.get_buf_mut();
458            buf.put_slice_at(offset, value);
459        }
460
461        /// primitive array field 'volume' from an Iterator
462        /// - min value: 0
463        /// - max value: 254
464        /// - null value: 0xff_u8
465        /// - characterEncoding: null
466        /// - semanticType: null
467        /// - encodedOffset: 110
468        /// - encodedLength: 16
469        /// - version: 0
470        #[inline]
471        pub fn volume_from_iter(&mut self, iter: impl Iterator<Item = u8>) {
472            let offset = self.offset + 110;
473            let buf = self.get_buf_mut();
474            for (i, v) in iter.enumerate() {
475                buf.put_u8_at(offset + i, v);
476            }
477        }
478
479        /// primitive array field 'volume' with zero padding
480        /// - min value: 0
481        /// - max value: 254
482        /// - null value: 0xff_u8
483        /// - characterEncoding: null
484        /// - semanticType: null
485        /// - encodedOffset: 110
486        /// - encodedLength: 16
487        /// - version: 0
488        #[inline]
489        pub fn volume_zero_padded(&mut self, value: &[u8]) {
490            let iter = value
491                .iter()
492                .copied()
493                .chain(std::iter::repeat(0_u8))
494                .take(16);
495            self.volume_from_iter(iter);
496        }
497
498        #[inline]
499        pub fn quote_volume_at(&mut self, index: usize, value: u8) {
500            let offset = self.offset + 126;
501            let buf = self.get_buf_mut();
502            buf.put_u8_at(offset + index, value);
503        }
504
505        /// primitive array field 'quoteVolume'
506        /// - min value: 0
507        /// - max value: 254
508        /// - null value: 0xff_u8
509        /// - characterEncoding: null
510        /// - semanticType: null
511        /// - encodedOffset: 126
512        /// - encodedLength: 16
513        /// - version: 0
514        #[inline]
515        pub fn quote_volume(&mut self, value: &[u8]) {
516            debug_assert_eq!(16, value.len());
517            let offset = self.offset + 126;
518            let buf = self.get_buf_mut();
519            buf.put_slice_at(offset, value);
520        }
521
522        /// primitive array field 'quoteVolume' from an Iterator
523        /// - min value: 0
524        /// - max value: 254
525        /// - null value: 0xff_u8
526        /// - characterEncoding: null
527        /// - semanticType: null
528        /// - encodedOffset: 126
529        /// - encodedLength: 16
530        /// - version: 0
531        #[inline]
532        pub fn quote_volume_from_iter(&mut self, iter: impl Iterator<Item = u8>) {
533            let offset = self.offset + 126;
534            let buf = self.get_buf_mut();
535            for (i, v) in iter.enumerate() {
536                buf.put_u8_at(offset + i, v);
537            }
538        }
539
540        /// primitive array field 'quoteVolume' with zero padding
541        /// - min value: 0
542        /// - max value: 254
543        /// - null value: 0xff_u8
544        /// - characterEncoding: null
545        /// - semanticType: null
546        /// - encodedOffset: 126
547        /// - encodedLength: 16
548        /// - version: 0
549        #[inline]
550        pub fn quote_volume_zero_padded(&mut self, value: &[u8]) {
551            let iter = value
552                .iter()
553                .copied()
554                .chain(std::iter::repeat(0_u8))
555                .take(16);
556            self.quote_volume_from_iter(iter);
557        }
558
559        /// primitive field 'openTime'
560        /// - min value: -9223372036854775807
561        /// - max value: 9223372036854775807
562        /// - null value: -9223372036854775808_i64
563        /// - characterEncoding: null
564        /// - semanticType: null
565        /// - encodedOffset: 142
566        /// - encodedLength: 8
567        /// - version: 0
568        #[inline]
569        pub fn open_time(&mut self, value: i64) {
570            let offset = self.offset + 142;
571            self.get_buf_mut().put_i64_at(offset, value);
572        }
573
574        /// primitive field 'closeTime'
575        /// - min value: -9223372036854775807
576        /// - max value: 9223372036854775807
577        /// - null value: -9223372036854775808_i64
578        /// - characterEncoding: null
579        /// - semanticType: null
580        /// - encodedOffset: 150
581        /// - encodedLength: 8
582        /// - version: 0
583        #[inline]
584        pub fn close_time(&mut self, value: i64) {
585            let offset = self.offset + 150;
586            self.get_buf_mut().put_i64_at(offset, value);
587        }
588
589        /// primitive field 'firstId'
590        /// - min value: -9223372036854775807
591        /// - max value: 9223372036854775807
592        /// - null value: -9223372036854775808_i64
593        /// - characterEncoding: null
594        /// - semanticType: null
595        /// - encodedOffset: 158
596        /// - encodedLength: 8
597        /// - version: 0
598        #[inline]
599        pub fn first_id(&mut self, value: i64) {
600            let offset = self.offset + 158;
601            self.get_buf_mut().put_i64_at(offset, value);
602        }
603
604        /// primitive field 'lastId'
605        /// - min value: -9223372036854775807
606        /// - max value: 9223372036854775807
607        /// - null value: -9223372036854775808_i64
608        /// - characterEncoding: null
609        /// - semanticType: null
610        /// - encodedOffset: 166
611        /// - encodedLength: 8
612        /// - version: 0
613        #[inline]
614        pub fn last_id(&mut self, value: i64) {
615            let offset = self.offset + 166;
616            self.get_buf_mut().put_i64_at(offset, value);
617        }
618
619        /// primitive field 'numTrades'
620        /// - min value: -9223372036854775807
621        /// - max value: 9223372036854775807
622        /// - null value: -9223372036854775808_i64
623        /// - characterEncoding: null
624        /// - semanticType: null
625        /// - encodedOffset: 174
626        /// - encodedLength: 8
627        /// - version: 0
628        #[inline]
629        pub fn num_trades(&mut self, value: i64) {
630            let offset = self.offset + 174;
631            self.get_buf_mut().put_i64_at(offset, value);
632        }
633
634        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
635        #[inline]
636        pub fn symbol(&mut self, value: &str) {
637            let limit = self.get_limit();
638            let data_length = value.len();
639            self.set_limit(limit + 1 + data_length);
640            self.get_buf_mut().put_u8_at(limit, data_length as u8);
641            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
642        }
643    }
644} // end encoder
645
646pub mod decoder {
647    use message_header_codec::*;
648
649    use super::*;
650
651    #[derive(Clone, Copy, Debug, Default)]
652    pub struct Ticker24hFullResponseDecoder<'a> {
653        buf: ReadBuf<'a>,
654        initial_offset: usize,
655        offset: usize,
656        limit: usize,
657        pub acting_block_length: u16,
658        pub acting_version: u16,
659    }
660
661    impl ActingVersion for Ticker24hFullResponseDecoder<'_> {
662        #[inline]
663        fn acting_version(&self) -> u16 {
664            self.acting_version
665        }
666    }
667
668    impl<'a> Reader<'a> for Ticker24hFullResponseDecoder<'a> {
669        #[inline]
670        fn get_buf(&self) -> &ReadBuf<'a> {
671            &self.buf
672        }
673    }
674
675    impl<'a> Decoder<'a> for Ticker24hFullResponseDecoder<'a> {
676        #[inline]
677        fn get_limit(&self) -> usize {
678            self.limit
679        }
680
681        #[inline]
682        fn set_limit(&mut self, limit: usize) {
683            self.limit = limit;
684        }
685    }
686
687    impl<'a> Ticker24hFullResponseDecoder<'a> {
688        pub fn wrap(
689            mut self,
690            buf: ReadBuf<'a>,
691            offset: usize,
692            acting_block_length: u16,
693            acting_version: u16,
694        ) -> Self {
695            let limit = offset + acting_block_length as usize;
696            self.buf = buf;
697            self.initial_offset = offset;
698            self.offset = offset;
699            self.limit = limit;
700            self.acting_block_length = acting_block_length;
701            self.acting_version = acting_version;
702            self
703        }
704
705        #[inline]
706        pub fn encoded_length(&self) -> usize {
707            self.limit - self.offset
708        }
709
710        pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
711            debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
712            let acting_block_length = header.block_length();
713            let acting_version = header.version();
714
715            self.wrap(
716                header.parent().unwrap(),
717                offset + message_header_codec::ENCODED_LENGTH,
718                acting_block_length,
719                acting_version,
720            )
721        }
722
723        /// GROUP DECODER (id=100)
724        #[inline]
725        pub fn tickers_decoder(self) -> TickersDecoder<Self> {
726            TickersDecoder::default().wrap(self)
727        }
728    }
729
730    #[derive(Debug, Default)]
731    pub struct TickersDecoder<P> {
732        parent: Option<P>,
733        block_length: u16,
734        count: u32,
735        index: usize,
736        offset: usize,
737    }
738
739    impl<'a, P> ActingVersion for TickersDecoder<P>
740    where
741        P: Reader<'a> + ActingVersion + Default,
742    {
743        #[inline]
744        fn acting_version(&self) -> u16 {
745            self.parent.as_ref().unwrap().acting_version()
746        }
747    }
748
749    impl<'a, P> Reader<'a> for TickersDecoder<P>
750    where
751        P: Reader<'a> + Default,
752    {
753        #[inline]
754        fn get_buf(&self) -> &ReadBuf<'a> {
755            self.parent.as_ref().expect("parent missing").get_buf()
756        }
757    }
758
759    impl<'a, P> Decoder<'a> for TickersDecoder<P>
760    where
761        P: Decoder<'a> + ActingVersion + Default,
762    {
763        #[inline]
764        fn get_limit(&self) -> usize {
765            self.parent.as_ref().expect("parent missing").get_limit()
766        }
767
768        #[inline]
769        fn set_limit(&mut self, limit: usize) {
770            self.parent
771                .as_mut()
772                .expect("parent missing")
773                .set_limit(limit);
774        }
775    }
776
777    impl<'a, P> TickersDecoder<P>
778    where
779        P: Decoder<'a> + ActingVersion + Default,
780    {
781        pub fn wrap(mut self, mut parent: P) -> Self {
782            let initial_offset = parent.get_limit();
783            let block_length = parent.get_buf().get_u16_at(initial_offset);
784            let count = parent.get_buf().get_u32_at(initial_offset + 2);
785            parent.set_limit(initial_offset + 6);
786            self.parent = Some(parent);
787            self.block_length = block_length;
788            self.count = count;
789            self.index = usize::MAX;
790            self.offset = 0;
791            self
792        }
793
794        /// group token - Token{signal=BEGIN_GROUP, name='tickers', referencedName='null', description='null', packageName='null', id=100, version=0, deprecated=0, encodedLength=182, offset=0, componentTokenCount=78, 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'}}
795        #[inline]
796        pub fn parent(&mut self) -> SbeResult<P> {
797            self.parent.take().ok_or(SbeErr::ParentNotSet)
798        }
799
800        #[inline]
801        pub fn acting_version(&mut self) -> u16 {
802            self.parent.as_ref().unwrap().acting_version()
803        }
804
805        #[inline]
806        pub fn count(&self) -> u32 {
807            self.count
808        }
809
810        /// will return Some(current index) when successful otherwise None
811        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
812            let index = self.index.wrapping_add(1);
813            if index >= self.count as usize {
814                return Ok(None);
815            }
816
817            if let Some(parent) = self.parent.as_mut() {
818                self.offset = parent.get_limit();
819                parent.set_limit(self.offset + self.block_length as usize);
820                self.index = index;
821                Ok(Some(index))
822            } else {
823                Err(SbeErr::ParentNotSet)
824            }
825        }
826
827        /// primitive field - 'REQUIRED'
828        #[inline]
829        pub fn price_exponent(&self) -> i8 {
830            self.get_buf().get_i8_at(self.offset)
831        }
832
833        /// primitive field - 'REQUIRED'
834        #[inline]
835        pub fn qty_exponent(&self) -> i8 {
836            self.get_buf().get_i8_at(self.offset + 1)
837        }
838
839        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
840        #[inline]
841        pub fn price_change(&self) -> Option<i64> {
842            let value = self.get_buf().get_i64_at(self.offset + 2);
843            if value == -9223372036854775808_i64 {
844                None
845            } else {
846                Some(value)
847            }
848        }
849
850        /// primitive field - 'OPTIONAL' { null_value: 'f32::NAN' }
851        #[inline]
852        pub fn price_change_percent(&self) -> Option<f32> {
853            let value = self.get_buf().get_f32_at(self.offset + 10);
854            if value.is_nan() { None } else { Some(value) }
855        }
856
857        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
858        #[inline]
859        pub fn weighted_avg_price(&self) -> Option<i64> {
860            let value = self.get_buf().get_i64_at(self.offset + 14);
861            if value == -9223372036854775808_i64 {
862                None
863            } else {
864                Some(value)
865            }
866        }
867
868        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
869        #[inline]
870        pub fn prev_close_price(&self) -> Option<i64> {
871            let value = self.get_buf().get_i64_at(self.offset + 22);
872            if value == -9223372036854775808_i64 {
873                None
874            } else {
875                Some(value)
876            }
877        }
878
879        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
880        #[inline]
881        pub fn last_price(&self) -> Option<i64> {
882            let value = self.get_buf().get_i64_at(self.offset + 30);
883            if value == -9223372036854775808_i64 {
884                None
885            } else {
886                Some(value)
887            }
888        }
889
890        #[inline]
891        pub fn last_qty(&self) -> [u8; 16] {
892            let buf = self.get_buf();
893            ReadBuf::get_bytes_at(buf.data, self.offset + 38)
894        }
895
896        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
897        #[inline]
898        pub fn bid_price(&self) -> Option<i64> {
899            let value = self.get_buf().get_i64_at(self.offset + 54);
900            if value == -9223372036854775808_i64 {
901                None
902            } else {
903                Some(value)
904            }
905        }
906
907        /// primitive field - 'REQUIRED'
908        #[inline]
909        pub fn bid_qty(&self) -> i64 {
910            self.get_buf().get_i64_at(self.offset + 62)
911        }
912
913        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
914        #[inline]
915        pub fn ask_price(&self) -> Option<i64> {
916            let value = self.get_buf().get_i64_at(self.offset + 70);
917            if value == -9223372036854775808_i64 {
918                None
919            } else {
920                Some(value)
921            }
922        }
923
924        /// primitive field - 'REQUIRED'
925        #[inline]
926        pub fn ask_qty(&self) -> i64 {
927            self.get_buf().get_i64_at(self.offset + 78)
928        }
929
930        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
931        #[inline]
932        pub fn open_price(&self) -> Option<i64> {
933            let value = self.get_buf().get_i64_at(self.offset + 86);
934            if value == -9223372036854775808_i64 {
935                None
936            } else {
937                Some(value)
938            }
939        }
940
941        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
942        #[inline]
943        pub fn high_price(&self) -> Option<i64> {
944            let value = self.get_buf().get_i64_at(self.offset + 94);
945            if value == -9223372036854775808_i64 {
946                None
947            } else {
948                Some(value)
949            }
950        }
951
952        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
953        #[inline]
954        pub fn low_price(&self) -> Option<i64> {
955            let value = self.get_buf().get_i64_at(self.offset + 102);
956            if value == -9223372036854775808_i64 {
957                None
958            } else {
959                Some(value)
960            }
961        }
962
963        #[inline]
964        pub fn volume(&self) -> [u8; 16] {
965            let buf = self.get_buf();
966            ReadBuf::get_bytes_at(buf.data, self.offset + 110)
967        }
968
969        #[inline]
970        pub fn quote_volume(&self) -> [u8; 16] {
971            let buf = self.get_buf();
972            ReadBuf::get_bytes_at(buf.data, self.offset + 126)
973        }
974
975        /// primitive field - 'REQUIRED'
976        #[inline]
977        pub fn open_time(&self) -> i64 {
978            self.get_buf().get_i64_at(self.offset + 142)
979        }
980
981        /// primitive field - 'REQUIRED'
982        #[inline]
983        pub fn close_time(&self) -> i64 {
984            self.get_buf().get_i64_at(self.offset + 150)
985        }
986
987        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
988        #[inline]
989        pub fn first_id(&self) -> Option<i64> {
990            let value = self.get_buf().get_i64_at(self.offset + 158);
991            if value == -9223372036854775808_i64 {
992                None
993            } else {
994                Some(value)
995            }
996        }
997
998        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
999        #[inline]
1000        pub fn last_id(&self) -> Option<i64> {
1001            let value = self.get_buf().get_i64_at(self.offset + 166);
1002            if value == -9223372036854775808_i64 {
1003                None
1004            } else {
1005                Some(value)
1006            }
1007        }
1008
1009        /// primitive field - 'REQUIRED'
1010        #[inline]
1011        pub fn num_trades(&self) -> i64 {
1012            self.get_buf().get_i64_at(self.offset + 174)
1013        }
1014
1015        /// VAR_DATA DECODER - character encoding: 'UTF-8'
1016        #[inline]
1017        pub fn symbol_decoder(&mut self) -> (usize, usize) {
1018            let offset = self.parent.as_ref().expect("parent missing").get_limit();
1019            let data_length = self.get_buf().get_u8_at(offset) as usize;
1020            self.parent
1021                .as_mut()
1022                .unwrap()
1023                .set_limit(offset + 1 + data_length);
1024            (offset + 1, data_length)
1025        }
1026
1027        #[inline]
1028        pub fn symbol_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
1029            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
1030            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
1031        }
1032    }
1033} // end decoder