Skip to main content

nautilus_binance/spot/sbe/generated/
error_response_codec.rs

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