Skip to main content

nautilus_binance/spot/sbe/generated/
outbound_account_position_event_codec.rs

1pub use decoder::OutboundAccountPositionEventDecoder;
2pub use encoder::OutboundAccountPositionEventEncoder;
3
4use super::*;
5pub use super::{SBE_SCHEMA_ID, SBE_SCHEMA_VERSION, SBE_SEMANTIC_VERSION};
6
7pub const SBE_BLOCK_LENGTH: u16 = 18;
8pub const SBE_TEMPLATE_ID: u16 = 607;
9
10pub mod encoder {
11    use message_header_codec::*;
12
13    use super::*;
14
15    #[derive(Debug, Default)]
16    pub struct OutboundAccountPositionEventEncoder<'a> {
17        buf: WriteBuf<'a>,
18        initial_offset: usize,
19        offset: usize,
20        limit: usize,
21    }
22
23    impl<'a> Writer<'a> for OutboundAccountPositionEventEncoder<'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 OutboundAccountPositionEventEncoder<'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> OutboundAccountPositionEventEncoder<'a> {
43        pub fn wrap(mut self, buf: WriteBuf<'a>, offset: usize) -> Self {
44            let limit = offset + SBE_BLOCK_LENGTH as usize;
45            self.buf = buf;
46            self.initial_offset = offset;
47            self.offset = offset;
48            self.limit = limit;
49            self
50        }
51
52        #[inline]
53        pub fn encoded_length(&self) -> usize {
54            self.limit - self.offset
55        }
56
57        pub fn header(self, offset: usize) -> MessageHeaderEncoder<Self> {
58            let mut header = MessageHeaderEncoder::default().wrap(self, offset);
59            header.block_length(SBE_BLOCK_LENGTH);
60            header.template_id(SBE_TEMPLATE_ID);
61            header.schema_id(SBE_SCHEMA_ID);
62            header.version(SBE_SCHEMA_VERSION);
63            header
64        }
65
66        /// primitive field 'eventTime'
67        /// - min value: -9223372036854775807
68        /// - max value: 9223372036854775807
69        /// - null value: -9223372036854775808_i64
70        /// - characterEncoding: null
71        /// - semanticType: null
72        /// - encodedOffset: 0
73        /// - encodedLength: 8
74        /// - version: 0
75        #[inline]
76        pub fn event_time(&mut self, value: i64) {
77            let offset = self.offset;
78            self.get_buf_mut().put_i64_at(offset, value);
79        }
80
81        /// primitive field 'updateTime'
82        /// - min value: -9223372036854775807
83        /// - max value: 9223372036854775807
84        /// - null value: -9223372036854775808_i64
85        /// - characterEncoding: null
86        /// - semanticType: null
87        /// - encodedOffset: 8
88        /// - encodedLength: 8
89        /// - version: 0
90        #[inline]
91        pub fn update_time(&mut self, value: i64) {
92            let offset = self.offset + 8;
93            self.get_buf_mut().put_i64_at(offset, value);
94        }
95
96        /// primitive field 'subscriptionId'
97        /// - min value: 0
98        /// - max value: 65534
99        /// - null value: 0xffff_u16
100        /// - characterEncoding: null
101        /// - semanticType: null
102        /// - encodedOffset: 16
103        /// - encodedLength: 2
104        /// - version: 1
105        #[inline]
106        pub fn subscription_id(&mut self, value: u16) {
107            let offset = self.offset + 16;
108            self.get_buf_mut().put_u16_at(offset, value);
109        }
110
111        /// GROUP ENCODER (id=100)
112        #[inline]
113        pub fn balances_encoder(
114            self,
115            count: u32,
116            balances_encoder: BalancesEncoder<Self>,
117        ) -> BalancesEncoder<Self> {
118            balances_encoder.wrap(self, count)
119        }
120    }
121
122    #[derive(Debug, Default)]
123    pub struct BalancesEncoder<P> {
124        parent: Option<P>,
125        count: u32,
126        index: usize,
127        offset: usize,
128        initial_limit: usize,
129    }
130
131    impl<'a, P> Writer<'a> for BalancesEncoder<P>
132    where
133        P: Writer<'a> + Default,
134    {
135        #[inline]
136        fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
137            if let Some(parent) = self.parent.as_mut() {
138                parent.get_buf_mut()
139            } else {
140                panic!("parent was None")
141            }
142        }
143    }
144
145    impl<'a, P> Encoder<'a> for BalancesEncoder<P>
146    where
147        P: Encoder<'a> + Default,
148    {
149        #[inline]
150        fn get_limit(&self) -> usize {
151            self.parent.as_ref().expect("parent missing").get_limit()
152        }
153
154        #[inline]
155        fn set_limit(&mut self, limit: usize) {
156            self.parent
157                .as_mut()
158                .expect("parent missing")
159                .set_limit(limit);
160        }
161    }
162
163    impl<'a, P> BalancesEncoder<P>
164    where
165        P: Encoder<'a> + Default,
166    {
167        #[inline]
168        pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
169            let initial_limit = parent.get_limit();
170            parent.set_limit(initial_limit + 6);
171            parent
172                .get_buf_mut()
173                .put_u16_at(initial_limit, Self::block_length());
174            parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
175            self.parent = Some(parent);
176            self.count = count;
177            self.index = usize::MAX;
178            self.offset = usize::MAX;
179            self.initial_limit = initial_limit;
180            self
181        }
182
183        #[inline]
184        pub fn block_length() -> u16 {
185            17
186        }
187
188        #[inline]
189        pub fn parent(&mut self) -> SbeResult<P> {
190            self.parent.take().ok_or(SbeErr::ParentNotSet)
191        }
192
193        /// will return Some(current index) when successful otherwise None
194        #[inline]
195        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
196            let index = self.index.wrapping_add(1);
197            if index >= self.count as usize {
198                return Ok(None);
199            }
200
201            if let Some(parent) = self.parent.as_mut() {
202                self.offset = parent.get_limit();
203                parent.set_limit(self.offset + Self::block_length() as usize);
204                self.index = index;
205                Ok(Some(index))
206            } else {
207                Err(SbeErr::ParentNotSet)
208            }
209        }
210
211        /// primitive field 'exponent'
212        /// - min value: -127
213        /// - max value: 127
214        /// - null value: -128_i8
215        /// - characterEncoding: null
216        /// - semanticType: null
217        /// - encodedOffset: 0
218        /// - encodedLength: 1
219        /// - version: 0
220        #[inline]
221        pub fn exponent(&mut self, value: i8) {
222            let offset = self.offset;
223            self.get_buf_mut().put_i8_at(offset, value);
224        }
225
226        /// primitive field 'free'
227        /// - min value: -9223372036854775807
228        /// - max value: 9223372036854775807
229        /// - null value: -9223372036854775808_i64
230        /// - characterEncoding: null
231        /// - semanticType: null
232        /// - encodedOffset: 1
233        /// - encodedLength: 8
234        /// - version: 0
235        #[inline]
236        pub fn free(&mut self, value: i64) {
237            let offset = self.offset + 1;
238            self.get_buf_mut().put_i64_at(offset, value);
239        }
240
241        /// primitive field 'locked'
242        /// - min value: -9223372036854775807
243        /// - max value: 9223372036854775807
244        /// - null value: -9223372036854775808_i64
245        /// - characterEncoding: null
246        /// - semanticType: null
247        /// - encodedOffset: 9
248        /// - encodedLength: 8
249        /// - version: 0
250        #[inline]
251        pub fn locked(&mut self, value: i64) {
252            let offset = self.offset + 9;
253            self.get_buf_mut().put_i64_at(offset, value);
254        }
255
256        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
257        #[inline]
258        pub fn asset(&mut self, value: &str) {
259            let limit = self.get_limit();
260            let data_length = value.len();
261            self.set_limit(limit + 1 + data_length);
262            self.get_buf_mut().put_u8_at(limit, data_length as u8);
263            self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
264        }
265    }
266} // end encoder
267
268pub mod decoder {
269    use message_header_codec::*;
270
271    use super::*;
272
273    #[derive(Clone, Copy, Debug, Default)]
274    pub struct OutboundAccountPositionEventDecoder<'a> {
275        buf: ReadBuf<'a>,
276        initial_offset: usize,
277        offset: usize,
278        limit: usize,
279        pub acting_block_length: u16,
280        pub acting_version: u16,
281    }
282
283    impl ActingVersion for OutboundAccountPositionEventDecoder<'_> {
284        #[inline]
285        fn acting_version(&self) -> u16 {
286            self.acting_version
287        }
288    }
289
290    impl<'a> Reader<'a> for OutboundAccountPositionEventDecoder<'a> {
291        #[inline]
292        fn get_buf(&self) -> &ReadBuf<'a> {
293            &self.buf
294        }
295    }
296
297    impl<'a> Decoder<'a> for OutboundAccountPositionEventDecoder<'a> {
298        #[inline]
299        fn get_limit(&self) -> usize {
300            self.limit
301        }
302
303        #[inline]
304        fn set_limit(&mut self, limit: usize) {
305            self.limit = limit;
306        }
307    }
308
309    impl<'a> OutboundAccountPositionEventDecoder<'a> {
310        pub fn wrap(
311            mut self,
312            buf: ReadBuf<'a>,
313            offset: usize,
314            acting_block_length: u16,
315            acting_version: u16,
316        ) -> Self {
317            let limit = offset + acting_block_length as usize;
318            self.buf = buf;
319            self.initial_offset = offset;
320            self.offset = offset;
321            self.limit = limit;
322            self.acting_block_length = acting_block_length;
323            self.acting_version = acting_version;
324            self
325        }
326
327        #[inline]
328        pub fn encoded_length(&self) -> usize {
329            self.limit - self.offset
330        }
331
332        pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
333            debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
334            let acting_block_length = header.block_length();
335            let acting_version = header.version();
336
337            self.wrap(
338                header.parent().unwrap(),
339                offset + message_header_codec::ENCODED_LENGTH,
340                acting_block_length,
341                acting_version,
342            )
343        }
344
345        /// primitive field - 'REQUIRED'
346        #[inline]
347        pub fn event_time(&self) -> i64 {
348            self.get_buf().get_i64_at(self.offset)
349        }
350
351        /// primitive field - 'REQUIRED'
352        #[inline]
353        pub fn update_time(&self) -> i64 {
354            self.get_buf().get_i64_at(self.offset + 8)
355        }
356
357        /// primitive field - 'OPTIONAL' { null_value: '0xffff_u16' }
358        #[inline]
359        pub fn subscription_id(&self) -> Option<u16> {
360            if self.acting_version() < 1 {
361                return None;
362            }
363
364            let value = self.get_buf().get_u16_at(self.offset + 16);
365            if value == 0xffff_u16 {
366                None
367            } else {
368                Some(value)
369            }
370        }
371
372        /// GROUP DECODER (id=100)
373        #[inline]
374        pub fn balances_decoder(self) -> BalancesDecoder<Self> {
375            BalancesDecoder::default().wrap(self)
376        }
377    }
378
379    #[derive(Debug, Default)]
380    pub struct BalancesDecoder<P> {
381        parent: Option<P>,
382        block_length: u16,
383        count: u32,
384        index: usize,
385        offset: usize,
386    }
387
388    impl<'a, P> ActingVersion for BalancesDecoder<P>
389    where
390        P: Reader<'a> + ActingVersion + Default,
391    {
392        #[inline]
393        fn acting_version(&self) -> u16 {
394            self.parent.as_ref().unwrap().acting_version()
395        }
396    }
397
398    impl<'a, P> Reader<'a> for BalancesDecoder<P>
399    where
400        P: Reader<'a> + Default,
401    {
402        #[inline]
403        fn get_buf(&self) -> &ReadBuf<'a> {
404            self.parent.as_ref().expect("parent missing").get_buf()
405        }
406    }
407
408    impl<'a, P> Decoder<'a> for BalancesDecoder<P>
409    where
410        P: Decoder<'a> + ActingVersion + Default,
411    {
412        #[inline]
413        fn get_limit(&self) -> usize {
414            self.parent.as_ref().expect("parent missing").get_limit()
415        }
416
417        #[inline]
418        fn set_limit(&mut self, limit: usize) {
419            self.parent
420                .as_mut()
421                .expect("parent missing")
422                .set_limit(limit);
423        }
424    }
425
426    impl<'a, P> BalancesDecoder<P>
427    where
428        P: Decoder<'a> + ActingVersion + Default,
429    {
430        pub fn wrap(mut self, mut parent: P) -> Self {
431            let initial_offset = parent.get_limit();
432            let block_length = parent.get_buf().get_u16_at(initial_offset);
433            let count = parent.get_buf().get_u32_at(initial_offset + 2);
434            parent.set_limit(initial_offset + 6);
435            self.parent = Some(parent);
436            self.block_length = block_length;
437            self.count = count;
438            self.index = usize::MAX;
439            self.offset = 0;
440            self
441        }
442
443        /// group token - Token{signal=BEGIN_GROUP, name='balances', referencedName='null', description='null', packageName='null', id=100, version=0, deprecated=0, encodedLength=17, offset=18, 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'}}
444        #[inline]
445        pub fn parent(&mut self) -> SbeResult<P> {
446            self.parent.take().ok_or(SbeErr::ParentNotSet)
447        }
448
449        #[inline]
450        pub fn acting_version(&mut self) -> u16 {
451            self.parent.as_ref().unwrap().acting_version()
452        }
453
454        #[inline]
455        pub fn count(&self) -> u32 {
456            self.count
457        }
458
459        /// will return Some(current index) when successful otherwise None
460        pub fn advance(&mut self) -> SbeResult<Option<usize>> {
461            let index = self.index.wrapping_add(1);
462            if index >= self.count as usize {
463                return Ok(None);
464            }
465
466            if let Some(parent) = self.parent.as_mut() {
467                self.offset = parent.get_limit();
468                parent.set_limit(self.offset + self.block_length as usize);
469                self.index = index;
470                Ok(Some(index))
471            } else {
472                Err(SbeErr::ParentNotSet)
473            }
474        }
475
476        /// primitive field - 'REQUIRED'
477        #[inline]
478        pub fn exponent(&self) -> i8 {
479            self.get_buf().get_i8_at(self.offset)
480        }
481
482        /// primitive field - 'REQUIRED'
483        #[inline]
484        pub fn free(&self) -> i64 {
485            self.get_buf().get_i64_at(self.offset + 1)
486        }
487
488        /// primitive field - 'REQUIRED'
489        #[inline]
490        pub fn locked(&self) -> i64 {
491            self.get_buf().get_i64_at(self.offset + 9)
492        }
493
494        /// VAR_DATA DECODER - character encoding: 'UTF-8'
495        #[inline]
496        pub fn asset_decoder(&mut self) -> (usize, usize) {
497            let offset = self.parent.as_ref().expect("parent missing").get_limit();
498            let data_length = self.get_buf().get_u8_at(offset) as usize;
499            self.parent
500                .as_mut()
501                .unwrap()
502                .set_limit(offset + 1 + data_length);
503            (offset + 1, data_length)
504        }
505
506        #[inline]
507        pub fn asset_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
508            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
509            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
510        }
511    }
512} // end decoder