Skip to main content

nautilus_binance/spot/sbe/generated/
execution_rules_response_codec.rs

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