nautilus_binance/spot/sbe/generated/
cancel_open_orders_response_codec.rs1pub use decoder::CancelOpenOrdersResponseDecoder;
2pub use encoder::CancelOpenOrdersResponseEncoder;
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 = 306;
9
10pub mod encoder {
11 use message_header_codec::*;
12
13 use super::*;
14
15 #[derive(Debug, Default)]
16 pub struct CancelOpenOrdersResponseEncoder<'a> {
17 buf: WriteBuf<'a>,
18 initial_offset: usize,
19 offset: usize,
20 limit: usize,
21 }
22
23 impl<'a> Writer<'a> for CancelOpenOrdersResponseEncoder<'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 CancelOpenOrdersResponseEncoder<'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> CancelOpenOrdersResponseEncoder<'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 responses_encoder(
69 self,
70 count: u32,
71 responses_encoder: ResponsesEncoder<Self>,
72 ) -> ResponsesEncoder<Self> {
73 responses_encoder.wrap(self, count)
74 }
75 }
76
77 #[derive(Debug, Default)]
78 pub struct ResponsesEncoder<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 ResponsesEncoder<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 ResponsesEncoder<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> ResponsesEncoder<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 0
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]
168 pub fn response(&mut self, value: &[u8]) {
169 let limit = self.get_limit();
170 let data_length = value.len();
171 self.set_limit(limit + 2 + data_length);
172 self.get_buf_mut().put_u16_at(limit, data_length as u16);
173 self.get_buf_mut().put_slice_at(limit + 2, value);
174 }
175 }
176} pub mod decoder {
179 use message_header_codec::*;
180
181 use super::*;
182
183 #[derive(Clone, Copy, Debug, Default)]
184 pub struct CancelOpenOrdersResponseDecoder<'a> {
185 buf: ReadBuf<'a>,
186 initial_offset: usize,
187 offset: usize,
188 limit: usize,
189 pub acting_block_length: u16,
190 pub acting_version: u16,
191 }
192
193 impl ActingVersion for CancelOpenOrdersResponseDecoder<'_> {
194 #[inline]
195 fn acting_version(&self) -> u16 {
196 self.acting_version
197 }
198 }
199
200 impl<'a> Reader<'a> for CancelOpenOrdersResponseDecoder<'a> {
201 #[inline]
202 fn get_buf(&self) -> &ReadBuf<'a> {
203 &self.buf
204 }
205 }
206
207 impl<'a> Decoder<'a> for CancelOpenOrdersResponseDecoder<'a> {
208 #[inline]
209 fn get_limit(&self) -> usize {
210 self.limit
211 }
212
213 #[inline]
214 fn set_limit(&mut self, limit: usize) {
215 self.limit = limit;
216 }
217 }
218
219 impl<'a> CancelOpenOrdersResponseDecoder<'a> {
220 pub fn wrap(
221 mut self,
222 buf: ReadBuf<'a>,
223 offset: usize,
224 acting_block_length: u16,
225 acting_version: u16,
226 ) -> Self {
227 let limit = offset + acting_block_length as usize;
228 self.buf = buf;
229 self.initial_offset = offset;
230 self.offset = offset;
231 self.limit = limit;
232 self.acting_block_length = acting_block_length;
233 self.acting_version = acting_version;
234 self
235 }
236
237 #[inline]
238 pub fn encoded_length(&self) -> usize {
239 self.limit - self.offset
240 }
241
242 pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
243 debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
244 let acting_block_length = header.block_length();
245 let acting_version = header.version();
246
247 self.wrap(
248 header.parent().unwrap(),
249 offset + message_header_codec::ENCODED_LENGTH,
250 acting_block_length,
251 acting_version,
252 )
253 }
254
255 #[inline]
257 pub fn responses_decoder(self) -> ResponsesDecoder<Self> {
258 ResponsesDecoder::default().wrap(self)
259 }
260 }
261
262 #[derive(Debug, Default)]
263 pub struct ResponsesDecoder<P> {
264 parent: Option<P>,
265 block_length: u16,
266 count: u32,
267 index: usize,
268 offset: usize,
269 }
270
271 impl<'a, P> ActingVersion for ResponsesDecoder<P>
272 where
273 P: Reader<'a> + ActingVersion + Default,
274 {
275 #[inline]
276 fn acting_version(&self) -> u16 {
277 self.parent.as_ref().unwrap().acting_version()
278 }
279 }
280
281 impl<'a, P> Reader<'a> for ResponsesDecoder<P>
282 where
283 P: Reader<'a> + Default,
284 {
285 #[inline]
286 fn get_buf(&self) -> &ReadBuf<'a> {
287 self.parent.as_ref().expect("parent missing").get_buf()
288 }
289 }
290
291 impl<'a, P> Decoder<'a> for ResponsesDecoder<P>
292 where
293 P: Decoder<'a> + ActingVersion + Default,
294 {
295 #[inline]
296 fn get_limit(&self) -> usize {
297 self.parent.as_ref().expect("parent missing").get_limit()
298 }
299
300 #[inline]
301 fn set_limit(&mut self, limit: usize) {
302 self.parent
303 .as_mut()
304 .expect("parent missing")
305 .set_limit(limit);
306 }
307 }
308
309 impl<'a, P> ResponsesDecoder<P>
310 where
311 P: Decoder<'a> + ActingVersion + Default,
312 {
313 pub fn wrap(mut self, mut parent: P) -> Self {
314 let initial_offset = parent.get_limit();
315 let block_length = parent.get_buf().get_u16_at(initial_offset);
316 let count = parent.get_buf().get_u32_at(initial_offset + 2);
317 parent.set_limit(initial_offset + 6);
318 self.parent = Some(parent);
319 self.block_length = block_length;
320 self.count = count;
321 self.index = usize::MAX;
322 self.offset = 0;
323 self
324 }
325
326 #[inline]
328 pub fn parent(&mut self) -> SbeResult<P> {
329 self.parent.take().ok_or(SbeErr::ParentNotSet)
330 }
331
332 #[inline]
333 pub fn acting_version(&mut self) -> u16 {
334 self.parent.as_ref().unwrap().acting_version()
335 }
336
337 #[inline]
338 pub fn count(&self) -> u32 {
339 self.count
340 }
341
342 pub fn advance(&mut self) -> SbeResult<Option<usize>> {
344 let index = self.index.wrapping_add(1);
345 if index >= self.count as usize {
346 return Ok(None);
347 }
348
349 if let Some(parent) = self.parent.as_mut() {
350 self.offset = parent.get_limit();
351 parent.set_limit(self.offset + self.block_length as usize);
352 self.index = index;
353 Ok(Some(index))
354 } else {
355 Err(SbeErr::ParentNotSet)
356 }
357 }
358
359 #[inline]
361 pub fn response_decoder(&mut self) -> (usize, usize) {
362 let offset = self.parent.as_ref().expect("parent missing").get_limit();
363 let data_length = self.get_buf().get_u16_at(offset) as usize;
364 self.parent
365 .as_mut()
366 .unwrap()
367 .set_limit(offset + 2 + data_length);
368 (offset + 2, data_length)
369 }
370
371 #[inline]
372 pub fn response_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
373 debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
374 self.get_buf().get_slice_at(coordinates.0, coordinates.1)
375 }
376 }
377}