nautilus_binance/spot/sbe/generated/
external_lock_update_event_codec.rs1pub use decoder::ExternalLockUpdateEventDecoder;
2pub use encoder::ExternalLockUpdateEventEncoder;
3
4use super::*;
5pub use super::{SBE_SCHEMA_ID, SBE_SCHEMA_VERSION, SBE_SEMANTIC_VERSION};
6
7pub const SBE_BLOCK_LENGTH: u16 = 27;
8pub const SBE_TEMPLATE_ID: u16 = 604;
9
10pub mod encoder {
11 use message_header_codec::*;
12
13 use super::*;
14
15 #[derive(Debug, Default)]
16 pub struct ExternalLockUpdateEventEncoder<'a> {
17 buf: WriteBuf<'a>,
18 initial_offset: usize,
19 offset: usize,
20 limit: usize,
21 }
22
23 impl<'a> Writer<'a> for ExternalLockUpdateEventEncoder<'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 ExternalLockUpdateEventEncoder<'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> ExternalLockUpdateEventEncoder<'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]
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 #[inline]
91 pub fn clear_time(&mut self, value: i64) {
92 let offset = self.offset + 8;
93 self.get_buf_mut().put_i64_at(offset, value);
94 }
95
96 #[inline]
106 pub fn qty_exponent(&mut self, value: i8) {
107 let offset = self.offset + 16;
108 self.get_buf_mut().put_i8_at(offset, value);
109 }
110
111 #[inline]
121 pub fn locked_qty_delta(&mut self, value: i64) {
122 let offset = self.offset + 17;
123 self.get_buf_mut().put_i64_at(offset, value);
124 }
125
126 #[inline]
136 pub fn subscription_id(&mut self, value: u16) {
137 let offset = self.offset + 25;
138 self.get_buf_mut().put_u16_at(offset, value);
139 }
140
141 #[inline]
143 pub fn asset(&mut self, value: &str) {
144 let limit = self.get_limit();
145 let data_length = value.len();
146 self.set_limit(limit + 1 + data_length);
147 self.get_buf_mut().put_u8_at(limit, data_length as u8);
148 self.get_buf_mut().put_slice_at(limit + 1, value.as_bytes());
149 }
150 }
151} pub mod decoder {
154 use message_header_codec::*;
155
156 use super::*;
157
158 #[derive(Clone, Copy, Debug, Default)]
159 pub struct ExternalLockUpdateEventDecoder<'a> {
160 buf: ReadBuf<'a>,
161 initial_offset: usize,
162 offset: usize,
163 limit: usize,
164 pub acting_block_length: u16,
165 pub acting_version: u16,
166 }
167
168 impl ActingVersion for ExternalLockUpdateEventDecoder<'_> {
169 #[inline]
170 fn acting_version(&self) -> u16 {
171 self.acting_version
172 }
173 }
174
175 impl<'a> Reader<'a> for ExternalLockUpdateEventDecoder<'a> {
176 #[inline]
177 fn get_buf(&self) -> &ReadBuf<'a> {
178 &self.buf
179 }
180 }
181
182 impl<'a> Decoder<'a> for ExternalLockUpdateEventDecoder<'a> {
183 #[inline]
184 fn get_limit(&self) -> usize {
185 self.limit
186 }
187
188 #[inline]
189 fn set_limit(&mut self, limit: usize) {
190 self.limit = limit;
191 }
192 }
193
194 impl<'a> ExternalLockUpdateEventDecoder<'a> {
195 pub fn wrap(
196 mut self,
197 buf: ReadBuf<'a>,
198 offset: usize,
199 acting_block_length: u16,
200 acting_version: u16,
201 ) -> Self {
202 let limit = offset + acting_block_length as usize;
203 self.buf = buf;
204 self.initial_offset = offset;
205 self.offset = offset;
206 self.limit = limit;
207 self.acting_block_length = acting_block_length;
208 self.acting_version = acting_version;
209 self
210 }
211
212 #[inline]
213 pub fn encoded_length(&self) -> usize {
214 self.limit - self.offset
215 }
216
217 pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
218 debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
219 let acting_block_length = header.block_length();
220 let acting_version = header.version();
221
222 self.wrap(
223 header.parent().unwrap(),
224 offset + message_header_codec::ENCODED_LENGTH,
225 acting_block_length,
226 acting_version,
227 )
228 }
229
230 #[inline]
232 pub fn event_time(&self) -> i64 {
233 self.get_buf().get_i64_at(self.offset)
234 }
235
236 #[inline]
238 pub fn clear_time(&self) -> i64 {
239 self.get_buf().get_i64_at(self.offset + 8)
240 }
241
242 #[inline]
244 pub fn qty_exponent(&self) -> i8 {
245 self.get_buf().get_i8_at(self.offset + 16)
246 }
247
248 #[inline]
250 pub fn locked_qty_delta(&self) -> i64 {
251 self.get_buf().get_i64_at(self.offset + 17)
252 }
253
254 #[inline]
256 pub fn subscription_id(&self) -> Option<u16> {
257 if self.acting_version() < 1 {
258 return None;
259 }
260
261 let value = self.get_buf().get_u16_at(self.offset + 25);
262 if value == 0xffff_u16 {
263 None
264 } else {
265 Some(value)
266 }
267 }
268
269 #[inline]
271 pub fn asset_decoder(&mut self) -> (usize, usize) {
272 let offset = self.get_limit();
273 let data_length = self.get_buf().get_u8_at(offset) as usize;
274 self.set_limit(offset + 1 + data_length);
275 (offset + 1, data_length)
276 }
277
278 #[inline]
279 pub fn asset_slice(&'a self, coordinates: (usize, usize)) -> &'a [u8] {
280 debug_assert!(self.get_limit() >= coordinates.0 + coordinates.1);
281 self.get_buf().get_slice_at(coordinates.0, coordinates.1)
282 }
283 }
284}