nautilus_binance/spot/sbe/generated/
average_price_response_codec.rs1pub use decoder::AveragePriceResponseDecoder;
2pub use encoder::AveragePriceResponseEncoder;
3
4use super::*;
5pub use super::{SBE_SCHEMA_ID, SBE_SCHEMA_VERSION, SBE_SEMANTIC_VERSION};
6
7pub const SBE_BLOCK_LENGTH: u16 = 25;
8pub const SBE_TEMPLATE_ID: u16 = 204;
9
10pub mod encoder {
11 use message_header_codec::*;
12
13 use super::*;
14
15 #[derive(Debug, Default)]
16 pub struct AveragePriceResponseEncoder<'a> {
17 buf: WriteBuf<'a>,
18 initial_offset: usize,
19 offset: usize,
20 limit: usize,
21 }
22
23 impl<'a> Writer<'a> for AveragePriceResponseEncoder<'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 AveragePriceResponseEncoder<'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> AveragePriceResponseEncoder<'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 mins(&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 price_exponent(&mut self, value: i8) {
92 let offset = self.offset + 8;
93 self.get_buf_mut().put_i8_at(offset, value);
94 }
95
96 #[inline]
106 pub fn price(&mut self, value: i64) {
107 let offset = self.offset + 9;
108 self.get_buf_mut().put_i64_at(offset, value);
109 }
110
111 #[inline]
121 pub fn close_time(&mut self, value: i64) {
122 let offset = self.offset + 17;
123 self.get_buf_mut().put_i64_at(offset, value);
124 }
125 }
126} pub mod decoder {
129 use message_header_codec::*;
130
131 use super::*;
132
133 #[derive(Clone, Copy, Debug, Default)]
134 pub struct AveragePriceResponseDecoder<'a> {
135 buf: ReadBuf<'a>,
136 initial_offset: usize,
137 offset: usize,
138 limit: usize,
139 pub acting_block_length: u16,
140 pub acting_version: u16,
141 }
142
143 impl ActingVersion for AveragePriceResponseDecoder<'_> {
144 #[inline]
145 fn acting_version(&self) -> u16 {
146 self.acting_version
147 }
148 }
149
150 impl<'a> Reader<'a> for AveragePriceResponseDecoder<'a> {
151 #[inline]
152 fn get_buf(&self) -> &ReadBuf<'a> {
153 &self.buf
154 }
155 }
156
157 impl<'a> Decoder<'a> for AveragePriceResponseDecoder<'a> {
158 #[inline]
159 fn get_limit(&self) -> usize {
160 self.limit
161 }
162
163 #[inline]
164 fn set_limit(&mut self, limit: usize) {
165 self.limit = limit;
166 }
167 }
168
169 impl<'a> AveragePriceResponseDecoder<'a> {
170 pub fn wrap(
171 mut self,
172 buf: ReadBuf<'a>,
173 offset: usize,
174 acting_block_length: u16,
175 acting_version: u16,
176 ) -> Self {
177 let limit = offset + acting_block_length as usize;
178 self.buf = buf;
179 self.initial_offset = offset;
180 self.offset = offset;
181 self.limit = limit;
182 self.acting_block_length = acting_block_length;
183 self.acting_version = acting_version;
184 self
185 }
186
187 #[inline]
188 pub fn encoded_length(&self) -> usize {
189 self.limit - self.offset
190 }
191
192 pub fn header(self, mut header: MessageHeaderDecoder<ReadBuf<'a>>, offset: usize) -> Self {
193 debug_assert_eq!(SBE_TEMPLATE_ID, header.template_id());
194 let acting_block_length = header.block_length();
195 let acting_version = header.version();
196
197 self.wrap(
198 header.parent().unwrap(),
199 offset + message_header_codec::ENCODED_LENGTH,
200 acting_block_length,
201 acting_version,
202 )
203 }
204
205 #[inline]
207 pub fn mins(&self) -> i64 {
208 self.get_buf().get_i64_at(self.offset)
209 }
210
211 #[inline]
213 pub fn price_exponent(&self) -> i8 {
214 self.get_buf().get_i8_at(self.offset + 8)
215 }
216
217 #[inline]
219 pub fn price(&self) -> Option<i64> {
220 let value = self.get_buf().get_i64_at(self.offset + 9);
221 if value == -9223372036854775808_i64 {
222 None
223 } else {
224 Some(value)
225 }
226 }
227
228 #[inline]
230 pub fn close_time(&self) -> Option<i64> {
231 let value = self.get_buf().get_i64_at(self.offset + 17);
232 if value == -9223372036854775808_i64 {
233 None
234 } else {
235 Some(value)
236 }
237 }
238 }
239}