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