nautilus_binance/spot/sbe/generated/
account_prevented_matches_response_codec.rs1pub use decoder::AccountPreventedMatchesResponseDecoder;
2pub use encoder::AccountPreventedMatchesResponseEncoder;
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 = 403;
9
10pub mod encoder {
11 use message_header_codec::*;
12
13 use super::*;
14
15 #[derive(Debug, Default)]
16 pub struct AccountPreventedMatchesResponseEncoder<'a> {
17 buf: WriteBuf<'a>,
18 initial_offset: usize,
19 offset: usize,
20 limit: usize,
21 }
22
23 impl<'a> Writer<'a> for AccountPreventedMatchesResponseEncoder<'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 AccountPreventedMatchesResponseEncoder<'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> AccountPreventedMatchesResponseEncoder<'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 prevented_matches_encoder(
69 self,
70 count: u32,
71 prevented_matches_encoder: PreventedMatchesEncoder<Self>,
72 ) -> PreventedMatchesEncoder<Self> {
73 prevented_matches_encoder.wrap(self, count)
74 }
75 }
76
77 #[derive(Debug, Default)]
78 pub struct PreventedMatchesEncoder<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 PreventedMatchesEncoder<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 PreventedMatchesEncoder<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> PreventedMatchesEncoder<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 67
141 }
142
143 #[inline]
144 pub fn parent(&mut self) -> SbeResult<P> {
145 self.parent.take().ok_or(SbeErr::ParentNotSet)
146 }
147
148 #[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 #[inline]
176 pub fn price_exponent(&mut self, value: i8) {
177 let offset = self.offset;
178 self.get_buf_mut().put_i8_at(offset, value);
179 }
180
181 #[inline]
191 pub fn qty_exponent(&mut self, value: i8) {
192 let offset = self.offset + 1;
193 self.get_buf_mut().put_i8_at(offset, value);
194 }
195
196 #[inline]
206 pub fn prevented_match_id(&mut self, value: i64) {
207 let offset = self.offset + 2;
208 self.get_buf_mut().put_i64_at(offset, value);
209 }
210
211 #[inline]
221 pub fn taker_order_id(&mut self, value: i64) {
222 let offset = self.offset + 10;
223 self.get_buf_mut().put_i64_at(offset, value);
224 }
225
226 #[inline]
236 pub fn maker_order_id(&mut self, value: i64) {
237 let offset = self.offset + 18;
238 self.get_buf_mut().put_i64_at(offset, value);
239 }
240
241 #[inline]
251 pub fn trade_group_id(&mut self, value: i64) {
252 let offset = self.offset + 26;
253 self.get_buf_mut().put_i64_at(offset, value);
254 }
255
256 #[inline]
258 pub fn self_trade_prevention_mode(
259 &mut self,
260 value: self_trade_prevention_mode::SelfTradePreventionMode,
261 ) {
262 let offset = self.offset + 34;
263 self.get_buf_mut().put_u8_at(offset, value as u8)
264 }
265
266 #[inline]
276 pub fn price(&mut self, value: i64) {
277 let offset = self.offset + 35;
278 self.get_buf_mut().put_i64_at(offset, value);
279 }
280
281 #[inline]
291 pub fn taker_prevented_quantity(&mut self, value: i64) {
292 let offset = self.offset + 43;
293 self.get_buf_mut().put_i64_at(offset, value);
294 }
295
296 #[inline]
306 pub fn maker_prevented_quantity(&mut self, value: i64) {
307 let offset = self.offset + 51;
308 self.get_buf_mut().put_i64_at(offset, value);
309 }
310
311 #[inline]
321 pub fn transact_time(&mut self, value: i64) {
322 let offset = self.offset + 59;
323 self.get_buf_mut().put_i64_at(offset, value);
324 }
325
326 #[inline]
328 pub fn symbol(&mut self, value: &str) {
329 let limit = self.get_limit();
330 let data_length = value.len();
331 self.set_limit(limit + 1 + data_length);
332 self.get_buf_mut().put_u8_at(limit, data_length as u8);
333 self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
334 }
335
336 #[inline]
338 pub fn maker_symbol(&mut self, value: &str) {
339 let limit = self.get_limit();
340 let data_length = value.len();
341 self.set_limit(limit + 1 + data_length);
342 self.get_buf_mut().put_u8_at(limit, data_length as u8);
343 self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
344 }
345 }
346} pub mod decoder {
349 use message_header_codec::*;
350
351 use super::*;
352
353 #[derive(Clone, Copy, Debug, Default)]
354 pub struct AccountPreventedMatchesResponseDecoder<'a> {
355 buf: ReadBuf<'a>,
356 initial_offset: usize,
357 offset: usize,
358 limit: usize,
359 pub acting_block_length: u16,
360 pub acting_version: u16,
361 }
362
363 impl ActingVersion for AccountPreventedMatchesResponseDecoder<'_> {
364 #[inline]
365 fn acting_version(&self) -> u16 {
366 self.acting_version
367 }
368 }
369
370 impl<'a> Reader<'a> for AccountPreventedMatchesResponseDecoder<'a> {
371 #[inline]
372 fn get_buf(&self) -> &ReadBuf<'a> {
373 &self.buf
374 }
375 }
376
377 impl<'a> Decoder<'a> for AccountPreventedMatchesResponseDecoder<'a> {
378 #[inline]
379 fn get_limit(&self) -> usize {
380 self.limit
381 }
382
383 #[inline]
384 fn set_limit(&mut self, limit: usize) {
385 self.limit = limit;
386 }
387 }
388
389 impl<'a> AccountPreventedMatchesResponseDecoder<'a> {
390 pub fn wrap(
391 mut self,
392 buf: ReadBuf<'a>,
393 offset: usize,
394 acting_block_length: u16,
395 acting_version: u16,
396 ) -> Self {
397 let limit = offset + acting_block_length as usize;
398 self.buf = buf;
399 self.initial_offset = offset;
400 self.offset = offset;
401 self.limit = limit;
402 self.acting_block_length = acting_block_length;
403 self.acting_version = acting_version;
404 self
405 }
406
407 #[inline]
408 pub fn encoded_length(&self) -> usize {
409 self.limit - self.offset
410 }
411
412 pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
413 debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
414 let acting_block_length = header.block_length();
415 let acting_version = header.version();
416
417 self.wrap(
418 header.parent().unwrap(),
419 offset + message_header_codec::ENCODED_LENGTH,
420 acting_block_length,
421 acting_version,
422 )
423 }
424
425 #[inline]
427 pub fn prevented_matches_decoder(self) -> PreventedMatchesDecoder<Self> {
428 PreventedMatchesDecoder::default().wrap(self)
429 }
430 }
431
432 #[derive(Debug, Default)]
433 pub struct PreventedMatchesDecoder<P> {
434 parent: Option<P>,
435 block_length: u16,
436 count: u32,
437 index: usize,
438 offset: usize,
439 }
440
441 impl<'a, P> ActingVersion for PreventedMatchesDecoder<P>
442 where
443 P: Reader<'a> + ActingVersion + Default,
444 {
445 #[inline]
446 fn acting_version(&self) -> u16 {
447 self.parent.as_ref().unwrap().acting_version()
448 }
449 }
450
451 impl<'a, P> Reader<'a> for PreventedMatchesDecoder<P>
452 where
453 P: Reader<'a> + Default,
454 {
455 #[inline]
456 fn get_buf(&self) -> &ReadBuf<'a> {
457 self.parent.as_ref().expect("parent missing").get_buf()
458 }
459 }
460
461 impl<'a, P> Decoder<'a> for PreventedMatchesDecoder<P>
462 where
463 P: Decoder<'a> + ActingVersion + Default,
464 {
465 #[inline]
466 fn get_limit(&self) -> usize {
467 self.parent.as_ref().expect("parent missing").get_limit()
468 }
469
470 #[inline]
471 fn set_limit(&mut self, limit: usize) {
472 self.parent
473 .as_mut()
474 .expect("parent missing")
475 .set_limit(limit);
476 }
477 }
478
479 impl<'a, P> PreventedMatchesDecoder<P>
480 where
481 P: Decoder<'a> + ActingVersion + Default,
482 {
483 pub fn wrap(mut self, mut parent: P) -> Self {
484 let initial_offset = parent.get_limit();
485 let block_length = parent.get_buf().get_u16_at(initial_offset);
486 let count = parent.get_buf().get_u32_at(initial_offset + 2);
487 parent.set_limit(initial_offset + 6);
488 self.parent = Some(parent);
489 self.block_length = block_length;
490 self.count = count;
491 self.index = usize::MAX;
492 self.offset = 0;
493 self
494 }
495
496 #[inline]
498 pub fn parent(&mut self) -> SbeResult<P> {
499 self.parent.take().ok_or(SbeErr::ParentNotSet)
500 }
501
502 #[inline]
503 pub fn acting_version(&mut self) -> u16 {
504 self.parent.as_ref().unwrap().acting_version()
505 }
506
507 #[inline]
508 pub fn count(&self) -> u32 {
509 self.count
510 }
511
512 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
514 let index = self.index.wrapping_add(1);
515 if index >= self.count as usize {
516 return Ok(None);
517 }
518
519 if let Some(parent) = self.parent.as_mut() {
520 self.offset = parent.get_limit();
521 parent.set_limit(self.offset + self.block_length as usize);
522 self.index = index;
523 Ok(Some(index))
524 } else {
525 Err(SbeErr::ParentNotSet)
526 }
527 }
528
529 #[inline]
531 pub fn price_exponent(&self) -> i8 {
532 self.get_buf().get_i8_at(self.offset)
533 }
534
535 #[inline]
537 pub fn qty_exponent(&self) -> i8 {
538 self.get_buf().get_i8_at(self.offset + 1)
539 }
540
541 #[inline]
543 pub fn prevented_match_id(&self) -> i64 {
544 self.get_buf().get_i64_at(self.offset + 2)
545 }
546
547 #[inline]
549 pub fn taker_order_id(&self) -> i64 {
550 self.get_buf().get_i64_at(self.offset + 10)
551 }
552
553 #[inline]
555 pub fn maker_order_id(&self) -> i64 {
556 self.get_buf().get_i64_at(self.offset + 18)
557 }
558
559 #[inline]
561 pub fn trade_group_id(&self) -> i64 {
562 self.get_buf().get_i64_at(self.offset + 26)
563 }
564
565 #[inline]
567 pub fn self_trade_prevention_mode(
568 &self,
569 ) -> self_trade_prevention_mode::SelfTradePreventionMode {
570 self.get_buf().get_u8_at(self.offset + 34).into()
571 }
572
573 #[inline]
575 pub fn price(&self) -> i64 {
576 self.get_buf().get_i64_at(self.offset + 35)
577 }
578
579 #[inline]
581 pub fn taker_prevented_quantity(&self) -> Option<i64> {
582 let value = self.get_buf().get_i64_at(self.offset + 43);
583 if value == -9223372036854775808_i64 {
584 None
585 } else {
586 Some(value)
587 }
588 }
589
590 #[inline]
592 pub fn maker_prevented_quantity(&self) -> Option<i64> {
593 let value = self.get_buf().get_i64_at(self.offset + 51);
594 if value == -9223372036854775808_i64 {
595 None
596 } else {
597 Some(value)
598 }
599 }
600
601 #[inline]
603 pub fn transact_time(&self) -> i64 {
604 self.get_buf().get_i64_at(self.offset + 59)
605 }
606
607 #[inline]
609 pub fn symbol_decoder(&mut self) -> (usize, usize) {
610 let offset = self.parent.as_ref().expect("parent missing").get_limit();
611 let data_length = self.get_buf().get_u8_at(offset) as usize;
612 self.parent
613 .as_mut()
614 .unwrap()
615 .set_limit(offset + 1 + data_length);
616 (offset + 1, data_length)
617 }
618
619 #[inline]
620 pub fn symbol_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
621 debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
622 self.get_buf().get_slice_at(coordinates.0, coordinates.1)
623 }
624
625 #[inline]
627 pub fn maker_symbol_decoder(&mut self) -> (usize, usize) {
628 let offset = self.parent.as_ref().expect("parent missing").get_limit();
629 let data_length = self.get_buf().get_u8_at(offset) as usize;
630 self.parent
631 .as_mut()
632 .unwrap()
633 .set_limit(offset + 1 + data_length);
634 (offset + 1, data_length)
635 }
636
637 #[inline]
638 pub fn maker_symbol_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
639 debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
640 self.get_buf().get_slice_at(coordinates.0, coordinates.1)
641 }
642 }
643}