nautilus_binance/common/sbe/spot/
account_response_codec.rs

1pub use decoder::AccountResponseDecoder;
2pub use encoder::AccountResponseEncoder;
3
4use super::*;
5pub use super::{SBE_SCHEMA_ID, SBE_SCHEMA_VERSION, SBE_SEMANTIC_VERSION};
6
7pub const SBE_BLOCK_LENGTH: u16 = 64;
8pub const SBE_TEMPLATE_ID: u16 = 400;
9
10pub mod encoder {
11    use message_header_codec::*;
12
13    use super::*;
14
15    #[derive(Debug, Default)]
16    pub struct AccountResponseEncoder<'a> {
17        buf: WriteBuf<'a>,
18        initial_offset: usize,
19        offset: usize,
20        limit: usize,
21    }
22
23    impl<'a> Writer<'a> for AccountResponseEncoder<'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 AccountResponseEncoder<'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> AccountResponseEncoder<'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 'commissionExponent'
67        /// - min value: -127
68        /// - max value: 127
69        /// - null value: -128_i8
70        /// - characterEncoding: null
71        /// - semanticType: null
72        /// - encodedOffset: 0
73        /// - encodedLength: 1
74        /// - version: 0
75        #[inline]
76        pub fn commission_exponent(&mut self, value: i8) {
77            let offset = self.offset;
78            self.get_buf_mut().put_i8_at(offset, value);
79        }
80
81        /// primitive field 'commissionRateMaker'
82        /// - min value: -9223372036854775807
83        /// - max value: 9223372036854775807
84        /// - null value: -9223372036854775808_i64
85        /// - characterEncoding: null
86        /// - semanticType: null
87        /// - encodedOffset: 1
88        /// - encodedLength: 8
89        /// - version: 0
90        #[inline]
91        pub fn commission_rate_maker(&mut self, value: i64) {
92            let offset = self.offset + 1;
93            self.get_buf_mut().put_i64_at(offset, value);
94        }
95
96        /// primitive field 'commissionRateTaker'
97        /// - min value: -9223372036854775807
98        /// - max value: 9223372036854775807
99        /// - null value: -9223372036854775808_i64
100        /// - characterEncoding: null
101        /// - semanticType: null
102        /// - encodedOffset: 9
103        /// - encodedLength: 8
104        /// - version: 0
105        #[inline]
106        pub fn commission_rate_taker(&mut self, value: i64) {
107            let offset = self.offset + 9;
108            self.get_buf_mut().put_i64_at(offset, value);
109        }
110
111        /// primitive field 'commissionRateBuyer'
112        /// - min value: -9223372036854775807
113        /// - max value: 9223372036854775807
114        /// - null value: -9223372036854775808_i64
115        /// - characterEncoding: null
116        /// - semanticType: null
117        /// - encodedOffset: 17
118        /// - encodedLength: 8
119        /// - version: 0
120        #[inline]
121        pub fn commission_rate_buyer(&mut self, value: i64) {
122            let offset = self.offset + 17;
123            self.get_buf_mut().put_i64_at(offset, value);
124        }
125
126        /// primitive field 'commissionRateSeller'
127        /// - min value: -9223372036854775807
128        /// - max value: 9223372036854775807
129        /// - null value: -9223372036854775808_i64
130        /// - characterEncoding: null
131        /// - semanticType: null
132        /// - encodedOffset: 25
133        /// - encodedLength: 8
134        /// - version: 0
135        #[inline]
136        pub fn commission_rate_seller(&mut self, value: i64) {
137            let offset = self.offset + 25;
138            self.get_buf_mut().put_i64_at(offset, value);
139        }
140
141        /// REQUIRED enum
142        #[inline]
143        pub fn can_trade(&mut self, value: bool_enum::BoolEnum) {
144            let offset = self.offset + 33;
145            self.get_buf_mut().put_u8_at(offset, value as u8)
146        }
147
148        /// REQUIRED enum
149        #[inline]
150        pub fn can_withdraw(&mut self, value: bool_enum::BoolEnum) {
151            let offset = self.offset + 34;
152            self.get_buf_mut().put_u8_at(offset, value as u8)
153        }
154
155        /// REQUIRED enum
156        #[inline]
157        pub fn can_deposit(&mut self, value: bool_enum::BoolEnum) {
158            let offset = self.offset + 35;
159            self.get_buf_mut().put_u8_at(offset, value as u8)
160        }
161
162        /// REQUIRED enum
163        #[inline]
164        pub fn brokered(&mut self, value: bool_enum::BoolEnum) {
165            let offset = self.offset + 36;
166            self.get_buf_mut().put_u8_at(offset, value as u8)
167        }
168
169        /// REQUIRED enum
170        #[inline]
171        pub fn require_self_trade_prevention(&mut self, value: bool_enum::BoolEnum) {
172            let offset = self.offset + 37;
173            self.get_buf_mut().put_u8_at(offset, value as u8)
174        }
175
176        /// REQUIRED enum
177        #[inline]
178        pub fn prevent_sor(&mut self, value: bool_enum::BoolEnum) {
179            let offset = self.offset + 38;
180            self.get_buf_mut().put_u8_at(offset, value as u8)
181        }
182
183        /// primitive field 'updateTime'
184        /// - min value: -9223372036854775807
185        /// - max value: 9223372036854775807
186        /// - null value: -9223372036854775808_i64
187        /// - characterEncoding: null
188        /// - semanticType: null
189        /// - encodedOffset: 39
190        /// - encodedLength: 8
191        /// - version: 0
192        #[inline]
193        pub fn update_time(&mut self, value: i64) {
194            let offset = self.offset + 39;
195            self.get_buf_mut().put_i64_at(offset, value);
196        }
197
198        /// REQUIRED enum
199        #[inline]
200        pub fn account_type(&mut self, value: account_type::AccountType) {
201            let offset = self.offset + 47;
202            self.get_buf_mut().put_u8_at(offset, value as u8)
203        }
204
205        /// primitive field 'tradeGroupId'
206        /// - min value: -9223372036854775807
207        /// - max value: 9223372036854775807
208        /// - null value: -9223372036854775808_i64
209        /// - characterEncoding: null
210        /// - semanticType: null
211        /// - encodedOffset: 48
212        /// - encodedLength: 8
213        /// - version: 0
214        #[inline]
215        pub fn trade_group_id(&mut self, value: i64) {
216            let offset = self.offset + 48;
217            self.get_buf_mut().put_i64_at(offset, value);
218        }
219
220        /// primitive field 'uid'
221        /// - min value: -9223372036854775807
222        /// - max value: 9223372036854775807
223        /// - null value: -9223372036854775808_i64
224        /// - characterEncoding: null
225        /// - semanticType: null
226        /// - encodedOffset: 56
227        /// - encodedLength: 8
228        /// - version: 0
229        #[inline]
230        pub fn uid(&mut self, value: i64) {
231            let offset = self.offset + 56;
232            self.get_buf_mut().put_i64_at(offset, value);
233        }
234
235        /// GROUP ENCODER (id=100)
236        #[inline]
237        pub fn balances_encoder(
238            self,
239            count: u32,
240            balances_encoder: BalancesEncoder<Self>,
241        ) -> BalancesEncoder<Self> {
242            balances_encoder.wrap(self, count)
243        }
244
245        /// GROUP ENCODER (id=101)
246        #[inline]
247        pub fn permissions_encoder(
248            self,
249            count: u32,
250            permissions_encoder: PermissionsEncoder<Self>,
251        ) -> PermissionsEncoder<Self> {
252            permissions_encoder.wrap(self, count)
253        }
254
255        /// GROUP ENCODER (id=102)
256        #[inline]
257        pub fn reduce_only_assets_encoder(
258            self,
259            count: u32,
260            reduce_only_assets_encoder: ReduceOnlyAssetsEncoder<Self>,
261        ) -> ReduceOnlyAssetsEncoder<Self> {
262            reduce_only_assets_encoder.wrap(self, count)
263        }
264    }
265
266    #[derive(Debug, Default)]
267    pub struct BalancesEncoder<P> {
268        parent: Option<P>,
269        count: u32,
270        index: usize,
271        offset: usize,
272        initial_limit: usize,
273    }
274
275    impl<'a, P> Writer<'a> for BalancesEncoder<P>
276    where
277        P: Writer<'a> + Default,
278    {
279        #[inline]
280        fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
281            if let Some(parent) = self.parent.as_mut() {
282                parent.get_buf_mut()
283            } else {
284                panic!("parent was None")
285            }
286        }
287    }
288
289    impl<'a, P> Encoder<'a> for BalancesEncoder<P>
290    where
291        P: Encoder<'a> + Default,
292    {
293        #[inline]
294        fn get_limit(&self) -> usize {
295            self.parent.as_ref().expect("parent missing").get_limit()
296        }
297
298        #[inline]
299        fn set_limit(&mut self, limit: usize) {
300            self.parent
301                .as_mut()
302                .expect("parent missing")
303                .set_limit(limit);
304        }
305    }
306
307    impl<'a, P> BalancesEncoder<P>
308    where
309        P: Encoder<'a> + Default,
310    {
311        #[inline]
312        pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
313            let initial_limit = parent.get_limit();
314            parent.set_limit(initial_limit + 6);
315            parent
316                .get_buf_mut()
317                .put_u16_at(initial_limit, Self::block_length());
318            parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
319            self.parent = Some(parent);
320            self.count = count;
321            self.index = usize::MAX;
322            self.offset = usize::MAX;
323            self.initial_limit = initial_limit;
324            self
325        }
326
327        #[inline]
328        pub fn block_length() -> u16 {
329            17
330        }
331
332        #[inline]
333        pub fn parent(&mut self) -> SbeResult<P> {
334            self.parent.take().ok_or(SbeErr::ParentNotSet)
335        }
336
337        /// will return Some(current index) when successful otherwise None
338        #[inline]
339        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
340            let index = self.index.wrapping_add(1);
341            if index >= self.count as usize {
342                return Ok(None);
343            }
344            if let Some(parent) = self.parent.as_mut() {
345                self.offset = parent.get_limit();
346                parent.set_limit(self.offset + Self::block_length() as usize);
347                self.index = index;
348                Ok(Some(index))
349            } else {
350                Err(SbeErr::ParentNotSet)
351            }
352        }
353
354        /// primitive field 'exponent'
355        /// - min value: -127
356        /// - max value: 127
357        /// - null value: -128_i8
358        /// - characterEncoding: null
359        /// - semanticType: null
360        /// - encodedOffset: 0
361        /// - encodedLength: 1
362        /// - version: 0
363        #[inline]
364        pub fn exponent(&mut self, value: i8) {
365            let offset = self.offset;
366            self.get_buf_mut().put_i8_at(offset, value);
367        }
368
369        /// primitive field 'free'
370        /// - min value: -9223372036854775807
371        /// - max value: 9223372036854775807
372        /// - null value: -9223372036854775808_i64
373        /// - characterEncoding: null
374        /// - semanticType: null
375        /// - encodedOffset: 1
376        /// - encodedLength: 8
377        /// - version: 0
378        #[inline]
379        pub fn free(&mut self, value: i64) {
380            let offset = self.offset + 1;
381            self.get_buf_mut().put_i64_at(offset, value);
382        }
383
384        /// primitive field 'locked'
385        /// - min value: -9223372036854775807
386        /// - max value: 9223372036854775807
387        /// - null value: -9223372036854775808_i64
388        /// - characterEncoding: null
389        /// - semanticType: null
390        /// - encodedOffset: 9
391        /// - encodedLength: 8
392        /// - version: 0
393        #[inline]
394        pub fn locked(&mut self, value: i64) {
395            let offset = self.offset + 9;
396            self.get_buf_mut().put_i64_at(offset, value);
397        }
398
399        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
400        #[inline]
401        pub fn asset(&mut self, value: &str) {
402            let limit = self.get_limit();
403            let data_length = value.len();
404            self.set_limit(limit + 1 + data_length);
405            self.get_buf_mut().put_u8_at(limit, data_length as u8);
406            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
407        }
408    }
409
410    #[derive(Debug, Default)]
411    pub struct PermissionsEncoder<P> {
412        parent: Option<P>,
413        count: u32,
414        index: usize,
415        offset: usize,
416        initial_limit: usize,
417    }
418
419    impl<'a, P> Writer<'a> for PermissionsEncoder<P>
420    where
421        P: Writer<'a> + Default,
422    {
423        #[inline]
424        fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
425            if let Some(parent) = self.parent.as_mut() {
426                parent.get_buf_mut()
427            } else {
428                panic!("parent was None")
429            }
430        }
431    }
432
433    impl<'a, P> Encoder<'a> for PermissionsEncoder<P>
434    where
435        P: Encoder<'a> + Default,
436    {
437        #[inline]
438        fn get_limit(&self) -> usize {
439            self.parent.as_ref().expect("parent missing").get_limit()
440        }
441
442        #[inline]
443        fn set_limit(&mut self, limit: usize) {
444            self.parent
445                .as_mut()
446                .expect("parent missing")
447                .set_limit(limit);
448        }
449    }
450
451    impl<'a, P> PermissionsEncoder<P>
452    where
453        P: Encoder<'a> + Default,
454    {
455        #[inline]
456        pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
457            let initial_limit = parent.get_limit();
458            parent.set_limit(initial_limit + 6);
459            parent
460                .get_buf_mut()
461                .put_u16_at(initial_limit, Self::block_length());
462            parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
463            self.parent = Some(parent);
464            self.count = count;
465            self.index = usize::MAX;
466            self.offset = usize::MAX;
467            self.initial_limit = initial_limit;
468            self
469        }
470
471        #[inline]
472        pub fn block_length() -> u16 {
473            0
474        }
475
476        #[inline]
477        pub fn parent(&mut self) -> SbeResult<P> {
478            self.parent.take().ok_or(SbeErr::ParentNotSet)
479        }
480
481        /// will return Some(current index) when successful otherwise None
482        #[inline]
483        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
484            let index = self.index.wrapping_add(1);
485            if index >= self.count as usize {
486                return Ok(None);
487            }
488            if let Some(parent) = self.parent.as_mut() {
489                self.offset = parent.get_limit();
490                parent.set_limit(self.offset + Self::block_length() as usize);
491                self.index = index;
492                Ok(Some(index))
493            } else {
494                Err(SbeErr::ParentNotSet)
495            }
496        }
497
498        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
499        #[inline]
500        pub fn permission(&mut self, value: &str) {
501            let limit = self.get_limit();
502            let data_length = value.len();
503            self.set_limit(limit + 1 + data_length);
504            self.get_buf_mut().put_u8_at(limit, data_length as u8);
505            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
506        }
507    }
508
509    #[derive(Debug, Default)]
510    pub struct ReduceOnlyAssetsEncoder<P> {
511        parent: Option<P>,
512        count: u32,
513        index: usize,
514        offset: usize,
515        initial_limit: usize,
516    }
517
518    impl<'a, P> Writer<'a> for ReduceOnlyAssetsEncoder<P>
519    where
520        P: Writer<'a> + Default,
521    {
522        #[inline]
523        fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
524            if let Some(parent) = self.parent.as_mut() {
525                parent.get_buf_mut()
526            } else {
527                panic!("parent was None")
528            }
529        }
530    }
531
532    impl<'a, P> Encoder<'a> for ReduceOnlyAssetsEncoder<P>
533    where
534        P: Encoder<'a> + Default,
535    {
536        #[inline]
537        fn get_limit(&self) -> usize {
538            self.parent.as_ref().expect("parent missing").get_limit()
539        }
540
541        #[inline]
542        fn set_limit(&mut self, limit: usize) {
543            self.parent
544                .as_mut()
545                .expect("parent missing")
546                .set_limit(limit);
547        }
548    }
549
550    impl<'a, P> ReduceOnlyAssetsEncoder<P>
551    where
552        P: Encoder<'a> + Default,
553    {
554        #[inline]
555        pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
556            let initial_limit = parent.get_limit();
557            parent.set_limit(initial_limit + 6);
558            parent
559                .get_buf_mut()
560                .put_u16_at(initial_limit, Self::block_length());
561            parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
562            self.parent = Some(parent);
563            self.count = count;
564            self.index = usize::MAX;
565            self.offset = usize::MAX;
566            self.initial_limit = initial_limit;
567            self
568        }
569
570        #[inline]
571        pub fn block_length() -> u16 {
572            0
573        }
574
575        #[inline]
576        pub fn parent(&mut self) -> SbeResult<P> {
577            self.parent.take().ok_or(SbeErr::ParentNotSet)
578        }
579
580        /// will return Some(current index) when successful otherwise None
581        #[inline]
582        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
583            let index = self.index.wrapping_add(1);
584            if index >= self.count as usize {
585                return Ok(None);
586            }
587            if let Some(parent) = self.parent.as_mut() {
588                self.offset = parent.get_limit();
589                parent.set_limit(self.offset + Self::block_length() as usize);
590                self.index = index;
591                Ok(Some(index))
592            } else {
593                Err(SbeErr::ParentNotSet)
594            }
595        }
596
597        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
598        #[inline]
599        pub fn asset(&mut self, value: &str) {
600            let limit = self.get_limit();
601            let data_length = value.len();
602            self.set_limit(limit + 1 + data_length);
603            self.get_buf_mut().put_u8_at(limit, data_length as u8);
604            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
605        }
606    }
607} // end encoder
608
609pub mod decoder {
610    use message_header_codec::*;
611
612    use super::*;
613
614    #[derive(Clone, Copy, Debug, Default)]
615    pub struct AccountResponseDecoder<'a> {
616        buf: ReadBuf<'a>,
617        initial_offset: usize,
618        offset: usize,
619        limit: usize,
620        pub acting_block_length: u16,
621        pub acting_version: u16,
622    }
623
624    impl ActingVersion for AccountResponseDecoder<'_> {
625        #[inline]
626        fn acting_version(&self) -> u16 {
627            self.acting_version
628        }
629    }
630
631    impl<'a> Reader<'a> for AccountResponseDecoder<'a> {
632        #[inline]
633        fn get_buf(&self) -> &ReadBuf<'a> {
634            &self.buf
635        }
636    }
637
638    impl<'a> Decoder<'a> for AccountResponseDecoder<'a> {
639        #[inline]
640        fn get_limit(&self) -> usize {
641            self.limit
642        }
643
644        #[inline]
645        fn set_limit(&mut self, limit: usize) {
646            self.limit = limit;
647        }
648    }
649
650    impl<'a> AccountResponseDecoder<'a> {
651        pub fn wrap(
652            mut self,
653            buf: ReadBuf<'a>,
654            offset: usize,
655            acting_block_length: u16,
656            acting_version: u16,
657        ) -> Self {
658            let limit = offset + acting_block_length as usize;
659            self.buf = buf;
660            self.initial_offset = offset;
661            self.offset = offset;
662            self.limit = limit;
663            self.acting_block_length = acting_block_length;
664            self.acting_version = acting_version;
665            self
666        }
667
668        #[inline]
669        pub fn encoded_length(&self) -> usize {
670            self.limit - self.offset
671        }
672
673        pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
674            debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
675            let acting_block_length = header.block_length();
676            let acting_version = header.version();
677
678            self.wrap(
679                header.parent().unwrap(),
680                offset + message_header_codec::ENCODED_LENGTH,
681                acting_block_length,
682                acting_version,
683            )
684        }
685
686        /// primitive field - 'REQUIRED'
687        #[inline]
688        pub fn commission_exponent(&self) -> i8 {
689            self.get_buf().get_i8_at(self.offset)
690        }
691
692        /// primitive field - 'REQUIRED'
693        #[inline]
694        pub fn commission_rate_maker(&self) -> i64 {
695            self.get_buf().get_i64_at(self.offset + 1)
696        }
697
698        /// primitive field - 'REQUIRED'
699        #[inline]
700        pub fn commission_rate_taker(&self) -> i64 {
701            self.get_buf().get_i64_at(self.offset + 9)
702        }
703
704        /// primitive field - 'REQUIRED'
705        #[inline]
706        pub fn commission_rate_buyer(&self) -> i64 {
707            self.get_buf().get_i64_at(self.offset + 17)
708        }
709
710        /// primitive field - 'REQUIRED'
711        #[inline]
712        pub fn commission_rate_seller(&self) -> i64 {
713            self.get_buf().get_i64_at(self.offset + 25)
714        }
715
716        /// REQUIRED enum
717        #[inline]
718        pub fn can_trade(&self) -> bool_enum::BoolEnum {
719            self.get_buf().get_u8_at(self.offset + 33).into()
720        }
721
722        /// REQUIRED enum
723        #[inline]
724        pub fn can_withdraw(&self) -> bool_enum::BoolEnum {
725            self.get_buf().get_u8_at(self.offset + 34).into()
726        }
727
728        /// REQUIRED enum
729        #[inline]
730        pub fn can_deposit(&self) -> bool_enum::BoolEnum {
731            self.get_buf().get_u8_at(self.offset + 35).into()
732        }
733
734        /// REQUIRED enum
735        #[inline]
736        pub fn brokered(&self) -> bool_enum::BoolEnum {
737            self.get_buf().get_u8_at(self.offset + 36).into()
738        }
739
740        /// REQUIRED enum
741        #[inline]
742        pub fn require_self_trade_prevention(&self) -> bool_enum::BoolEnum {
743            self.get_buf().get_u8_at(self.offset + 37).into()
744        }
745
746        /// REQUIRED enum
747        #[inline]
748        pub fn prevent_sor(&self) -> bool_enum::BoolEnum {
749            self.get_buf().get_u8_at(self.offset + 38).into()
750        }
751
752        /// primitive field - 'REQUIRED'
753        #[inline]
754        pub fn update_time(&self) -> i64 {
755            self.get_buf().get_i64_at(self.offset + 39)
756        }
757
758        /// REQUIRED enum
759        #[inline]
760        pub fn account_type(&self) -> account_type::AccountType {
761            self.get_buf().get_u8_at(self.offset + 47).into()
762        }
763
764        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
765        #[inline]
766        pub fn trade_group_id(&self) -> Option<i64> {
767            let value = self.get_buf().get_i64_at(self.offset + 48);
768            if value == -9223372036854775808_i64 {
769                None
770            } else {
771                Some(value)
772            }
773        }
774
775        /// primitive field - 'REQUIRED'
776        #[inline]
777        pub fn uid(&self) -> i64 {
778            self.get_buf().get_i64_at(self.offset + 56)
779        }
780
781        /// GROUP DECODER (id=100)
782        #[inline]
783        pub fn balances_decoder(self) -> BalancesDecoder<Self> {
784            BalancesDecoder::default().wrap(self)
785        }
786
787        /// GROUP DECODER (id=101)
788        #[inline]
789        pub fn permissions_decoder(self) -> PermissionsDecoder<Self> {
790            PermissionsDecoder::default().wrap(self)
791        }
792
793        /// GROUP DECODER (id=102)
794        #[inline]
795        pub fn reduce_only_assets_decoder(self) -> ReduceOnlyAssetsDecoder<Self> {
796            ReduceOnlyAssetsDecoder::default().wrap(self)
797        }
798    }
799
800    #[derive(Debug, Default)]
801    pub struct BalancesDecoder<P> {
802        parent: Option<P>,
803        block_length: u16,
804        count: u32,
805        index: usize,
806        offset: usize,
807    }
808
809    impl<'a, P> ActingVersion for BalancesDecoder<P>
810    where
811        P: Reader<'a> + ActingVersion + Default,
812    {
813        #[inline]
814        fn acting_version(&self) -> u16 {
815            self.parent.as_ref().unwrap().acting_version()
816        }
817    }
818
819    impl<'a, P> Reader<'a> for BalancesDecoder<P>
820    where
821        P: Reader<'a> + Default,
822    {
823        #[inline]
824        fn get_buf(&self) -> &ReadBuf<'a> {
825            self.parent.as_ref().expect("parent missing").get_buf()
826        }
827    }
828
829    impl<'a, P> Decoder<'a> for BalancesDecoder<P>
830    where
831        P: Decoder<'a> + ActingVersion + Default,
832    {
833        #[inline]
834        fn get_limit(&self) -> usize {
835            self.parent.as_ref().expect("parent missing").get_limit()
836        }
837
838        #[inline]
839        fn set_limit(&mut self, limit: usize) {
840            self.parent
841                .as_mut()
842                .expect("parent missing")
843                .set_limit(limit);
844        }
845    }
846
847    impl<'a, P> BalancesDecoder<P>
848    where
849        P: Decoder<'a> + ActingVersion + Default,
850    {
851        pub fn wrap(mut self, mut parent: P) -> Self {
852            let initial_offset = parent.get_limit();
853            let block_length = parent.get_buf().get_u16_at(initial_offset);
854            let count = parent.get_buf().get_u32_at(initial_offset + 2);
855            parent.set_limit(initial_offset + 6);
856            self.parent = Some(parent);
857            self.block_length = block_length;
858            self.count = count;
859            self.index = usize::MAX;
860            self.offset = 0;
861            self
862        }
863
864        /// group token - Token{signal=BEGIN_GROUP, name='balances', referencedName='null', description='null', packageName='null', id=100, version=0, deprecated=0, encodedLength=17, offset=64, 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'}}
865        #[inline]
866        pub fn parent(&mut self) -> SbeResult<P> {
867            self.parent.take().ok_or(SbeErr::ParentNotSet)
868        }
869
870        #[inline]
871        pub fn acting_version(&mut self) -> u16 {
872            self.parent.as_ref().unwrap().acting_version()
873        }
874
875        #[inline]
876        pub fn count(&self) -> u32 {
877            self.count
878        }
879
880        /// will return Some(current index) when successful otherwise None
881        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
882            let index = self.index.wrapping_add(1);
883            if index >= self.count as usize {
884                return Ok(None);
885            }
886            if let Some(parent) = self.parent.as_mut() {
887                self.offset = parent.get_limit();
888                parent.set_limit(self.offset + self.block_length as usize);
889                self.index = index;
890                Ok(Some(index))
891            } else {
892                Err(SbeErr::ParentNotSet)
893            }
894        }
895
896        /// primitive field - 'REQUIRED'
897        #[inline]
898        pub fn exponent(&self) -> i8 {
899            self.get_buf().get_i8_at(self.offset)
900        }
901
902        /// primitive field - 'REQUIRED'
903        #[inline]
904        pub fn free(&self) -> i64 {
905            self.get_buf().get_i64_at(self.offset + 1)
906        }
907
908        /// primitive field - 'REQUIRED'
909        #[inline]
910        pub fn locked(&self) -> i64 {
911            self.get_buf().get_i64_at(self.offset + 9)
912        }
913
914        /// VAR_DATA DECODER - character encoding: 'UTF-8'
915        #[inline]
916        pub fn asset_decoder(&mut self) -> (usize, usize) {
917            let offset = self.parent.as_ref().expect("parent missing").get_limit();
918            let data_length = self.get_buf().get_u8_at(offset) as usize;
919            self.parent
920                .as_mut()
921                .unwrap()
922                .set_limit(offset + 1 + data_length);
923            (offset + 1, data_length)
924        }
925
926        #[inline]
927        pub fn asset_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
928            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
929            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
930        }
931    }
932
933    #[derive(Debug, Default)]
934    pub struct PermissionsDecoder<P> {
935        parent: Option<P>,
936        block_length: u16,
937        count: u32,
938        index: usize,
939        offset: usize,
940    }
941
942    impl<'a, P> ActingVersion for PermissionsDecoder<P>
943    where
944        P: Reader<'a> + ActingVersion + Default,
945    {
946        #[inline]
947        fn acting_version(&self) -> u16 {
948            self.parent.as_ref().unwrap().acting_version()
949        }
950    }
951
952    impl<'a, P> Reader<'a> for PermissionsDecoder<P>
953    where
954        P: Reader<'a> + Default,
955    {
956        #[inline]
957        fn get_buf(&self) -> &ReadBuf<'a> {
958            self.parent.as_ref().expect("parent missing").get_buf()
959        }
960    }
961
962    impl<'a, P> Decoder<'a> for PermissionsDecoder<P>
963    where
964        P: Decoder<'a> + ActingVersion + Default,
965    {
966        #[inline]
967        fn get_limit(&self) -> usize {
968            self.parent.as_ref().expect("parent missing").get_limit()
969        }
970
971        #[inline]
972        fn set_limit(&mut self, limit: usize) {
973            self.parent
974                .as_mut()
975                .expect("parent missing")
976                .set_limit(limit);
977        }
978    }
979
980    impl<'a, P> PermissionsDecoder<P>
981    where
982        P: Decoder<'a> + ActingVersion + Default,
983    {
984        pub fn wrap(mut self, mut parent: P) -> Self {
985            let initial_offset = parent.get_limit();
986            let block_length = parent.get_buf().get_u16_at(initial_offset);
987            let count = parent.get_buf().get_u32_at(initial_offset + 2);
988            parent.set_limit(initial_offset + 6);
989            self.parent = Some(parent);
990            self.block_length = block_length;
991            self.count = count;
992            self.index = usize::MAX;
993            self.offset = 0;
994            self
995        }
996
997        /// group token - Token{signal=BEGIN_GROUP, name='permissions', referencedName='null', description='null', packageName='null', id=101, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=12, 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'}}
998        #[inline]
999        pub fn parent(&mut self) -> SbeResult<P> {
1000            self.parent.take().ok_or(SbeErr::ParentNotSet)
1001        }
1002
1003        #[inline]
1004        pub fn acting_version(&mut self) -> u16 {
1005            self.parent.as_ref().unwrap().acting_version()
1006        }
1007
1008        #[inline]
1009        pub fn count(&self) -> u32 {
1010            self.count
1011        }
1012
1013        /// will return Some(current index) when successful otherwise None
1014        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
1015            let index = self.index.wrapping_add(1);
1016            if index >= self.count as usize {
1017                return Ok(None);
1018            }
1019            if let Some(parent) = self.parent.as_mut() {
1020                self.offset = parent.get_limit();
1021                parent.set_limit(self.offset + self.block_length as usize);
1022                self.index = index;
1023                Ok(Some(index))
1024            } else {
1025                Err(SbeErr::ParentNotSet)
1026            }
1027        }
1028
1029        /// VAR_DATA DECODER - character encoding: 'UTF-8'
1030        #[inline]
1031        pub fn permission_decoder(&mut self) -> (usize, usize) {
1032            let offset = self.parent.as_ref().expect("parent missing").get_limit();
1033            let data_length = self.get_buf().get_u8_at(offset) as usize;
1034            self.parent
1035                .as_mut()
1036                .unwrap()
1037                .set_limit(offset + 1 + data_length);
1038            (offset + 1, data_length)
1039        }
1040
1041        #[inline]
1042        pub fn permission_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
1043            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
1044            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
1045        }
1046    }
1047
1048    #[derive(Debug, Default)]
1049    pub struct ReduceOnlyAssetsDecoder<P> {
1050        parent: Option<P>,
1051        block_length: u16,
1052        count: u32,
1053        index: usize,
1054        offset: usize,
1055    }
1056
1057    impl<'a, P> ActingVersion for ReduceOnlyAssetsDecoder<P>
1058    where
1059        P: Reader<'a> + ActingVersion + Default,
1060    {
1061        #[inline]
1062        fn acting_version(&self) -> u16 {
1063            self.parent.as_ref().unwrap().acting_version()
1064        }
1065    }
1066
1067    impl<'a, P> Reader<'a> for ReduceOnlyAssetsDecoder<P>
1068    where
1069        P: Reader<'a> + Default,
1070    {
1071        #[inline]
1072        fn get_buf(&self) -> &ReadBuf<'a> {
1073            self.parent.as_ref().expect("parent missing").get_buf()
1074        }
1075    }
1076
1077    impl<'a, P> Decoder<'a> for ReduceOnlyAssetsDecoder<P>
1078    where
1079        P: Decoder<'a> + ActingVersion + Default,
1080    {
1081        #[inline]
1082        fn get_limit(&self) -> usize {
1083            self.parent.as_ref().expect("parent missing").get_limit()
1084        }
1085
1086        #[inline]
1087        fn set_limit(&mut self, limit: usize) {
1088            self.parent
1089                .as_mut()
1090                .expect("parent missing")
1091                .set_limit(limit);
1092        }
1093    }
1094
1095    impl<'a, P> ReduceOnlyAssetsDecoder<P>
1096    where
1097        P: Decoder<'a> + ActingVersion + Default,
1098    {
1099        pub fn wrap(mut self, mut parent: P) -> Self {
1100            let initial_offset = parent.get_limit();
1101            let block_length = parent.get_buf().get_u16_at(initial_offset);
1102            let count = parent.get_buf().get_u32_at(initial_offset + 2);
1103            parent.set_limit(initial_offset + 6);
1104            self.parent = Some(parent);
1105            self.block_length = block_length;
1106            self.count = count;
1107            self.index = usize::MAX;
1108            self.offset = 0;
1109            self
1110        }
1111
1112        /// group token - Token{signal=BEGIN_GROUP, name='reduceOnlyAssets', referencedName='null', description='null', packageName='null', id=102, version=0, deprecated=0, encodedLength=0, offset=-1, componentTokenCount=12, 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'}}
1113        #[inline]
1114        pub fn parent(&mut self) -> SbeResult<P> {
1115            self.parent.take().ok_or(SbeErr::ParentNotSet)
1116        }
1117
1118        #[inline]
1119        pub fn acting_version(&mut self) -> u16 {
1120            self.parent.as_ref().unwrap().acting_version()
1121        }
1122
1123        #[inline]
1124        pub fn count(&self) -> u32 {
1125            self.count
1126        }
1127
1128        /// will return Some(current index) when successful otherwise None
1129        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
1130            let index = self.index.wrapping_add(1);
1131            if index >= self.count as usize {
1132                return Ok(None);
1133            }
1134            if let Some(parent) = self.parent.as_mut() {
1135                self.offset = parent.get_limit();
1136                parent.set_limit(self.offset + self.block_length as usize);
1137                self.index = index;
1138                Ok(Some(index))
1139            } else {
1140                Err(SbeErr::ParentNotSet)
1141            }
1142        }
1143
1144        /// VAR_DATA DECODER - character encoding: 'UTF-8'
1145        #[inline]
1146        pub fn asset_decoder(&mut self) -> (usize, usize) {
1147            let offset = self.parent.as_ref().expect("parent missing").get_limit();
1148            let data_length = self.get_buf().get_u8_at(offset) as usize;
1149            self.parent
1150                .as_mut()
1151                .unwrap()
1152                .set_limit(offset + 1 + data_length);
1153            (offset + 1, data_length)
1154        }
1155
1156        #[inline]
1157        pub fn asset_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
1158            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
1159            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
1160        }
1161    }
1162} // end decoder