1pub use decoder::ExchangeInfoResponseDecoder;
2pub use encoder::ExchangeInfoResponseEncoder;
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 = 103;
9
10pub mod encoder {
11 use message_header_codec::*;
12
13 use super::*;
14
15 #[derive(Debug, Default)]
16 pub struct ExchangeInfoResponseEncoder<'a> {
17 buf: WriteBuf<'a>,
18 initial_offset: usize,
19 offset: usize,
20 limit: usize,
21 }
22
23 impl<'a> Writer<'a> for ExchangeInfoResponseEncoder<'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 ExchangeInfoResponseEncoder<'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> ExchangeInfoResponseEncoder<'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 #[inline]
68 pub fn rate_limits_encoder(
69 self,
70 count: u32,
71 rate_limits_encoder: RateLimitsEncoder<Self>,
72 ) -> RateLimitsEncoder<Self> {
73 rate_limits_encoder.wrap(self, count)
74 }
75
76 #[inline]
78 pub fn exchange_filters_encoder(
79 self,
80 count: u32,
81 exchange_filters_encoder: ExchangeFiltersEncoder<Self>,
82 ) -> ExchangeFiltersEncoder<Self> {
83 exchange_filters_encoder.wrap(self, count)
84 }
85
86 #[inline]
88 pub fn symbols_encoder(
89 self,
90 count: u32,
91 symbols_encoder: SymbolsEncoder<Self>,
92 ) -> SymbolsEncoder<Self> {
93 symbols_encoder.wrap(self, count)
94 }
95
96 #[inline]
98 pub fn sors_encoder(
99 self,
100 count: u32,
101 sors_encoder: SorsEncoder<Self>,
102 ) -> SorsEncoder<Self> {
103 sors_encoder.wrap(self, count)
104 }
105 }
106
107 #[derive(Debug, Default)]
108 pub struct RateLimitsEncoder<P> {
109 parent: Option<P>,
110 count: u32,
111 index: usize,
112 offset: usize,
113 initial_limit: usize,
114 }
115
116 impl<'a, P> Writer<'a> for RateLimitsEncoder<P>
117 where
118 P: Writer<'a> + Default,
119 {
120 #[inline]
121 fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
122 if let Some(parent) = self.parent.as_mut() {
123 parent.get_buf_mut()
124 } else {
125 panic!("parent was None")
126 }
127 }
128 }
129
130 impl<'a, P> Encoder<'a> for RateLimitsEncoder<P>
131 where
132 P: Encoder<'a> + Default,
133 {
134 #[inline]
135 fn get_limit(&self) -> usize {
136 self.parent.as_ref().expect("parent missing").get_limit()
137 }
138
139 #[inline]
140 fn set_limit(&mut self, limit: usize) {
141 self.parent
142 .as_mut()
143 .expect("parent missing")
144 .set_limit(limit);
145 }
146 }
147
148 impl<'a, P> RateLimitsEncoder<P>
149 where
150 P: Encoder<'a> + Default,
151 {
152 #[inline]
153 pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
154 let initial_limit = parent.get_limit();
155 parent.set_limit(initial_limit + 6);
156 parent
157 .get_buf_mut()
158 .put_u16_at(initial_limit, Self::block_length());
159 parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
160 self.parent = Some(parent);
161 self.count = count;
162 self.index = usize::MAX;
163 self.offset = usize::MAX;
164 self.initial_limit = initial_limit;
165 self
166 }
167
168 #[inline]
169 pub fn block_length() -> u16 {
170 11
171 }
172
173 #[inline]
174 pub fn parent(&mut self) -> SbeResult<P> {
175 self.parent.take().ok_or(SbeErr::ParentNotSet)
176 }
177
178 #[inline]
180 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
181 let index = self.index.wrapping_add(1);
182 if index >= self.count as usize {
183 return Ok(None);
184 }
185
186 if let Some(parent) = self.parent.as_mut() {
187 self.offset = parent.get_limit();
188 parent.set_limit(self.offset + Self::block_length() as usize);
189 self.index = index;
190 Ok(Some(index))
191 } else {
192 Err(SbeErr::ParentNotSet)
193 }
194 }
195
196 #[inline]
198 pub fn rate_limit_type(&mut self, value: rate_limit_type::RateLimitType) {
199 let offset = self.offset;
200 self.get_buf_mut().put_u8_at(offset, value as u8)
201 }
202
203 #[inline]
205 pub fn interval(&mut self, value: rate_limit_interval::RateLimitInterval) {
206 let offset = self.offset + 1;
207 self.get_buf_mut().put_u8_at(offset, value as u8)
208 }
209
210 #[inline]
220 pub fn interval_num(&mut self, value: u8) {
221 let offset = self.offset + 2;
222 self.get_buf_mut().put_u8_at(offset, value);
223 }
224
225 #[inline]
235 pub fn rate_limit(&mut self, value: i64) {
236 let offset = self.offset + 3;
237 self.get_buf_mut().put_i64_at(offset, value);
238 }
239 }
240
241 #[derive(Debug, Default)]
242 pub struct ExchangeFiltersEncoder<P> {
243 parent: Option<P>,
244 count: u32,
245 index: usize,
246 offset: usize,
247 initial_limit: usize,
248 }
249
250 impl<'a, P> Writer<'a> for ExchangeFiltersEncoder<P>
251 where
252 P: Writer<'a> + Default,
253 {
254 #[inline]
255 fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
256 if let Some(parent) = self.parent.as_mut() {
257 parent.get_buf_mut()
258 } else {
259 panic!("parent was None")
260 }
261 }
262 }
263
264 impl<'a, P> Encoder<'a> for ExchangeFiltersEncoder<P>
265 where
266 P: Encoder<'a> + Default,
267 {
268 #[inline]
269 fn get_limit(&self) -> usize {
270 self.parent.as_ref().expect("parent missing").get_limit()
271 }
272
273 #[inline]
274 fn set_limit(&mut self, limit: usize) {
275 self.parent
276 .as_mut()
277 .expect("parent missing")
278 .set_limit(limit);
279 }
280 }
281
282 impl<'a, P> ExchangeFiltersEncoder<P>
283 where
284 P: Encoder<'a> + Default,
285 {
286 #[inline]
287 pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
288 let initial_limit = parent.get_limit();
289 parent.set_limit(initial_limit + 6);
290 parent
291 .get_buf_mut()
292 .put_u16_at(initial_limit, Self::block_length());
293 parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
294 self.parent = Some(parent);
295 self.count = count;
296 self.index = usize::MAX;
297 self.offset = usize::MAX;
298 self.initial_limit = initial_limit;
299 self
300 }
301
302 #[inline]
303 pub fn block_length() -> u16 {
304 0
305 }
306
307 #[inline]
308 pub fn parent(&mut self) -> SbeResult<P> {
309 self.parent.take().ok_or(SbeErr::ParentNotSet)
310 }
311
312 #[inline]
314 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
315 let index = self.index.wrapping_add(1);
316 if index >= self.count as usize {
317 return Ok(None);
318 }
319
320 if let Some(parent) = self.parent.as_mut() {
321 self.offset = parent.get_limit();
322 parent.set_limit(self.offset + Self::block_length() as usize);
323 self.index = index;
324 Ok(Some(index))
325 } else {
326 Err(SbeErr::ParentNotSet)
327 }
328 }
329
330 #[inline]
332 pub fn filter(&mut self, value: &[u8]) {
333 let limit = self.get_limit();
334 let data_length = value.len();
335 self.set_limit(limit + 1 + data_length);
336 self.get_buf_mut().put_u8_at(limit, data_length as u8);
337 self.get_buf_mut().put_slice_at(limit + 1, value);
338 }
339 }
340
341 #[derive(Debug, Default)]
342 pub struct SymbolsEncoder<P> {
343 parent: Option<P>,
344 count: u32,
345 index: usize,
346 offset: usize,
347 initial_limit: usize,
348 }
349
350 impl<'a, P> Writer<'a> for SymbolsEncoder<P>
351 where
352 P: Writer<'a> + Default,
353 {
354 #[inline]
355 fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
356 if let Some(parent) = self.parent.as_mut() {
357 parent.get_buf_mut()
358 } else {
359 panic!("parent was None")
360 }
361 }
362 }
363
364 impl<'a, P> Encoder<'a> for SymbolsEncoder<P>
365 where
366 P: Encoder<'a> + Default,
367 {
368 #[inline]
369 fn get_limit(&self) -> usize {
370 self.parent.as_ref().expect("parent missing").get_limit()
371 }
372
373 #[inline]
374 fn set_limit(&mut self, limit: usize) {
375 self.parent
376 .as_mut()
377 .expect("parent missing")
378 .set_limit(limit);
379 }
380 }
381
382 impl<'a, P> SymbolsEncoder<P>
383 where
384 P: Encoder<'a> + Default,
385 {
386 #[inline]
387 pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
388 let initial_limit = parent.get_limit();
389 parent.set_limit(initial_limit + 6);
390 parent
391 .get_buf_mut()
392 .put_u16_at(initial_limit, Self::block_length());
393 parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
394 self.parent = Some(parent);
395 self.count = count;
396 self.index = usize::MAX;
397 self.offset = usize::MAX;
398 self.initial_limit = initial_limit;
399 self
400 }
401
402 #[inline]
403 pub fn block_length() -> u16 {
404 19
405 }
406
407 #[inline]
408 pub fn parent(&mut self) -> SbeResult<P> {
409 self.parent.take().ok_or(SbeErr::ParentNotSet)
410 }
411
412 #[inline]
414 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
415 let index = self.index.wrapping_add(1);
416 if index >= self.count as usize {
417 return Ok(None);
418 }
419
420 if let Some(parent) = self.parent.as_mut() {
421 self.offset = parent.get_limit();
422 parent.set_limit(self.offset + Self::block_length() as usize);
423 self.index = index;
424 Ok(Some(index))
425 } else {
426 Err(SbeErr::ParentNotSet)
427 }
428 }
429
430 #[inline]
432 pub fn status(&mut self, value: symbol_status::SymbolStatus) {
433 let offset = self.offset;
434 self.get_buf_mut().put_u8_at(offset, value as u8)
435 }
436
437 #[inline]
447 pub fn base_asset_precision(&mut self, value: u8) {
448 let offset = self.offset + 1;
449 self.get_buf_mut().put_u8_at(offset, value);
450 }
451
452 #[inline]
462 pub fn quote_asset_precision(&mut self, value: u8) {
463 let offset = self.offset + 2;
464 self.get_buf_mut().put_u8_at(offset, value);
465 }
466
467 #[inline]
477 pub fn base_commission_precision(&mut self, value: u8) {
478 let offset = self.offset + 3;
479 self.get_buf_mut().put_u8_at(offset, value);
480 }
481
482 #[inline]
492 pub fn quote_commission_precision(&mut self, value: u8) {
493 let offset = self.offset + 4;
494 self.get_buf_mut().put_u8_at(offset, value);
495 }
496
497 #[inline]
498 pub fn order_types(&mut self, value: order_types::OrderTypes) {
499 let offset = self.offset + 5;
500 self.get_buf_mut().put_u16_at(offset, value.0)
501 }
502
503 #[inline]
505 pub fn iceberg_allowed(&mut self, value: bool_enum::BoolEnum) {
506 let offset = self.offset + 7;
507 self.get_buf_mut().put_u8_at(offset, value as u8)
508 }
509
510 #[inline]
512 pub fn oco_allowed(&mut self, value: bool_enum::BoolEnum) {
513 let offset = self.offset + 8;
514 self.get_buf_mut().put_u8_at(offset, value as u8)
515 }
516
517 #[inline]
519 pub fn oto_allowed(&mut self, value: bool_enum::BoolEnum) {
520 let offset = self.offset + 9;
521 self.get_buf_mut().put_u8_at(offset, value as u8)
522 }
523
524 #[inline]
526 pub fn quote_order_qty_market_allowed(&mut self, value: bool_enum::BoolEnum) {
527 let offset = self.offset + 10;
528 self.get_buf_mut().put_u8_at(offset, value as u8)
529 }
530
531 #[inline]
533 pub fn allow_trailing_stop(&mut self, value: bool_enum::BoolEnum) {
534 let offset = self.offset + 11;
535 self.get_buf_mut().put_u8_at(offset, value as u8)
536 }
537
538 #[inline]
540 pub fn cancel_replace_allowed(&mut self, value: bool_enum::BoolEnum) {
541 let offset = self.offset + 12;
542 self.get_buf_mut().put_u8_at(offset, value as u8)
543 }
544
545 #[inline]
547 pub fn amend_allowed(&mut self, value: bool_enum::BoolEnum) {
548 let offset = self.offset + 13;
549 self.get_buf_mut().put_u8_at(offset, value as u8)
550 }
551
552 #[inline]
554 pub fn is_spot_trading_allowed(&mut self, value: bool_enum::BoolEnum) {
555 let offset = self.offset + 14;
556 self.get_buf_mut().put_u8_at(offset, value as u8)
557 }
558
559 #[inline]
561 pub fn is_margin_trading_allowed(&mut self, value: bool_enum::BoolEnum) {
562 let offset = self.offset + 15;
563 self.get_buf_mut().put_u8_at(offset, value as u8)
564 }
565
566 #[inline]
568 pub fn default_self_trade_prevention_mode(
569 &mut self,
570 value: self_trade_prevention_mode::SelfTradePreventionMode,
571 ) {
572 let offset = self.offset + 16;
573 self.get_buf_mut().put_u8_at(offset, value as u8)
574 }
575
576 #[inline]
577 pub fn allowed_self_trade_prevention_modes(
578 &mut self,
579 value: allowed_self_trade_prevention_modes::AllowedSelfTradePreventionModes,
580 ) {
581 let offset = self.offset + 17;
582 self.get_buf_mut().put_u8_at(offset, value.0)
583 }
584
585 #[inline]
587 pub fn peg_instructions_allowed(&mut self, value: bool_enum::BoolEnum) {
588 let offset = self.offset + 18;
589 self.get_buf_mut().put_u8_at(offset, value as u8)
590 }
591
592 #[inline]
594 pub fn filters_encoder(
595 self,
596 count: u32,
597 filters_encoder: FiltersEncoder<Self>,
598 ) -> FiltersEncoder<Self> {
599 filters_encoder.wrap(self, count)
600 }
601
602 #[inline]
604 pub fn permission_sets_encoder(
605 self,
606 count: u32,
607 permission_sets_encoder: PermissionSetsEncoder<Self>,
608 ) -> PermissionSetsEncoder<Self> {
609 permission_sets_encoder.wrap(self, count)
610 }
611
612 #[inline]
614 pub fn symbol(&mut self, value: &str) {
615 let limit = self.get_limit();
616 let data_length = value.len();
617 self.set_limit(limit + 1 + data_length);
618 self.get_buf_mut().put_u8_at(limit, data_length as u8);
619 self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
620 }
621
622 #[inline]
624 pub fn base_asset(&mut self, value: &str) {
625 let limit = self.get_limit();
626 let data_length = value.len();
627 self.set_limit(limit + 1 + data_length);
628 self.get_buf_mut().put_u8_at(limit, data_length as u8);
629 self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
630 }
631
632 #[inline]
634 pub fn quote_asset(&mut self, value: &str) {
635 let limit = self.get_limit();
636 let data_length = value.len();
637 self.set_limit(limit + 1 + data_length);
638 self.get_buf_mut().put_u8_at(limit, data_length as u8);
639 self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
640 }
641 }
642
643 #[derive(Debug, Default)]
644 pub struct FiltersEncoder<P> {
645 parent: Option<P>,
646 count: u32,
647 index: usize,
648 offset: usize,
649 initial_limit: usize,
650 }
651
652 impl<'a, P> Writer<'a> for FiltersEncoder<P>
653 where
654 P: Writer<'a> + Default,
655 {
656 #[inline]
657 fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
658 if let Some(parent) = self.parent.as_mut() {
659 parent.get_buf_mut()
660 } else {
661 panic!("parent was None")
662 }
663 }
664 }
665
666 impl<'a, P> Encoder<'a> for FiltersEncoder<P>
667 where
668 P: Encoder<'a> + Default,
669 {
670 #[inline]
671 fn get_limit(&self) -> usize {
672 self.parent.as_ref().expect("parent missing").get_limit()
673 }
674
675 #[inline]
676 fn set_limit(&mut self, limit: usize) {
677 self.parent
678 .as_mut()
679 .expect("parent missing")
680 .set_limit(limit);
681 }
682 }
683
684 impl<'a, P> FiltersEncoder<P>
685 where
686 P: Encoder<'a> + Default,
687 {
688 #[inline]
689 pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
690 let initial_limit = parent.get_limit();
691 parent.set_limit(initial_limit + 6);
692 parent
693 .get_buf_mut()
694 .put_u16_at(initial_limit, Self::block_length());
695 parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
696 self.parent = Some(parent);
697 self.count = count;
698 self.index = usize::MAX;
699 self.offset = usize::MAX;
700 self.initial_limit = initial_limit;
701 self
702 }
703
704 #[inline]
705 pub fn block_length() -> u16 {
706 0
707 }
708
709 #[inline]
710 pub fn parent(&mut self) -> SbeResult<P> {
711 self.parent.take().ok_or(SbeErr::ParentNotSet)
712 }
713
714 #[inline]
716 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
717 let index = self.index.wrapping_add(1);
718 if index >= self.count as usize {
719 return Ok(None);
720 }
721
722 if let Some(parent) = self.parent.as_mut() {
723 self.offset = parent.get_limit();
724 parent.set_limit(self.offset + Self::block_length() as usize);
725 self.index = index;
726 Ok(Some(index))
727 } else {
728 Err(SbeErr::ParentNotSet)
729 }
730 }
731
732 #[inline]
734 pub fn filter(&mut self, value: &[u8]) {
735 let limit = self.get_limit();
736 let data_length = value.len();
737 self.set_limit(limit + 1 + data_length);
738 self.get_buf_mut().put_u8_at(limit, data_length as u8);
739 self.get_buf_mut().put_slice_at(limit + 1, value);
740 }
741 }
742
743 #[derive(Debug, Default)]
744 pub struct PermissionSetsEncoder<P> {
745 parent: Option<P>,
746 count: u32,
747 index: usize,
748 offset: usize,
749 initial_limit: usize,
750 }
751
752 impl<'a, P> Writer<'a> for PermissionSetsEncoder<P>
753 where
754 P: Writer<'a> + Default,
755 {
756 #[inline]
757 fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
758 if let Some(parent) = self.parent.as_mut() {
759 parent.get_buf_mut()
760 } else {
761 panic!("parent was None")
762 }
763 }
764 }
765
766 impl<'a, P> Encoder<'a> for PermissionSetsEncoder<P>
767 where
768 P: Encoder<'a> + Default,
769 {
770 #[inline]
771 fn get_limit(&self) -> usize {
772 self.parent.as_ref().expect("parent missing").get_limit()
773 }
774
775 #[inline]
776 fn set_limit(&mut self, limit: usize) {
777 self.parent
778 .as_mut()
779 .expect("parent missing")
780 .set_limit(limit);
781 }
782 }
783
784 impl<'a, P> PermissionSetsEncoder<P>
785 where
786 P: Encoder<'a> + Default,
787 {
788 #[inline]
789 pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
790 let initial_limit = parent.get_limit();
791 parent.set_limit(initial_limit + 6);
792 parent
793 .get_buf_mut()
794 .put_u16_at(initial_limit, Self::block_length());
795 parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
796 self.parent = Some(parent);
797 self.count = count;
798 self.index = usize::MAX;
799 self.offset = usize::MAX;
800 self.initial_limit = initial_limit;
801 self
802 }
803
804 #[inline]
805 pub fn block_length() -> u16 {
806 0
807 }
808
809 #[inline]
810 pub fn parent(&mut self) -> SbeResult<P> {
811 self.parent.take().ok_or(SbeErr::ParentNotSet)
812 }
813
814 #[inline]
816 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
817 let index = self.index.wrapping_add(1);
818 if index >= self.count as usize {
819 return Ok(None);
820 }
821
822 if let Some(parent) = self.parent.as_mut() {
823 self.offset = parent.get_limit();
824 parent.set_limit(self.offset + Self::block_length() as usize);
825 self.index = index;
826 Ok(Some(index))
827 } else {
828 Err(SbeErr::ParentNotSet)
829 }
830 }
831
832 #[inline]
834 pub fn permissions_encoder(
835 self,
836 count: u32,
837 permissions_encoder: PermissionsEncoder<Self>,
838 ) -> PermissionsEncoder<Self> {
839 permissions_encoder.wrap(self, count)
840 }
841 }
842
843 #[derive(Debug, Default)]
844 pub struct PermissionsEncoder<P> {
845 parent: Option<P>,
846 count: u32,
847 index: usize,
848 offset: usize,
849 initial_limit: usize,
850 }
851
852 impl<'a, P> Writer<'a> for PermissionsEncoder<P>
853 where
854 P: Writer<'a> + Default,
855 {
856 #[inline]
857 fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
858 if let Some(parent) = self.parent.as_mut() {
859 parent.get_buf_mut()
860 } else {
861 panic!("parent was None")
862 }
863 }
864 }
865
866 impl<'a, P> Encoder<'a> for PermissionsEncoder<P>
867 where
868 P: Encoder<'a> + Default,
869 {
870 #[inline]
871 fn get_limit(&self) -> usize {
872 self.parent.as_ref().expect("parent missing").get_limit()
873 }
874
875 #[inline]
876 fn set_limit(&mut self, limit: usize) {
877 self.parent
878 .as_mut()
879 .expect("parent missing")
880 .set_limit(limit);
881 }
882 }
883
884 impl<'a, P> PermissionsEncoder<P>
885 where
886 P: Encoder<'a> + Default,
887 {
888 #[inline]
889 pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
890 let initial_limit = parent.get_limit();
891 parent.set_limit(initial_limit + 6);
892 parent
893 .get_buf_mut()
894 .put_u16_at(initial_limit, Self::block_length());
895 parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
896 self.parent = Some(parent);
897 self.count = count;
898 self.index = usize::MAX;
899 self.offset = usize::MAX;
900 self.initial_limit = initial_limit;
901 self
902 }
903
904 #[inline]
905 pub fn block_length() -> u16 {
906 0
907 }
908
909 #[inline]
910 pub fn parent(&mut self) -> SbeResult<P> {
911 self.parent.take().ok_or(SbeErr::ParentNotSet)
912 }
913
914 #[inline]
916 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
917 let index = self.index.wrapping_add(1);
918 if index >= self.count as usize {
919 return Ok(None);
920 }
921
922 if let Some(parent) = self.parent.as_mut() {
923 self.offset = parent.get_limit();
924 parent.set_limit(self.offset + Self::block_length() as usize);
925 self.index = index;
926 Ok(Some(index))
927 } else {
928 Err(SbeErr::ParentNotSet)
929 }
930 }
931
932 #[inline]
934 pub fn permission(&mut self, value: &str) {
935 let limit = self.get_limit();
936 let data_length = value.len();
937 self.set_limit(limit + 1 + data_length);
938 self.get_buf_mut().put_u8_at(limit, data_length as u8);
939 self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
940 }
941 }
942
943 #[derive(Debug, Default)]
944 pub struct SorsEncoder<P> {
945 parent: Option<P>,
946 count: u32,
947 index: usize,
948 offset: usize,
949 initial_limit: usize,
950 }
951
952 impl<'a, P> Writer<'a> for SorsEncoder<P>
953 where
954 P: Writer<'a> + Default,
955 {
956 #[inline]
957 fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
958 if let Some(parent) = self.parent.as_mut() {
959 parent.get_buf_mut()
960 } else {
961 panic!("parent was None")
962 }
963 }
964 }
965
966 impl<'a, P> Encoder<'a> for SorsEncoder<P>
967 where
968 P: Encoder<'a> + 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> SorsEncoder<P>
985 where
986 P: Encoder<'a> + Default,
987 {
988 #[inline]
989 pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
990 let initial_limit = parent.get_limit();
991 parent.set_limit(initial_limit + 6);
992 parent
993 .get_buf_mut()
994 .put_u16_at(initial_limit, Self::block_length());
995 parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
996 self.parent = Some(parent);
997 self.count = count;
998 self.index = usize::MAX;
999 self.offset = usize::MAX;
1000 self.initial_limit = initial_limit;
1001 self
1002 }
1003
1004 #[inline]
1005 pub fn block_length() -> u16 {
1006 0
1007 }
1008
1009 #[inline]
1010 pub fn parent(&mut self) -> SbeResult<P> {
1011 self.parent.take().ok_or(SbeErr::ParentNotSet)
1012 }
1013
1014 #[inline]
1016 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
1017 let index = self.index.wrapping_add(1);
1018 if index >= self.count as usize {
1019 return Ok(None);
1020 }
1021
1022 if let Some(parent) = self.parent.as_mut() {
1023 self.offset = parent.get_limit();
1024 parent.set_limit(self.offset + Self::block_length() as usize);
1025 self.index = index;
1026 Ok(Some(index))
1027 } else {
1028 Err(SbeErr::ParentNotSet)
1029 }
1030 }
1031
1032 #[inline]
1034 pub fn sor_symbols_encoder(
1035 self,
1036 count: u32,
1037 sor_symbols_encoder: SorSymbolsEncoder<Self>,
1038 ) -> SorSymbolsEncoder<Self> {
1039 sor_symbols_encoder.wrap(self, count)
1040 }
1041
1042 #[inline]
1044 pub fn base_asset(&mut self, value: &str) {
1045 let limit = self.get_limit();
1046 let data_length = value.len();
1047 self.set_limit(limit + 1 + data_length);
1048 self.get_buf_mut().put_u8_at(limit, data_length as u8);
1049 self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
1050 }
1051 }
1052
1053 #[derive(Debug, Default)]
1054 pub struct SorSymbolsEncoder<P> {
1055 parent: Option<P>,
1056 count: u32,
1057 index: usize,
1058 offset: usize,
1059 initial_limit: usize,
1060 }
1061
1062 impl<'a, P> Writer<'a> for SorSymbolsEncoder<P>
1063 where
1064 P: Writer<'a> + Default,
1065 {
1066 #[inline]
1067 fn get_buf_mut(&mut self) -> &mut WriteBuf<'a> {
1068 if let Some(parent) = self.parent.as_mut() {
1069 parent.get_buf_mut()
1070 } else {
1071 panic!("parent was None")
1072 }
1073 }
1074 }
1075
1076 impl<'a, P> Encoder<'a> for SorSymbolsEncoder<P>
1077 where
1078 P: Encoder<'a> + Default,
1079 {
1080 #[inline]
1081 fn get_limit(&self) -> usize {
1082 self.parent.as_ref().expect("parent missing").get_limit()
1083 }
1084
1085 #[inline]
1086 fn set_limit(&mut self, limit: usize) {
1087 self.parent
1088 .as_mut()
1089 .expect("parent missing")
1090 .set_limit(limit);
1091 }
1092 }
1093
1094 impl<'a, P> SorSymbolsEncoder<P>
1095 where
1096 P: Encoder<'a> + Default,
1097 {
1098 #[inline]
1099 pub fn wrap(mut self, mut parent: P, count: u32) -> Self {
1100 let initial_limit = parent.get_limit();
1101 parent.set_limit(initial_limit + 6);
1102 parent
1103 .get_buf_mut()
1104 .put_u16_at(initial_limit, Self::block_length());
1105 parent.get_buf_mut().put_u32_at(initial_limit + 2, count);
1106 self.parent = Some(parent);
1107 self.count = count;
1108 self.index = usize::MAX;
1109 self.offset = usize::MAX;
1110 self.initial_limit = initial_limit;
1111 self
1112 }
1113
1114 #[inline]
1115 pub fn block_length() -> u16 {
1116 0
1117 }
1118
1119 #[inline]
1120 pub fn parent(&mut self) -> SbeResult<P> {
1121 self.parent.take().ok_or(SbeErr::ParentNotSet)
1122 }
1123
1124 #[inline]
1126 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
1127 let index = self.index.wrapping_add(1);
1128 if index >= self.count as usize {
1129 return Ok(None);
1130 }
1131
1132 if let Some(parent) = self.parent.as_mut() {
1133 self.offset = parent.get_limit();
1134 parent.set_limit(self.offset + Self::block_length() as usize);
1135 self.index = index;
1136 Ok(Some(index))
1137 } else {
1138 Err(SbeErr::ParentNotSet)
1139 }
1140 }
1141
1142 #[inline]
1144 pub fn symbol(&mut self, value: &str) {
1145 let limit = self.get_limit();
1146 let data_length = value.len();
1147 self.set_limit(limit + 1 + data_length);
1148 self.get_buf_mut().put_u8_at(limit, data_length as u8);
1149 self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
1150 }
1151 }
1152} pub mod decoder {
1155 use message_header_codec::*;
1156
1157 use super::*;
1158
1159 #[derive(Clone, Copy, Debug, Default)]
1160 pub struct ExchangeInfoResponseDecoder<'a> {
1161 buf: ReadBuf<'a>,
1162 initial_offset: usize,
1163 offset: usize,
1164 limit: usize,
1165 pub acting_block_length: u16,
1166 pub acting_version: u16,
1167 }
1168
1169 impl ActingVersion for ExchangeInfoResponseDecoder<'_> {
1170 #[inline]
1171 fn acting_version(&self) -> u16 {
1172 self.acting_version
1173 }
1174 }
1175
1176 impl<'a> Reader<'a> for ExchangeInfoResponseDecoder<'a> {
1177 #[inline]
1178 fn get_buf(&self) -> &ReadBuf<'a> {
1179 &self.buf
1180 }
1181 }
1182
1183 impl<'a> Decoder<'a> for ExchangeInfoResponseDecoder<'a> {
1184 #[inline]
1185 fn get_limit(&self) -> usize {
1186 self.limit
1187 }
1188
1189 #[inline]
1190 fn set_limit(&mut self, limit: usize) {
1191 self.limit = limit;
1192 }
1193 }
1194
1195 impl<'a> ExchangeInfoResponseDecoder<'a> {
1196 pub fn wrap(
1197 mut self,
1198 buf: ReadBuf<'a>,
1199 offset: usize,
1200 acting_block_length: u16,
1201 acting_version: u16,
1202 ) -> Self {
1203 let limit = offset + acting_block_length as usize;
1204 self.buf = buf;
1205 self.initial_offset = offset;
1206 self.offset = offset;
1207 self.limit = limit;
1208 self.acting_block_length = acting_block_length;
1209 self.acting_version = acting_version;
1210 self
1211 }
1212
1213 #[inline]
1214 pub fn encoded_length(&self) -> usize {
1215 self.limit - self.offset
1216 }
1217
1218 pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
1219 debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
1220 let acting_block_length = header.block_length();
1221 let acting_version = header.version();
1222
1223 self.wrap(
1224 header.parent().unwrap(),
1225 offset + message_header_codec::ENCODED_LENGTH,
1226 acting_block_length,
1227 acting_version,
1228 )
1229 }
1230
1231 #[inline]
1233 pub fn rate_limits_decoder(self) -> RateLimitsDecoder<Self> {
1234 RateLimitsDecoder::default().wrap(self)
1235 }
1236
1237 #[inline]
1239 pub fn exchange_filters_decoder(self) -> ExchangeFiltersDecoder<Self> {
1240 ExchangeFiltersDecoder::default().wrap(self)
1241 }
1242
1243 #[inline]
1245 pub fn symbols_decoder(self) -> SymbolsDecoder<Self> {
1246 SymbolsDecoder::default().wrap(self)
1247 }
1248
1249 #[inline]
1251 pub fn sors_decoder(self) -> SorsDecoder<Self> {
1252 SorsDecoder::default().wrap(self)
1253 }
1254 }
1255
1256 #[derive(Debug, Default)]
1257 pub struct RateLimitsDecoder<P> {
1258 parent: Option<P>,
1259 block_length: u16,
1260 count: u32,
1261 index: usize,
1262 offset: usize,
1263 }
1264
1265 impl<'a, P> ActingVersion for RateLimitsDecoder<P>
1266 where
1267 P: Reader<'a> + ActingVersion + Default,
1268 {
1269 #[inline]
1270 fn acting_version(&self) -> u16 {
1271 self.parent.as_ref().unwrap().acting_version()
1272 }
1273 }
1274
1275 impl<'a, P> Reader<'a> for RateLimitsDecoder<P>
1276 where
1277 P: Reader<'a> + Default,
1278 {
1279 #[inline]
1280 fn get_buf(&self) -> &ReadBuf<'a> {
1281 self.parent.as_ref().expect("parent missing").get_buf()
1282 }
1283 }
1284
1285 impl<'a, P> Decoder<'a> for RateLimitsDecoder<P>
1286 where
1287 P: Decoder<'a> + ActingVersion + Default,
1288 {
1289 #[inline]
1290 fn get_limit(&self) -> usize {
1291 self.parent.as_ref().expect("parent missing").get_limit()
1292 }
1293
1294 #[inline]
1295 fn set_limit(&mut self, limit: usize) {
1296 self.parent
1297 .as_mut()
1298 .expect("parent missing")
1299 .set_limit(limit);
1300 }
1301 }
1302
1303 impl<'a, P> RateLimitsDecoder<P>
1304 where
1305 P: Decoder<'a> + ActingVersion + Default,
1306 {
1307 pub fn wrap(mut self, mut parent: P) -> Self {
1308 let initial_offset = parent.get_limit();
1309 let block_length = parent.get_buf().get_u16_at(initial_offset);
1310 let count = parent.get_buf().get_u32_at(initial_offset + 2);
1311 parent.set_limit(initial_offset + 6);
1312 self.parent = Some(parent);
1313 self.block_length = block_length;
1314 self.count = count;
1315 self.index = usize::MAX;
1316 self.offset = 0;
1317 self
1318 }
1319
1320 #[inline]
1322 pub fn parent(&mut self) -> SbeResult<P> {
1323 self.parent.take().ok_or(SbeErr::ParentNotSet)
1324 }
1325
1326 #[inline]
1327 pub fn acting_version(&mut self) -> u16 {
1328 self.parent.as_ref().unwrap().acting_version()
1329 }
1330
1331 #[inline]
1332 pub fn count(&self) -> u32 {
1333 self.count
1334 }
1335
1336 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
1338 let index = self.index.wrapping_add(1);
1339 if index >= self.count as usize {
1340 return Ok(None);
1341 }
1342
1343 if let Some(parent) = self.parent.as_mut() {
1344 self.offset = parent.get_limit();
1345 parent.set_limit(self.offset + self.block_length as usize);
1346 self.index = index;
1347 Ok(Some(index))
1348 } else {
1349 Err(SbeErr::ParentNotSet)
1350 }
1351 }
1352
1353 #[inline]
1355 pub fn rate_limit_type(&self) -> rate_limit_type::RateLimitType {
1356 self.get_buf().get_u8_at(self.offset).into()
1357 }
1358
1359 #[inline]
1361 pub fn interval(&self) -> rate_limit_interval::RateLimitInterval {
1362 self.get_buf().get_u8_at(self.offset + 1).into()
1363 }
1364
1365 #[inline]
1367 pub fn interval_num(&self) -> u8 {
1368 self.get_buf().get_u8_at(self.offset + 2)
1369 }
1370
1371 #[inline]
1373 pub fn rate_limit(&self) -> i64 {
1374 self.get_buf().get_i64_at(self.offset + 3)
1375 }
1376 }
1377
1378 #[derive(Debug, Default)]
1379 pub struct ExchangeFiltersDecoder<P> {
1380 parent: Option<P>,
1381 block_length: u16,
1382 count: u32,
1383 index: usize,
1384 offset: usize,
1385 }
1386
1387 impl<'a, P> ActingVersion for ExchangeFiltersDecoder<P>
1388 where
1389 P: Reader<'a> + ActingVersion + Default,
1390 {
1391 #[inline]
1392 fn acting_version(&self) -> u16 {
1393 self.parent.as_ref().unwrap().acting_version()
1394 }
1395 }
1396
1397 impl<'a, P> Reader<'a> for ExchangeFiltersDecoder<P>
1398 where
1399 P: Reader<'a> + Default,
1400 {
1401 #[inline]
1402 fn get_buf(&self) -> &ReadBuf<'a> {
1403 self.parent.as_ref().expect("parent missing").get_buf()
1404 }
1405 }
1406
1407 impl<'a, P> Decoder<'a> for ExchangeFiltersDecoder<P>
1408 where
1409 P: Decoder<'a> + ActingVersion + Default,
1410 {
1411 #[inline]
1412 fn get_limit(&self) -> usize {
1413 self.parent.as_ref().expect("parent missing").get_limit()
1414 }
1415
1416 #[inline]
1417 fn set_limit(&mut self, limit: usize) {
1418 self.parent
1419 .as_mut()
1420 .expect("parent missing")
1421 .set_limit(limit);
1422 }
1423 }
1424
1425 impl<'a, P> ExchangeFiltersDecoder<P>
1426 where
1427 P: Decoder<'a> + ActingVersion + Default,
1428 {
1429 pub fn wrap(mut self, mut parent: P) -> Self {
1430 let initial_offset = parent.get_limit();
1431 let block_length = parent.get_buf().get_u16_at(initial_offset);
1432 let count = parent.get_buf().get_u32_at(initial_offset + 2);
1433 parent.set_limit(initial_offset + 6);
1434 self.parent = Some(parent);
1435 self.block_length = block_length;
1436 self.count = count;
1437 self.index = usize::MAX;
1438 self.offset = 0;
1439 self
1440 }
1441
1442 #[inline]
1444 pub fn parent(&mut self) -> SbeResult<P> {
1445 self.parent.take().ok_or(SbeErr::ParentNotSet)
1446 }
1447
1448 #[inline]
1449 pub fn acting_version(&mut self) -> u16 {
1450 self.parent.as_ref().unwrap().acting_version()
1451 }
1452
1453 #[inline]
1454 pub fn count(&self) -> u32 {
1455 self.count
1456 }
1457
1458 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
1460 let index = self.index.wrapping_add(1);
1461 if index >= self.count as usize {
1462 return Ok(None);
1463 }
1464
1465 if let Some(parent) = self.parent.as_mut() {
1466 self.offset = parent.get_limit();
1467 parent.set_limit(self.offset + self.block_length as usize);
1468 self.index = index;
1469 Ok(Some(index))
1470 } else {
1471 Err(SbeErr::ParentNotSet)
1472 }
1473 }
1474
1475 #[inline]
1477 pub fn filter_decoder(&mut self) -> (usize, usize) {
1478 let offset = self.parent.as_ref().expect("parent missing").get_limit();
1479 let data_length = self.get_buf().get_u8_at(offset) as usize;
1480 self.parent
1481 .as_mut()
1482 .unwrap()
1483 .set_limit(offset + 1 + data_length);
1484 (offset + 1, data_length)
1485 }
1486
1487 #[inline]
1488 pub fn filter_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
1489 debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
1490 self.get_buf().get_slice_at(coordinates.0, coordinates.1)
1491 }
1492 }
1493
1494 #[derive(Debug, Default)]
1495 pub struct SymbolsDecoder<P> {
1496 parent: Option<P>,
1497 block_length: u16,
1498 count: u32,
1499 index: usize,
1500 offset: usize,
1501 }
1502
1503 impl<'a, P> ActingVersion for SymbolsDecoder<P>
1504 where
1505 P: Reader<'a> + ActingVersion + Default,
1506 {
1507 #[inline]
1508 fn acting_version(&self) -> u16 {
1509 self.parent.as_ref().unwrap().acting_version()
1510 }
1511 }
1512
1513 impl<'a, P> Reader<'a> for SymbolsDecoder<P>
1514 where
1515 P: Reader<'a> + Default,
1516 {
1517 #[inline]
1518 fn get_buf(&self) -> &ReadBuf<'a> {
1519 self.parent.as_ref().expect("parent missing").get_buf()
1520 }
1521 }
1522
1523 impl<'a, P> Decoder<'a> for SymbolsDecoder<P>
1524 where
1525 P: Decoder<'a> + ActingVersion + Default,
1526 {
1527 #[inline]
1528 fn get_limit(&self) -> usize {
1529 self.parent.as_ref().expect("parent missing").get_limit()
1530 }
1531
1532 #[inline]
1533 fn set_limit(&mut self, limit: usize) {
1534 self.parent
1535 .as_mut()
1536 .expect("parent missing")
1537 .set_limit(limit);
1538 }
1539 }
1540
1541 impl<'a, P> SymbolsDecoder<P>
1542 where
1543 P: Decoder<'a> + ActingVersion + Default,
1544 {
1545 pub fn wrap(mut self, mut parent: P) -> Self {
1546 let initial_offset = parent.get_limit();
1547 let block_length = parent.get_buf().get_u16_at(initial_offset);
1548 let count = parent.get_buf().get_u32_at(initial_offset + 2);
1549 parent.set_limit(initial_offset + 6);
1550 self.parent = Some(parent);
1551 self.block_length = block_length;
1552 self.count = count;
1553 self.index = usize::MAX;
1554 self.offset = 0;
1555 self
1556 }
1557
1558 #[inline]
1560 pub fn parent(&mut self) -> SbeResult<P> {
1561 self.parent.take().ok_or(SbeErr::ParentNotSet)
1562 }
1563
1564 #[inline]
1565 pub fn acting_version(&mut self) -> u16 {
1566 self.parent.as_ref().unwrap().acting_version()
1567 }
1568
1569 #[inline]
1570 pub fn count(&self) -> u32 {
1571 self.count
1572 }
1573
1574 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
1576 let index = self.index.wrapping_add(1);
1577 if index >= self.count as usize {
1578 return Ok(None);
1579 }
1580
1581 if let Some(parent) = self.parent.as_mut() {
1582 self.offset = parent.get_limit();
1583 parent.set_limit(self.offset + self.block_length as usize);
1584 self.index = index;
1585 Ok(Some(index))
1586 } else {
1587 Err(SbeErr::ParentNotSet)
1588 }
1589 }
1590
1591 #[inline]
1593 pub fn status(&self) -> symbol_status::SymbolStatus {
1594 self.get_buf().get_u8_at(self.offset).into()
1595 }
1596
1597 #[inline]
1599 pub fn base_asset_precision(&self) -> u8 {
1600 self.get_buf().get_u8_at(self.offset + 1)
1601 }
1602
1603 #[inline]
1605 pub fn quote_asset_precision(&self) -> u8 {
1606 self.get_buf().get_u8_at(self.offset + 2)
1607 }
1608
1609 #[inline]
1611 pub fn base_commission_precision(&self) -> u8 {
1612 self.get_buf().get_u8_at(self.offset + 3)
1613 }
1614
1615 #[inline]
1617 pub fn quote_commission_precision(&self) -> u8 {
1618 self.get_buf().get_u8_at(self.offset + 4)
1619 }
1620
1621 #[inline]
1623 pub fn order_types(&self) -> order_types::OrderTypes {
1624 order_types::OrderTypes::new(self.get_buf().get_u16_at(self.offset + 5))
1625 }
1626
1627 #[inline]
1629 pub fn iceberg_allowed(&self) -> bool_enum::BoolEnum {
1630 self.get_buf().get_u8_at(self.offset + 7).into()
1631 }
1632
1633 #[inline]
1635 pub fn oco_allowed(&self) -> bool_enum::BoolEnum {
1636 self.get_buf().get_u8_at(self.offset + 8).into()
1637 }
1638
1639 #[inline]
1641 pub fn oto_allowed(&self) -> bool_enum::BoolEnum {
1642 self.get_buf().get_u8_at(self.offset + 9).into()
1643 }
1644
1645 #[inline]
1647 pub fn quote_order_qty_market_allowed(&self) -> bool_enum::BoolEnum {
1648 self.get_buf().get_u8_at(self.offset + 10).into()
1649 }
1650
1651 #[inline]
1653 pub fn allow_trailing_stop(&self) -> bool_enum::BoolEnum {
1654 self.get_buf().get_u8_at(self.offset + 11).into()
1655 }
1656
1657 #[inline]
1659 pub fn cancel_replace_allowed(&self) -> bool_enum::BoolEnum {
1660 self.get_buf().get_u8_at(self.offset + 12).into()
1661 }
1662
1663 #[inline]
1665 pub fn amend_allowed(&self) -> bool_enum::BoolEnum {
1666 self.get_buf().get_u8_at(self.offset + 13).into()
1667 }
1668
1669 #[inline]
1671 pub fn is_spot_trading_allowed(&self) -> bool_enum::BoolEnum {
1672 self.get_buf().get_u8_at(self.offset + 14).into()
1673 }
1674
1675 #[inline]
1677 pub fn is_margin_trading_allowed(&self) -> bool_enum::BoolEnum {
1678 self.get_buf().get_u8_at(self.offset + 15).into()
1679 }
1680
1681 #[inline]
1683 pub fn default_self_trade_prevention_mode(
1684 &self,
1685 ) -> self_trade_prevention_mode::SelfTradePreventionMode {
1686 self.get_buf().get_u8_at(self.offset + 16).into()
1687 }
1688
1689 #[inline]
1691 pub fn allowed_self_trade_prevention_modes(
1692 &self,
1693 ) -> allowed_self_trade_prevention_modes::AllowedSelfTradePreventionModes {
1694 allowed_self_trade_prevention_modes::AllowedSelfTradePreventionModes::new(
1695 self.get_buf().get_u8_at(self.offset + 17),
1696 )
1697 }
1698
1699 #[inline]
1701 pub fn peg_instructions_allowed(&self) -> bool_enum::BoolEnum {
1702 if self.acting_version() < 1 {
1703 return bool_enum::BoolEnum::default();
1704 }
1705
1706 self.get_buf().get_u8_at(self.offset + 18).into()
1707 }
1708
1709 #[inline]
1711 pub fn filters_decoder(self) -> FiltersDecoder<Self> {
1712 FiltersDecoder::default().wrap(self)
1713 }
1714
1715 #[inline]
1717 pub fn permission_sets_decoder(self) -> PermissionSetsDecoder<Self> {
1718 PermissionSetsDecoder::default().wrap(self)
1719 }
1720
1721 #[inline]
1723 pub fn symbol_decoder(&mut self) -> (usize, usize) {
1724 let offset = self.parent.as_ref().expect("parent missing").get_limit();
1725 let data_length = self.get_buf().get_u8_at(offset) as usize;
1726 self.parent
1727 .as_mut()
1728 .unwrap()
1729 .set_limit(offset + 1 + data_length);
1730 (offset + 1, data_length)
1731 }
1732
1733 #[inline]
1734 pub fn symbol_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
1735 debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
1736 self.get_buf().get_slice_at(coordinates.0, coordinates.1)
1737 }
1738
1739 #[inline]
1741 pub fn base_asset_decoder(&mut self) -> (usize, usize) {
1742 let offset = self.parent.as_ref().expect("parent missing").get_limit();
1743 let data_length = self.get_buf().get_u8_at(offset) as usize;
1744 self.parent
1745 .as_mut()
1746 .unwrap()
1747 .set_limit(offset + 1 + data_length);
1748 (offset + 1, data_length)
1749 }
1750
1751 #[inline]
1752 pub fn base_asset_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
1753 debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
1754 self.get_buf().get_slice_at(coordinates.0, coordinates.1)
1755 }
1756
1757 #[inline]
1759 pub fn quote_asset_decoder(&mut self) -> (usize, usize) {
1760 let offset = self.parent.as_ref().expect("parent missing").get_limit();
1761 let data_length = self.get_buf().get_u8_at(offset) as usize;
1762 self.parent
1763 .as_mut()
1764 .unwrap()
1765 .set_limit(offset + 1 + data_length);
1766 (offset + 1, data_length)
1767 }
1768
1769 #[inline]
1770 pub fn quote_asset_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
1771 debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
1772 self.get_buf().get_slice_at(coordinates.0, coordinates.1)
1773 }
1774 }
1775
1776 #[derive(Debug, Default)]
1777 pub struct FiltersDecoder<P> {
1778 parent: Option<P>,
1779 block_length: u16,
1780 count: u32,
1781 index: usize,
1782 offset: usize,
1783 }
1784
1785 impl<'a, P> ActingVersion for FiltersDecoder<P>
1786 where
1787 P: Reader<'a> + ActingVersion + Default,
1788 {
1789 #[inline]
1790 fn acting_version(&self) -> u16 {
1791 self.parent.as_ref().unwrap().acting_version()
1792 }
1793 }
1794
1795 impl<'a, P> Reader<'a> for FiltersDecoder<P>
1796 where
1797 P: Reader<'a> + Default,
1798 {
1799 #[inline]
1800 fn get_buf(&self) -> &ReadBuf<'a> {
1801 self.parent.as_ref().expect("parent missing").get_buf()
1802 }
1803 }
1804
1805 impl<'a, P> Decoder<'a> for FiltersDecoder<P>
1806 where
1807 P: Decoder<'a> + ActingVersion + Default,
1808 {
1809 #[inline]
1810 fn get_limit(&self) -> usize {
1811 self.parent.as_ref().expect("parent missing").get_limit()
1812 }
1813
1814 #[inline]
1815 fn set_limit(&mut self, limit: usize) {
1816 self.parent
1817 .as_mut()
1818 .expect("parent missing")
1819 .set_limit(limit);
1820 }
1821 }
1822
1823 impl<'a, P> FiltersDecoder<P>
1824 where
1825 P: Decoder<'a> + ActingVersion + Default,
1826 {
1827 pub fn wrap(mut self, mut parent: P) -> Self {
1828 let initial_offset = parent.get_limit();
1829 let block_length = parent.get_buf().get_u16_at(initial_offset);
1830 let count = parent.get_buf().get_u32_at(initial_offset + 2);
1831 parent.set_limit(initial_offset + 6);
1832 self.parent = Some(parent);
1833 self.block_length = block_length;
1834 self.count = count;
1835 self.index = usize::MAX;
1836 self.offset = 0;
1837 self
1838 }
1839
1840 #[inline]
1842 pub fn parent(&mut self) -> SbeResult<P> {
1843 self.parent.take().ok_or(SbeErr::ParentNotSet)
1844 }
1845
1846 #[inline]
1847 pub fn acting_version(&mut self) -> u16 {
1848 self.parent.as_ref().unwrap().acting_version()
1849 }
1850
1851 #[inline]
1852 pub fn count(&self) -> u32 {
1853 self.count
1854 }
1855
1856 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
1858 let index = self.index.wrapping_add(1);
1859 if index >= self.count as usize {
1860 return Ok(None);
1861 }
1862
1863 if let Some(parent) = self.parent.as_mut() {
1864 self.offset = parent.get_limit();
1865 parent.set_limit(self.offset + self.block_length as usize);
1866 self.index = index;
1867 Ok(Some(index))
1868 } else {
1869 Err(SbeErr::ParentNotSet)
1870 }
1871 }
1872
1873 #[inline]
1875 pub fn filter_decoder(&mut self) -> (usize, usize) {
1876 let offset = self.parent.as_ref().expect("parent missing").get_limit();
1877 let data_length = self.get_buf().get_u8_at(offset) as usize;
1878 self.parent
1879 .as_mut()
1880 .unwrap()
1881 .set_limit(offset + 1 + data_length);
1882 (offset + 1, data_length)
1883 }
1884
1885 #[inline]
1886 pub fn filter_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
1887 debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
1888 self.get_buf().get_slice_at(coordinates.0, coordinates.1)
1889 }
1890 }
1891
1892 #[derive(Debug, Default)]
1893 pub struct PermissionSetsDecoder<P> {
1894 parent: Option<P>,
1895 block_length: u16,
1896 count: u32,
1897 index: usize,
1898 offset: usize,
1899 }
1900
1901 impl<'a, P> ActingVersion for PermissionSetsDecoder<P>
1902 where
1903 P: Reader<'a> + ActingVersion + Default,
1904 {
1905 #[inline]
1906 fn acting_version(&self) -> u16 {
1907 self.parent.as_ref().unwrap().acting_version()
1908 }
1909 }
1910
1911 impl<'a, P> Reader<'a> for PermissionSetsDecoder<P>
1912 where
1913 P: Reader<'a> + Default,
1914 {
1915 #[inline]
1916 fn get_buf(&self) -> &ReadBuf<'a> {
1917 self.parent.as_ref().expect("parent missing").get_buf()
1918 }
1919 }
1920
1921 impl<'a, P> Decoder<'a> for PermissionSetsDecoder<P>
1922 where
1923 P: Decoder<'a> + ActingVersion + Default,
1924 {
1925 #[inline]
1926 fn get_limit(&self) -> usize {
1927 self.parent.as_ref().expect("parent missing").get_limit()
1928 }
1929
1930 #[inline]
1931 fn set_limit(&mut self, limit: usize) {
1932 self.parent
1933 .as_mut()
1934 .expect("parent missing")
1935 .set_limit(limit);
1936 }
1937 }
1938
1939 impl<'a, P> PermissionSetsDecoder<P>
1940 where
1941 P: Decoder<'a> + ActingVersion + Default,
1942 {
1943 pub fn wrap(mut self, mut parent: P) -> Self {
1944 let initial_offset = parent.get_limit();
1945 let block_length = parent.get_buf().get_u16_at(initial_offset);
1946 let count = parent.get_buf().get_u32_at(initial_offset + 2);
1947 parent.set_limit(initial_offset + 6);
1948 self.parent = Some(parent);
1949 self.block_length = block_length;
1950 self.count = count;
1951 self.index = usize::MAX;
1952 self.offset = 0;
1953 self
1954 }
1955
1956 #[inline]
1958 pub fn parent(&mut self) -> SbeResult<P> {
1959 self.parent.take().ok_or(SbeErr::ParentNotSet)
1960 }
1961
1962 #[inline]
1963 pub fn acting_version(&mut self) -> u16 {
1964 self.parent.as_ref().unwrap().acting_version()
1965 }
1966
1967 #[inline]
1968 pub fn count(&self) -> u32 {
1969 self.count
1970 }
1971
1972 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
1974 let index = self.index.wrapping_add(1);
1975 if index >= self.count as usize {
1976 return Ok(None);
1977 }
1978
1979 if let Some(parent) = self.parent.as_mut() {
1980 self.offset = parent.get_limit();
1981 parent.set_limit(self.offset + self.block_length as usize);
1982 self.index = index;
1983 Ok(Some(index))
1984 } else {
1985 Err(SbeErr::ParentNotSet)
1986 }
1987 }
1988
1989 #[inline]
1991 pub fn permissions_decoder(self) -> PermissionsDecoder<Self> {
1992 PermissionsDecoder::default().wrap(self)
1993 }
1994 }
1995
1996 #[derive(Debug, Default)]
1997 pub struct PermissionsDecoder<P> {
1998 parent: Option<P>,
1999 block_length: u16,
2000 count: u32,
2001 index: usize,
2002 offset: usize,
2003 }
2004
2005 impl<'a, P> ActingVersion for PermissionsDecoder<P>
2006 where
2007 P: Reader<'a> + ActingVersion + Default,
2008 {
2009 #[inline]
2010 fn acting_version(&self) -> u16 {
2011 self.parent.as_ref().unwrap().acting_version()
2012 }
2013 }
2014
2015 impl<'a, P> Reader<'a> for PermissionsDecoder<P>
2016 where
2017 P: Reader<'a> + Default,
2018 {
2019 #[inline]
2020 fn get_buf(&self) -> &ReadBuf<'a> {
2021 self.parent.as_ref().expect("parent missing").get_buf()
2022 }
2023 }
2024
2025 impl<'a, P> Decoder<'a> for PermissionsDecoder<P>
2026 where
2027 P: Decoder<'a> + ActingVersion + Default,
2028 {
2029 #[inline]
2030 fn get_limit(&self) -> usize {
2031 self.parent.as_ref().expect("parent missing").get_limit()
2032 }
2033
2034 #[inline]
2035 fn set_limit(&mut self, limit: usize) {
2036 self.parent
2037 .as_mut()
2038 .expect("parent missing")
2039 .set_limit(limit);
2040 }
2041 }
2042
2043 impl<'a, P> PermissionsDecoder<P>
2044 where
2045 P: Decoder<'a> + ActingVersion + Default,
2046 {
2047 pub fn wrap(mut self, mut parent: P) -> Self {
2048 let initial_offset = parent.get_limit();
2049 let block_length = parent.get_buf().get_u16_at(initial_offset);
2050 let count = parent.get_buf().get_u32_at(initial_offset + 2);
2051 parent.set_limit(initial_offset + 6);
2052 self.parent = Some(parent);
2053 self.block_length = block_length;
2054 self.count = count;
2055 self.index = usize::MAX;
2056 self.offset = 0;
2057 self
2058 }
2059
2060 #[inline]
2062 pub fn parent(&mut self) -> SbeResult<P> {
2063 self.parent.take().ok_or(SbeErr::ParentNotSet)
2064 }
2065
2066 #[inline]
2067 pub fn acting_version(&mut self) -> u16 {
2068 self.parent.as_ref().unwrap().acting_version()
2069 }
2070
2071 #[inline]
2072 pub fn count(&self) -> u32 {
2073 self.count
2074 }
2075
2076 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
2078 let index = self.index.wrapping_add(1);
2079 if index >= self.count as usize {
2080 return Ok(None);
2081 }
2082
2083 if let Some(parent) = self.parent.as_mut() {
2084 self.offset = parent.get_limit();
2085 parent.set_limit(self.offset + self.block_length as usize);
2086 self.index = index;
2087 Ok(Some(index))
2088 } else {
2089 Err(SbeErr::ParentNotSet)
2090 }
2091 }
2092
2093 #[inline]
2095 pub fn permission_decoder(&mut self) -> (usize, usize) {
2096 let offset = self.parent.as_ref().expect("parent missing").get_limit();
2097 let data_length = self.get_buf().get_u8_at(offset) as usize;
2098 self.parent
2099 .as_mut()
2100 .unwrap()
2101 .set_limit(offset + 1 + data_length);
2102 (offset + 1, data_length)
2103 }
2104
2105 #[inline]
2106 pub fn permission_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
2107 debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
2108 self.get_buf().get_slice_at(coordinates.0, coordinates.1)
2109 }
2110 }
2111
2112 #[derive(Debug, Default)]
2113 pub struct SorsDecoder<P> {
2114 parent: Option<P>,
2115 block_length: u16,
2116 count: u32,
2117 index: usize,
2118 offset: usize,
2119 }
2120
2121 impl<'a, P> ActingVersion for SorsDecoder<P>
2122 where
2123 P: Reader<'a> + ActingVersion + Default,
2124 {
2125 #[inline]
2126 fn acting_version(&self) -> u16 {
2127 self.parent.as_ref().unwrap().acting_version()
2128 }
2129 }
2130
2131 impl<'a, P> Reader<'a> for SorsDecoder<P>
2132 where
2133 P: Reader<'a> + Default,
2134 {
2135 #[inline]
2136 fn get_buf(&self) -> &ReadBuf<'a> {
2137 self.parent.as_ref().expect("parent missing").get_buf()
2138 }
2139 }
2140
2141 impl<'a, P> Decoder<'a> for SorsDecoder<P>
2142 where
2143 P: Decoder<'a> + ActingVersion + Default,
2144 {
2145 #[inline]
2146 fn get_limit(&self) -> usize {
2147 self.parent.as_ref().expect("parent missing").get_limit()
2148 }
2149
2150 #[inline]
2151 fn set_limit(&mut self, limit: usize) {
2152 self.parent
2153 .as_mut()
2154 .expect("parent missing")
2155 .set_limit(limit);
2156 }
2157 }
2158
2159 impl<'a, P> SorsDecoder<P>
2160 where
2161 P: Decoder<'a> + ActingVersion + Default,
2162 {
2163 pub fn wrap(mut self, mut parent: P) -> Self {
2164 let initial_offset = parent.get_limit();
2165 let block_length = parent.get_buf().get_u16_at(initial_offset);
2166 let count = parent.get_buf().get_u32_at(initial_offset + 2);
2167 parent.set_limit(initial_offset + 6);
2168 self.parent = Some(parent);
2169 self.block_length = block_length;
2170 self.count = count;
2171 self.index = usize::MAX;
2172 self.offset = 0;
2173 self
2174 }
2175
2176 #[inline]
2178 pub fn parent(&mut self) -> SbeResult<P> {
2179 self.parent.take().ok_or(SbeErr::ParentNotSet)
2180 }
2181
2182 #[inline]
2183 pub fn acting_version(&mut self) -> u16 {
2184 self.parent.as_ref().unwrap().acting_version()
2185 }
2186
2187 #[inline]
2188 pub fn count(&self) -> u32 {
2189 self.count
2190 }
2191
2192 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
2194 let index = self.index.wrapping_add(1);
2195 if index >= self.count as usize {
2196 return Ok(None);
2197 }
2198
2199 if let Some(parent) = self.parent.as_mut() {
2200 self.offset = parent.get_limit();
2201 parent.set_limit(self.offset + self.block_length as usize);
2202 self.index = index;
2203 Ok(Some(index))
2204 } else {
2205 Err(SbeErr::ParentNotSet)
2206 }
2207 }
2208
2209 #[inline]
2211 pub fn sor_symbols_decoder(self) -> SorSymbolsDecoder<Self> {
2212 SorSymbolsDecoder::default().wrap(self)
2213 }
2214
2215 #[inline]
2217 pub fn base_asset_decoder(&mut self) -> (usize, usize) {
2218 let offset = self.parent.as_ref().expect("parent missing").get_limit();
2219 let data_length = self.get_buf().get_u8_at(offset) as usize;
2220 self.parent
2221 .as_mut()
2222 .unwrap()
2223 .set_limit(offset + 1 + data_length);
2224 (offset + 1, data_length)
2225 }
2226
2227 #[inline]
2228 pub fn base_asset_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
2229 debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
2230 self.get_buf().get_slice_at(coordinates.0, coordinates.1)
2231 }
2232 }
2233
2234 #[derive(Debug, Default)]
2235 pub struct SorSymbolsDecoder<P> {
2236 parent: Option<P>,
2237 block_length: u16,
2238 count: u32,
2239 index: usize,
2240 offset: usize,
2241 }
2242
2243 impl<'a, P> ActingVersion for SorSymbolsDecoder<P>
2244 where
2245 P: Reader<'a> + ActingVersion + Default,
2246 {
2247 #[inline]
2248 fn acting_version(&self) -> u16 {
2249 self.parent.as_ref().unwrap().acting_version()
2250 }
2251 }
2252
2253 impl<'a, P> Reader<'a> for SorSymbolsDecoder<P>
2254 where
2255 P: Reader<'a> + Default,
2256 {
2257 #[inline]
2258 fn get_buf(&self) -> &ReadBuf<'a> {
2259 self.parent.as_ref().expect("parent missing").get_buf()
2260 }
2261 }
2262
2263 impl<'a, P> Decoder<'a> for SorSymbolsDecoder<P>
2264 where
2265 P: Decoder<'a> + ActingVersion + Default,
2266 {
2267 #[inline]
2268 fn get_limit(&self) -> usize {
2269 self.parent.as_ref().expect("parent missing").get_limit()
2270 }
2271
2272 #[inline]
2273 fn set_limit(&mut self, limit: usize) {
2274 self.parent
2275 .as_mut()
2276 .expect("parent missing")
2277 .set_limit(limit);
2278 }
2279 }
2280
2281 impl<'a, P> SorSymbolsDecoder<P>
2282 where
2283 P: Decoder<'a> + ActingVersion + Default,
2284 {
2285 pub fn wrap(mut self, mut parent: P) -> Self {
2286 let initial_offset = parent.get_limit();
2287 let block_length = parent.get_buf().get_u16_at(initial_offset);
2288 let count = parent.get_buf().get_u32_at(initial_offset + 2);
2289 parent.set_limit(initial_offset + 6);
2290 self.parent = Some(parent);
2291 self.block_length = block_length;
2292 self.count = count;
2293 self.index = usize::MAX;
2294 self.offset = 0;
2295 self
2296 }
2297
2298 #[inline]
2300 pub fn parent(&mut self) -> SbeResult<P> {
2301 self.parent.take().ok_or(SbeErr::ParentNotSet)
2302 }
2303
2304 #[inline]
2305 pub fn acting_version(&mut self) -> u16 {
2306 self.parent.as_ref().unwrap().acting_version()
2307 }
2308
2309 #[inline]
2310 pub fn count(&self) -> u32 {
2311 self.count
2312 }
2313
2314 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
2316 let index = self.index.wrapping_add(1);
2317 if index >= self.count as usize {
2318 return Ok(None);
2319 }
2320
2321 if let Some(parent) = self.parent.as_mut() {
2322 self.offset = parent.get_limit();
2323 parent.set_limit(self.offset + self.block_length as usize);
2324 self.index = index;
2325 Ok(Some(index))
2326 } else {
2327 Err(SbeErr::ParentNotSet)
2328 }
2329 }
2330
2331 #[inline]
2333 pub fn symbol_decoder(&mut self) -> (usize, usize) {
2334 let offset = self.parent.as_ref().expect("parent missing").get_limit();
2335 let data_length = self.get_buf().get_u8_at(offset) as usize;
2336 self.parent
2337 .as_mut()
2338 .unwrap()
2339 .set_limit(offset + 1 + data_length);
2340 (offset + 1, data_length)
2341 }
2342
2343 #[inline]
2344 pub fn symbol_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
2345 debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
2346 self.get_buf().get_slice_at(coordinates.0, coordinates.1)
2347 }
2348 }
2349}