Skip to main content

nautilus_binance/spot/sbe/generated/
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
345            if let Some(parent) = self.parent.as_mut() {
346                self.offset = parent.get_limit();
347                parent.set_limit(self.offset + Self::block_length() as usize);
348                self.index = index;
349                Ok(Some(index))
350            } else {
351                Err(SbeErr::ParentNotSet)
352            }
353        }
354
355        /// primitive field 'exponent'
356        /// - min value: -127
357        /// - max value: 127
358        /// - null value: -128_i8
359        /// - characterEncoding: null
360        /// - semanticType: null
361        /// - encodedOffset: 0
362        /// - encodedLength: 1
363        /// - version: 0
364        #[inline]
365        pub fn exponent(&mut self, value: i8) {
366            let offset = self.offset;
367            self.get_buf_mut().put_i8_at(offset, value);
368        }
369
370        /// primitive field 'free'
371        /// - min value: -9223372036854775807
372        /// - max value: 9223372036854775807
373        /// - null value: -9223372036854775808_i64
374        /// - characterEncoding: null
375        /// - semanticType: null
376        /// - encodedOffset: 1
377        /// - encodedLength: 8
378        /// - version: 0
379        #[inline]
380        pub fn free(&mut self, value: i64) {
381            let offset = self.offset + 1;
382            self.get_buf_mut().put_i64_at(offset, value);
383        }
384
385        /// primitive field 'locked'
386        /// - min value: -9223372036854775807
387        /// - max value: 9223372036854775807
388        /// - null value: -9223372036854775808_i64
389        /// - characterEncoding: null
390        /// - semanticType: null
391        /// - encodedOffset: 9
392        /// - encodedLength: 8
393        /// - version: 0
394        #[inline]
395        pub fn locked(&mut self, value: i64) {
396            let offset = self.offset + 9;
397            self.get_buf_mut().put_i64_at(offset, value);
398        }
399
400        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
401        #[inline]
402        pub fn asset(&mut self, value: &str) {
403            let limit = self.get_limit();
404            let data_length = value.len();
405            self.set_limit(limit + 1 + data_length);
406            self.get_buf_mut().put_u8_at(limit, data_length as u8);
407            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
408        }
409    }
410
411    #[derive(Debug, Default)]
412    pub struct PermissionsEncoder<P> {
413        parent: Option<P>,
414        count: u32,
415        index: usize,
416        offset: usize,
417        initial_limit: usize,
418    }
419
420    impl<'a, P> Writer<'a> for PermissionsEncoder<P>
421    where
422        P: Writer<'a> + Default,
423    {
424        #[inline]
425        fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
426            if let Some(parent) = self.parent.as_mut() {
427                parent.get_buf_mut()
428            } else {
429                panic!("parent was None")
430            }
431        }
432    }
433
434    impl<'a, P> Encoder<'a> for PermissionsEncoder<P>
435    where
436        P: Encoder<'a> + Default,
437    {
438        #[inline]
439        fn get_limit(&self) -> usize {
440            self.parent.as_ref().expect("parent missing").get_limit()
441        }
442
443        #[inline]
444        fn set_limit(&mut self, limit: usize) {
445            self.parent
446                .as_mut()
447                .expect("parent missing")
448                .set_limit(limit);
449        }
450    }
451
452    impl<'a, P> PermissionsEncoder<P>
453    where
454        P: Encoder<'a> + Default,
455    {
456        #[inline]
457        pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
458            let initial_limit = parent.get_limit();
459            parent.set_limit(initial_limit + 6);
460            parent
461                .get_buf_mut()
462                .put_u16_at(initial_limit, Self::block_length());
463            parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
464            self.parent = Some(parent);
465            self.count = count;
466            self.index = usize::MAX;
467            self.offset = usize::MAX;
468            self.initial_limit = initial_limit;
469            self
470        }
471
472        #[inline]
473        pub fn block_length() -> u16 {
474            0
475        }
476
477        #[inline]
478        pub fn parent(&mut self) -> SbeResult<P> {
479            self.parent.take().ok_or(SbeErr::ParentNotSet)
480        }
481
482        /// will return Some(current index) when successful otherwise None
483        #[inline]
484        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
485            let index = self.index.wrapping_add(1);
486            if index >= self.count as usize {
487                return Ok(None);
488            }
489
490            if let Some(parent) = self.parent.as_mut() {
491                self.offset = parent.get_limit();
492                parent.set_limit(self.offset + Self::block_length() as usize);
493                self.index = index;
494                Ok(Some(index))
495            } else {
496                Err(SbeErr::ParentNotSet)
497            }
498        }
499
500        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
501        #[inline]
502        pub fn permission(&mut self, value: &str) {
503            let limit = self.get_limit();
504            let data_length = value.len();
505            self.set_limit(limit + 1 + data_length);
506            self.get_buf_mut().put_u8_at(limit, data_length as u8);
507            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
508        }
509    }
510
511    #[derive(Debug, Default)]
512    pub struct ReduceOnlyAssetsEncoder<P> {
513        parent: Option<P>,
514        count: u32,
515        index: usize,
516        offset: usize,
517        initial_limit: usize,
518    }
519
520    impl<'a, P> Writer<'a> for ReduceOnlyAssetsEncoder<P>
521    where
522        P: Writer<'a> + Default,
523    {
524        #[inline]
525        fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
526            if let Some(parent) = self.parent.as_mut() {
527                parent.get_buf_mut()
528            } else {
529                panic!("parent was None")
530            }
531        }
532    }
533
534    impl<'a, P> Encoder<'a> for ReduceOnlyAssetsEncoder<P>
535    where
536        P: Encoder<'a> + Default,
537    {
538        #[inline]
539        fn get_limit(&self) -> usize {
540            self.parent.as_ref().expect("parent missing").get_limit()
541        }
542
543        #[inline]
544        fn set_limit(&mut self, limit: usize) {
545            self.parent
546                .as_mut()
547                .expect("parent missing")
548                .set_limit(limit);
549        }
550    }
551
552    impl<'a, P> ReduceOnlyAssetsEncoder<P>
553    where
554        P: Encoder<'a> + Default,
555    {
556        #[inline]
557        pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
558            let initial_limit = parent.get_limit();
559            parent.set_limit(initial_limit + 6);
560            parent
561                .get_buf_mut()
562                .put_u16_at(initial_limit, Self::block_length());
563            parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
564            self.parent = Some(parent);
565            self.count = count;
566            self.index = usize::MAX;
567            self.offset = usize::MAX;
568            self.initial_limit = initial_limit;
569            self
570        }
571
572        #[inline]
573        pub fn block_length() -> u16 {
574            0
575        }
576
577        #[inline]
578        pub fn parent(&mut self) -> SbeResult<P> {
579            self.parent.take().ok_or(SbeErr::ParentNotSet)
580        }
581
582        /// will return Some(current index) when successful otherwise None
583        #[inline]
584        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
585            let index = self.index.wrapping_add(1);
586            if index >= self.count as usize {
587                return Ok(None);
588            }
589
590            if let Some(parent) = self.parent.as_mut() {
591                self.offset = parent.get_limit();
592                parent.set_limit(self.offset + Self::block_length() as usize);
593                self.index = index;
594                Ok(Some(index))
595            } else {
596                Err(SbeErr::ParentNotSet)
597            }
598        }
599
600        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
601        #[inline]
602        pub fn asset(&mut self, value: &str) {
603            let limit = self.get_limit();
604            let data_length = value.len();
605            self.set_limit(limit + 1 + data_length);
606            self.get_buf_mut().put_u8_at(limit, data_length as u8);
607            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
608        }
609    }
610} // end encoder
611
612pub mod decoder {
613    use message_header_codec::*;
614
615    use super::*;
616
617    #[derive(Clone, Copy, Debug, Default)]
618    pub struct AccountResponseDecoder<'a> {
619        buf: ReadBuf<'a>,
620        initial_offset: usize,
621        offset: usize,
622        limit: usize,
623        pub acting_block_length: u16,
624        pub acting_version: u16,
625    }
626
627    impl ActingVersion for AccountResponseDecoder<'_> {
628        #[inline]
629        fn acting_version(&self) -> u16 {
630            self.acting_version
631        }
632    }
633
634    impl<'a> Reader<'a> for AccountResponseDecoder<'a> {
635        #[inline]
636        fn get_buf(&self) -> &ReadBuf<'a> {
637            &self.buf
638        }
639    }
640
641    impl<'a> Decoder<'a> for AccountResponseDecoder<'a> {
642        #[inline]
643        fn get_limit(&self) -> usize {
644            self.limit
645        }
646
647        #[inline]
648        fn set_limit(&mut self, limit: usize) {
649            self.limit = limit;
650        }
651    }
652
653    impl<'a> AccountResponseDecoder<'a> {
654        pub fn wrap(
655            mut self,
656            buf: ReadBuf<'a>,
657            offset: usize,
658            acting_block_length: u16,
659            acting_version: u16,
660        ) -> Self {
661            let limit = offset + acting_block_length as usize;
662            self.buf = buf;
663            self.initial_offset = offset;
664            self.offset = offset;
665            self.limit = limit;
666            self.acting_block_length = acting_block_length;
667            self.acting_version = acting_version;
668            self
669        }
670
671        #[inline]
672        pub fn encoded_length(&self) -> usize {
673            self.limit - self.offset
674        }
675
676        pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
677            debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
678            let acting_block_length = header.block_length();
679            let acting_version = header.version();
680
681            self.wrap(
682                header.parent().unwrap(),
683                offset + message_header_codec::ENCODED_LENGTH,
684                acting_block_length,
685                acting_version,
686            )
687        }
688
689        /// primitive field - 'REQUIRED'
690        #[inline]
691        pub fn commission_exponent(&self) -> i8 {
692            self.get_buf().get_i8_at(self.offset)
693        }
694
695        /// primitive field - 'REQUIRED'
696        #[inline]
697        pub fn commission_rate_maker(&self) -> i64 {
698            self.get_buf().get_i64_at(self.offset + 1)
699        }
700
701        /// primitive field - 'REQUIRED'
702        #[inline]
703        pub fn commission_rate_taker(&self) -> i64 {
704            self.get_buf().get_i64_at(self.offset + 9)
705        }
706
707        /// primitive field - 'REQUIRED'
708        #[inline]
709        pub fn commission_rate_buyer(&self) -> i64 {
710            self.get_buf().get_i64_at(self.offset + 17)
711        }
712
713        /// primitive field - 'REQUIRED'
714        #[inline]
715        pub fn commission_rate_seller(&self) -> i64 {
716            self.get_buf().get_i64_at(self.offset + 25)
717        }
718
719        /// REQUIRED enum
720        #[inline]
721        pub fn can_trade(&self) -> bool_enum::BoolEnum {
722            self.get_buf().get_u8_at(self.offset + 33).into()
723        }
724
725        /// REQUIRED enum
726        #[inline]
727        pub fn can_withdraw(&self) -> bool_enum::BoolEnum {
728            self.get_buf().get_u8_at(self.offset + 34).into()
729        }
730
731        /// REQUIRED enum
732        #[inline]
733        pub fn can_deposit(&self) -> bool_enum::BoolEnum {
734            self.get_buf().get_u8_at(self.offset + 35).into()
735        }
736
737        /// REQUIRED enum
738        #[inline]
739        pub fn brokered(&self) -> bool_enum::BoolEnum {
740            self.get_buf().get_u8_at(self.offset + 36).into()
741        }
742
743        /// REQUIRED enum
744        #[inline]
745        pub fn require_self_trade_prevention(&self) -> bool_enum::BoolEnum {
746            self.get_buf().get_u8_at(self.offset + 37).into()
747        }
748
749        /// REQUIRED enum
750        #[inline]
751        pub fn prevent_sor(&self) -> bool_enum::BoolEnum {
752            self.get_buf().get_u8_at(self.offset + 38).into()
753        }
754
755        /// primitive field - 'REQUIRED'
756        #[inline]
757        pub fn update_time(&self) -> i64 {
758            self.get_buf().get_i64_at(self.offset + 39)
759        }
760
761        /// REQUIRED enum
762        #[inline]
763        pub fn account_type(&self) -> account_type::AccountType {
764            self.get_buf().get_u8_at(self.offset + 47).into()
765        }
766
767        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
768        #[inline]
769        pub fn trade_group_id(&self) -> Option<i64> {
770            let value = self.get_buf().get_i64_at(self.offset + 48);
771            if value == -9223372036854775808_i64 {
772                None
773            } else {
774                Some(value)
775            }
776        }
777
778        /// primitive field - 'REQUIRED'
779        #[inline]
780        pub fn uid(&self) -> i64 {
781            self.get_buf().get_i64_at(self.offset + 56)
782        }
783
784        /// GROUP DECODER (id=100)
785        #[inline]
786        pub fn balances_decoder(self) -> BalancesDecoder<Self> {
787            BalancesDecoder::default().wrap(self)
788        }
789
790        /// GROUP DECODER (id=101)
791        #[inline]
792        pub fn permissions_decoder(self) -> PermissionsDecoder<Self> {
793            PermissionsDecoder::default().wrap(self)
794        }
795
796        /// GROUP DECODER (id=102)
797        #[inline]
798        pub fn reduce_only_assets_decoder(self) -> ReduceOnlyAssetsDecoder<Self> {
799            ReduceOnlyAssetsDecoder::default().wrap(self)
800        }
801    }
802
803    #[derive(Debug, Default)]
804    pub struct BalancesDecoder<P> {
805        parent: Option<P>,
806        block_length: u16,
807        count: u32,
808        index: usize,
809        offset: usize,
810    }
811
812    impl<'a, P> ActingVersion for BalancesDecoder<P>
813    where
814        P: Reader<'a> + ActingVersion + Default,
815    {
816        #[inline]
817        fn acting_version(&self) -> u16 {
818            self.parent.as_ref().unwrap().acting_version()
819        }
820    }
821
822    impl<'a, P> Reader<'a> for BalancesDecoder<P>
823    where
824        P: Reader<'a> + Default,
825    {
826        #[inline]
827        fn get_buf(&self) -> &ReadBuf<'a> {
828            self.parent.as_ref().expect("parent missing").get_buf()
829        }
830    }
831
832    impl<'a, P> Decoder<'a> for BalancesDecoder<P>
833    where
834        P: Decoder<'a> + ActingVersion + Default,
835    {
836        #[inline]
837        fn get_limit(&self) -> usize {
838            self.parent.as_ref().expect("parent missing").get_limit()
839        }
840
841        #[inline]
842        fn set_limit(&mut self, limit: usize) {
843            self.parent
844                .as_mut()
845                .expect("parent missing")
846                .set_limit(limit);
847        }
848    }
849
850    impl<'a, P> BalancesDecoder<P>
851    where
852        P: Decoder<'a> + ActingVersion + Default,
853    {
854        pub fn wrap(mut self, mut parent: P) -> Self {
855            let initial_offset = parent.get_limit();
856            let block_length = parent.get_buf().get_u16_at(initial_offset);
857            let count = parent.get_buf().get_u32_at(initial_offset + 2);
858            parent.set_limit(initial_offset + 6);
859            self.parent = Some(parent);
860            self.block_length = block_length;
861            self.count = count;
862            self.index = usize::MAX;
863            self.offset = 0;
864            self
865        }
866
867        /// 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'}}
868        #[inline]
869        pub fn parent(&mut self) -> SbeResult<P> {
870            self.parent.take().ok_or(SbeErr::ParentNotSet)
871        }
872
873        #[inline]
874        pub fn acting_version(&mut self) -> u16 {
875            self.parent.as_ref().unwrap().acting_version()
876        }
877
878        #[inline]
879        pub fn count(&self) -> u32 {
880            self.count
881        }
882
883        /// will return Some(current index) when successful otherwise None
884        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
885            let index = self.index.wrapping_add(1);
886            if index >= self.count as usize {
887                return Ok(None);
888            }
889
890            if let Some(parent) = self.parent.as_mut() {
891                self.offset = parent.get_limit();
892                parent.set_limit(self.offset + self.block_length as usize);
893                self.index = index;
894                Ok(Some(index))
895            } else {
896                Err(SbeErr::ParentNotSet)
897            }
898        }
899
900        /// primitive field - 'REQUIRED'
901        #[inline]
902        pub fn exponent(&self) -> i8 {
903            self.get_buf().get_i8_at(self.offset)
904        }
905
906        /// primitive field - 'REQUIRED'
907        #[inline]
908        pub fn free(&self) -> i64 {
909            self.get_buf().get_i64_at(self.offset + 1)
910        }
911
912        /// primitive field - 'REQUIRED'
913        #[inline]
914        pub fn locked(&self) -> i64 {
915            self.get_buf().get_i64_at(self.offset + 9)
916        }
917
918        /// VAR_DATA DECODER - character encoding: 'UTF-8'
919        #[inline]
920        pub fn asset_decoder(&mut self) -> (usize, usize) {
921            let offset = self.parent.as_ref().expect("parent missing").get_limit();
922            let data_length = self.get_buf().get_u8_at(offset) as usize;
923            self.parent
924                .as_mut()
925                .unwrap()
926                .set_limit(offset + 1 + data_length);
927            (offset + 1, data_length)
928        }
929
930        #[inline]
931        pub fn asset_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
932            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
933            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
934        }
935    }
936
937    #[derive(Debug, Default)]
938    pub struct PermissionsDecoder<P> {
939        parent: Option<P>,
940        block_length: u16,
941        count: u32,
942        index: usize,
943        offset: usize,
944    }
945
946    impl<'a, P> ActingVersion for PermissionsDecoder<P>
947    where
948        P: Reader<'a> + ActingVersion + Default,
949    {
950        #[inline]
951        fn acting_version(&self) -> u16 {
952            self.parent.as_ref().unwrap().acting_version()
953        }
954    }
955
956    impl<'a, P> Reader<'a> for PermissionsDecoder<P>
957    where
958        P: Reader<'a> + Default,
959    {
960        #[inline]
961        fn get_buf(&self) -> &ReadBuf<'a> {
962            self.parent.as_ref().expect("parent missing").get_buf()
963        }
964    }
965
966    impl<'a, P> Decoder<'a> for PermissionsDecoder<P>
967    where
968        P: Decoder<'a> + ActingVersion + Default,
969    {
970        #[inline]
971        fn get_limit(&self) -> usize {
972            self.parent.as_ref().expect("parent missing").get_limit()
973        }
974
975        #[inline]
976        fn set_limit(&mut self, limit: usize) {
977            self.parent
978                .as_mut()
979                .expect("parent missing")
980                .set_limit(limit);
981        }
982    }
983
984    impl<'a, P> PermissionsDecoder<P>
985    where
986        P: Decoder<'a> + ActingVersion + Default,
987    {
988        pub fn wrap(mut self, mut parent: P) -> Self {
989            let initial_offset = parent.get_limit();
990            let block_length = parent.get_buf().get_u16_at(initial_offset);
991            let count = parent.get_buf().get_u32_at(initial_offset + 2);
992            parent.set_limit(initial_offset + 6);
993            self.parent = Some(parent);
994            self.block_length = block_length;
995            self.count = count;
996            self.index = usize::MAX;
997            self.offset = 0;
998            self
999        }
1000
1001        /// 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'}}
1002        #[inline]
1003        pub fn parent(&mut self) -> SbeResult<P> {
1004            self.parent.take().ok_or(SbeErr::ParentNotSet)
1005        }
1006
1007        #[inline]
1008        pub fn acting_version(&mut self) -> u16 {
1009            self.parent.as_ref().unwrap().acting_version()
1010        }
1011
1012        #[inline]
1013        pub fn count(&self) -> u32 {
1014            self.count
1015        }
1016
1017        /// will return Some(current index) when successful otherwise None
1018        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
1019            let index = self.index.wrapping_add(1);
1020            if index >= self.count as usize {
1021                return Ok(None);
1022            }
1023
1024            if let Some(parent) = self.parent.as_mut() {
1025                self.offset = parent.get_limit();
1026                parent.set_limit(self.offset + self.block_length as usize);
1027                self.index = index;
1028                Ok(Some(index))
1029            } else {
1030                Err(SbeErr::ParentNotSet)
1031            }
1032        }
1033
1034        /// VAR_DATA DECODER - character encoding: 'UTF-8'
1035        #[inline]
1036        pub fn permission_decoder(&mut self) -> (usize, usize) {
1037            let offset = self.parent.as_ref().expect("parent missing").get_limit();
1038            let data_length = self.get_buf().get_u8_at(offset) as usize;
1039            self.parent
1040                .as_mut()
1041                .unwrap()
1042                .set_limit(offset + 1 + data_length);
1043            (offset + 1, data_length)
1044        }
1045
1046        #[inline]
1047        pub fn permission_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
1048            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
1049            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
1050        }
1051    }
1052
1053    #[derive(Debug, Default)]
1054    pub struct ReduceOnlyAssetsDecoder<P> {
1055        parent: Option<P>,
1056        block_length: u16,
1057        count: u32,
1058        index: usize,
1059        offset: usize,
1060    }
1061
1062    impl<'a, P> ActingVersion for ReduceOnlyAssetsDecoder<P>
1063    where
1064        P: Reader<'a> + ActingVersion + Default,
1065    {
1066        #[inline]
1067        fn acting_version(&self) -> u16 {
1068            self.parent.as_ref().unwrap().acting_version()
1069        }
1070    }
1071
1072    impl<'a, P> Reader<'a> for ReduceOnlyAssetsDecoder<P>
1073    where
1074        P: Reader<'a> + Default,
1075    {
1076        #[inline]
1077        fn get_buf(&self) -> &ReadBuf<'a> {
1078            self.parent.as_ref().expect("parent missing").get_buf()
1079        }
1080    }
1081
1082    impl<'a, P> Decoder<'a> for ReduceOnlyAssetsDecoder<P>
1083    where
1084        P: Decoder<'a> + ActingVersion + Default,
1085    {
1086        #[inline]
1087        fn get_limit(&self) -> usize {
1088            self.parent.as_ref().expect("parent missing").get_limit()
1089        }
1090
1091        #[inline]
1092        fn set_limit(&mut self, limit: usize) {
1093            self.parent
1094                .as_mut()
1095                .expect("parent missing")
1096                .set_limit(limit);
1097        }
1098    }
1099
1100    impl<'a, P> ReduceOnlyAssetsDecoder<P>
1101    where
1102        P: Decoder<'a> + ActingVersion + Default,
1103    {
1104        pub fn wrap(mut self, mut parent: P) -> Self {
1105            let initial_offset = parent.get_limit();
1106            let block_length = parent.get_buf().get_u16_at(initial_offset);
1107            let count = parent.get_buf().get_u32_at(initial_offset + 2);
1108            parent.set_limit(initial_offset + 6);
1109            self.parent = Some(parent);
1110            self.block_length = block_length;
1111            self.count = count;
1112            self.index = usize::MAX;
1113            self.offset = 0;
1114            self
1115        }
1116
1117        /// 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'}}
1118        #[inline]
1119        pub fn parent(&mut self) -> SbeResult<P> {
1120            self.parent.take().ok_or(SbeErr::ParentNotSet)
1121        }
1122
1123        #[inline]
1124        pub fn acting_version(&mut self) -> u16 {
1125            self.parent.as_ref().unwrap().acting_version()
1126        }
1127
1128        #[inline]
1129        pub fn count(&self) -> u32 {
1130            self.count
1131        }
1132
1133        /// will return Some(current index) when successful otherwise None
1134        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
1135            let index = self.index.wrapping_add(1);
1136            if index >= self.count as usize {
1137                return Ok(None);
1138            }
1139
1140            if let Some(parent) = self.parent.as_mut() {
1141                self.offset = parent.get_limit();
1142                parent.set_limit(self.offset + self.block_length as usize);
1143                self.index = index;
1144                Ok(Some(index))
1145            } else {
1146                Err(SbeErr::ParentNotSet)
1147            }
1148        }
1149
1150        /// VAR_DATA DECODER - character encoding: 'UTF-8'
1151        #[inline]
1152        pub fn asset_decoder(&mut self) -> (usize, usize) {
1153            let offset = self.parent.as_ref().expect("parent missing").get_limit();
1154            let data_length = self.get_buf().get_u8_at(offset) as usize;
1155            self.parent
1156                .as_mut()
1157                .unwrap()
1158                .set_limit(offset + 1 + data_length);
1159            (offset + 1, data_length)
1160        }
1161
1162        #[inline]
1163        pub fn asset_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
1164            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
1165            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
1166        }
1167    }
1168} // end decoder