Skip to main content

nautilus_binance/spot/sbe/generated/
reference_price_calculation_response_codec.rs

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