MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / to_vec

Method to_vec

chirpstack/src/codec/cayenne_lpp.rs:204–422  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

202 }
203
204 fn to_vec(&self) -> Vec<u8> {
205 let mut out: Vec<u8> = Vec::new();
206
207 // digital input
208 for (k, v) in &self.digital_input {
209 out.extend([*k, LPP_DIGITAL_INPUT]);
210 out.push(*v);
211 }
212
213 // digital output
214 for (k, v) in &self.digital_output {
215 out.extend([*k, LPP_DIGITAL_OUTPUT]);
216 out.push(*v);
217 }
218
219 // analog input
220 for (k, v) in &self.analog_input {
221 out.extend([*k, LPP_ANALOG_INPUT]);
222
223 let val = (*v * 100.0) as i16;
224 out.extend(val.to_be_bytes());
225 }
226
227 // analog output
228 for (k, v) in &self.analog_output {
229 out.extend([*k, LPP_ANALOG_OUTPUT]);
230
231 let val = (*v * 100.0) as i16;
232 out.extend(val.to_be_bytes());
233 }
234
235 // generic sensor
236 for (k, v) in &self.generic_sensor {
237 out.extend([*k, LPP_GENERIC_SENSOR]);
238
239 let val = *v;
240 out.extend(val.to_be_bytes());
241 }
242
243 // illuminance sensor
244 for (k, v) in &self.illuminance_sensor {
245 out.extend([*k, LPP_ILLUMINANCE_SENSOR]);
246 out.extend(v.to_be_bytes());
247 }
248
249 // presence sensor
250 for (k, v) in &self.presence_sensor {
251 out.extend([*k, LPP_PRESENCE_SENSOR]);
252 out.push(*v);
253 }
254
255 // temperature sensor
256 for (k, v) in &self.temperature_sensor {
257 out.extend([*k, LPP_TEMPERATURE_SENSOR]);
258
259 let val = (*v * 10.0) as i16;
260 out.extend(val.to_be_bytes());
261 }

Calls 2

pushMethod · 0.80
to_be_bytesMethod · 0.45

Tested by 15

test_update_uplink_listFunction · 0.36
run_testFunction · 0.36
test_fnsFunction · 0.36
test_snsFunction · 0.36
run_testFunction · 0.36
test_fns_uplinkFunction · 0.36
test_sns_uplinkFunction · 0.36
test_sns_dev_not_foundFunction · 0.36
test_class_bFunction · 0.36
run_uplink_testFunction · 0.36