Skip to main content

nautilus_binance/spot/sbe/generated/
event_stream_terminated_event_codec.rs

1pub use decoder::EventStreamTerminatedEventDecoder;
2pub use encoder::EventStreamTerminatedEventEncoder;
3
4use super::*;
5pub use super::{SBE_SCHEMA_ID, SBE_SCHEMA_VERSION, SBE_SEMANTIC_VERSION};
6
7pub const SBE_BLOCK_LENGTH: u16 = 10;
8pub const SBE_TEMPLATE_ID: u16 = 602;
9
10pub mod encoder {
11    use message_header_codec::*;
12
13    use super::*;
14
15    #[derive(Debug, Default)]
16    pub struct EventStreamTerminatedEventEncoder<'a> {
17        buf: WriteBuf<'a>,
18        initial_offset: usize,
19        offset: usize,
20        limit: usize,
21    }
22
23    impl<'a> Writer<'a> for EventStreamTerminatedEventEncoder<'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 EventStreamTerminatedEventEncoder<'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> EventStreamTerminatedEventEncoder<'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 'subscriptionId'
82        /// - min value: 0
83        /// - max value: 65534
84        /// - null value: 0xffff_u16
85        /// - characterEncoding: null
86        /// - semanticType: null
87        /// - encodedOffset: 8
88        /// - encodedLength: 2
89        /// - version: 1
90        #[inline]
91        pub fn subscription_id(&mut self, value: u16) {
92            let offset = self.offset + 8;
93            self.get_buf_mut().put_u16_at(offset, value);
94        }
95    }
96} // end encoder
97
98pub mod decoder {
99    use message_header_codec::*;
100
101    use super::*;
102
103    #[derive(Clone, Copy, Debug, Default)]
104    pub struct EventStreamTerminatedEventDecoder<'a> {
105        buf: ReadBuf<'a>,
106        initial_offset: usize,
107        offset: usize,
108        limit: usize,
109        pub acting_block_length: u16,
110        pub acting_version: u16,
111    }
112
113    impl ActingVersion for EventStreamTerminatedEventDecoder<'_> {
114        #[inline]
115        fn acting_version(&self) -> u16 {
116            self.acting_version
117        }
118    }
119
120    impl<'a> Reader<'a> for EventStreamTerminatedEventDecoder<'a> {
121        #[inline]
122        fn get_buf(&self) -> &ReadBuf<'a> {
123            &self.buf
124        }
125    }
126
127    impl<'a> Decoder<'a> for EventStreamTerminatedEventDecoder<'a> {
128        #[inline]
129        fn get_limit(&self) -> usize {
130            self.limit
131        }
132
133        #[inline]
134        fn set_limit(&mut self, limit: usize) {
135            self.limit = limit;
136        }
137    }
138
139    impl<'a> EventStreamTerminatedEventDecoder<'a> {
140        pub fn wrap(
141            mut self,
142            buf: ReadBuf<'a>,
143            offset: usize,
144            acting_block_length: u16,
145            acting_version: u16,
146        ) -> Self {
147            let limit = offset + acting_block_length as usize;
148            self.buf = buf;
149            self.initial_offset = offset;
150            self.offset = offset;
151            self.limit = limit;
152            self.acting_block_length = acting_block_length;
153            self.acting_version = acting_version;
154            self
155        }
156
157        #[inline]
158        pub fn encoded_length(&self) -> usize {
159            self.limit - self.offset
160        }
161
162        pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
163            debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
164            let acting_block_length = header.block_length();
165            let acting_version = header.version();
166
167            self.wrap(
168                header.parent().unwrap(),
169                offset + message_header_codec::ENCODED_LENGTH,
170                acting_block_length,
171                acting_version,
172            )
173        }
174
175        /// primitive field - 'REQUIRED'
176        #[inline]
177        pub fn event_time(&self) -> i64 {
178            self.get_buf().get_i64_at(self.offset)
179        }
180
181        /// primitive field - 'OPTIONAL' { null_value: '0xffff_u16' }
182        #[inline]
183        pub fn subscription_id(&self) -> Option<u16> {
184            if self.acting_version() < 1 {
185                return None;
186            }
187
188            let value = self.get_buf().get_u16_at(self.offset + 8);
189            if value == 0xffff_u16 {
190                None
191            } else {
192                Some(value)
193            }
194        }
195    }
196} // end decoder