Skip to main content

nautilus_binance/spot/sbe/generated/
web_socket_session_status_response_codec.rs

1pub use decoder::WebSocketSessionStatusResponseDecoder;
2pub use encoder::WebSocketSessionStatusResponseEncoder;
3
4use super::*;
5pub use super::{SBE_SCHEMA_ID, SBE_SCHEMA_VERSION, SBE_SEMANTIC_VERSION};
6
7pub const SBE_BLOCK_LENGTH: u16 = 26;
8pub const SBE_TEMPLATE_ID: u16 = 52;
9
10pub mod encoder {
11    use message_header_codec::*;
12
13    use super::*;
14
15    #[derive(Debug, Default)]
16    pub struct WebSocketSessionStatusResponseEncoder<'a> {
17        buf: WriteBuf<'a>,
18        initial_offset: usize,
19        offset: usize,
20        limit: usize,
21    }
22
23    impl<'a> Writer<'a> for WebSocketSessionStatusResponseEncoder<'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 WebSocketSessionStatusResponseEncoder<'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> WebSocketSessionStatusResponseEncoder<'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 'authorizedSince'
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 authorized_since(&mut self, value: i64) {
77            let offset = self.offset;
78            self.get_buf_mut().put_i64_at(offset, value);
79        }
80
81        /// primitive field 'connectedSince'
82        /// - min value: -9223372036854775807
83        /// - max value: 9223372036854775807
84        /// - null value: -9223372036854775808_i64
85        /// - characterEncoding: null
86        /// - semanticType: null
87        /// - encodedOffset: 8
88        /// - encodedLength: 8
89        /// - version: 0
90        #[inline]
91        pub fn connected_since(&mut self, value: i64) {
92            let offset = self.offset + 8;
93            self.get_buf_mut().put_i64_at(offset, value);
94        }
95
96        /// REQUIRED enum
97        #[inline]
98        pub fn return_rate_limits(&mut self, value: bool_enum::BoolEnum) {
99            let offset = self.offset + 16;
100            self.get_buf_mut().put_u8_at(offset, value as u8)
101        }
102
103        /// primitive field 'serverTime'
104        /// - min value: -9223372036854775807
105        /// - max value: 9223372036854775807
106        /// - null value: -9223372036854775808_i64
107        /// - characterEncoding: null
108        /// - semanticType: null
109        /// - encodedOffset: 17
110        /// - encodedLength: 8
111        /// - version: 0
112        #[inline]
113        pub fn server_time(&mut self, value: i64) {
114            let offset = self.offset + 17;
115            self.get_buf_mut().put_i64_at(offset, value);
116        }
117
118        /// REQUIRED enum
119        #[inline]
120        pub fn user_data_stream(&mut self, value: bool_enum::BoolEnum) {
121            let offset = self.offset + 25;
122            self.get_buf_mut().put_u8_at(offset, value as u8)
123        }
124
125        /// VAR_DATA ENCODER - character encoding: 'UTF-8'
126        #[inline]
127        pub fn logged_on_api_key(&mut self, value: &str) {
128            let limit = self.get_limit();
129            let data_length = value.len();
130            self.set_limit(limit + 2 + data_length);
131            self.get_buf_mut().put_u16_at(limit, data_length as u16);
132            self.get_buf_mut().put_slice_at(limit + 2, value.as_bytes());
133        }
134    }
135} // end encoder
136
137pub mod decoder {
138    use message_header_codec::*;
139
140    use super::*;
141
142    #[derive(Clone, Copy, Debug, Default)]
143    pub struct WebSocketSessionStatusResponseDecoder<'a> {
144        buf: ReadBuf<'a>,
145        initial_offset: usize,
146        offset: usize,
147        limit: usize,
148        pub acting_block_length: u16,
149        pub acting_version: u16,
150    }
151
152    impl ActingVersion for WebSocketSessionStatusResponseDecoder<'_> {
153        #[inline]
154        fn acting_version(&self) -> u16 {
155            self.acting_version
156        }
157    }
158
159    impl<'a> Reader<'a> for WebSocketSessionStatusResponseDecoder<'a> {
160        #[inline]
161        fn get_buf(&self) -> &ReadBuf<'a> {
162            &self.buf
163        }
164    }
165
166    impl<'a> Decoder<'a> for WebSocketSessionStatusResponseDecoder<'a> {
167        #[inline]
168        fn get_limit(&self) -> usize {
169            self.limit
170        }
171
172        #[inline]
173        fn set_limit(&mut self, limit: usize) {
174            self.limit = limit;
175        }
176    }
177
178    impl<'a> WebSocketSessionStatusResponseDecoder<'a> {
179        pub fn wrap(
180            mut self,
181            buf: ReadBuf<'a>,
182            offset: usize,
183            acting_block_length: u16,
184            acting_version: u16,
185        ) -> Self {
186            let limit = offset + acting_block_length as usize;
187            self.buf = buf;
188            self.initial_offset = offset;
189            self.offset = offset;
190            self.limit = limit;
191            self.acting_block_length = acting_block_length;
192            self.acting_version = acting_version;
193            self
194        }
195
196        #[inline]
197        pub fn encoded_length(&self) -> usize {
198            self.limit - self.offset
199        }
200
201        pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
202            debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
203            let acting_block_length = header.block_length();
204            let acting_version = header.version();
205
206            self.wrap(
207                header.parent().unwrap(),
208                offset + message_header_codec::ENCODED_LENGTH,
209                acting_block_length,
210                acting_version,
211            )
212        }
213
214        /// primitive field - 'OPTIONAL' { null_value: '-9223372036854775808_i64' }
215        #[inline]
216        pub fn authorized_since(&self) -> Option<i64> {
217            let value = self.get_buf().get_i64_at(self.offset);
218            if value == -9223372036854775808_i64 {
219                None
220            } else {
221                Some(value)
222            }
223        }
224
225        /// primitive field - 'REQUIRED'
226        #[inline]
227        pub fn connected_since(&self) -> i64 {
228            self.get_buf().get_i64_at(self.offset + 8)
229        }
230
231        /// REQUIRED enum
232        #[inline]
233        pub fn return_rate_limits(&self) -> bool_enum::BoolEnum {
234            self.get_buf().get_u8_at(self.offset + 16).into()
235        }
236
237        /// primitive field - 'REQUIRED'
238        #[inline]
239        pub fn server_time(&self) -> i64 {
240            self.get_buf().get_i64_at(self.offset + 17)
241        }
242
243        /// REQUIRED enum
244        #[inline]
245        pub fn user_data_stream(&self) -> bool_enum::BoolEnum {
246            self.get_buf().get_u8_at(self.offset + 25).into()
247        }
248
249        /// VAR_DATA DECODER - character encoding: 'UTF-8'
250        #[inline]
251        pub fn logged_on_api_key_decoder(&mut self) -> (usize, usize) {
252            let offset = self.get_limit();
253            let data_length = self.get_buf().get_u16_at(offset) as usize;
254            self.set_limit(offset + 2 + data_length);
255            (offset + 2, data_length)
256        }
257
258        #[inline]
259        pub fn logged_on_api_key_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
260            debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
261            self.get_buf().get_slice_at(coordinates.0, coordinates.1)
262        }
263    }
264} // end decoder