1pub trait GetParameterValue: Sized {
3 fn from_bytes_as_bool(bytes: &[u8]) -> Result<Self, String>;
4 fn from_bytes_as_i8(bytes: &[u8]) -> Result<Self, String>;
5 fn from_bytes_as_u8(bytes: &[u8]) -> Result<Self, String>;
6 fn from_bytes_as_i16(bytes: &[u8]) -> Result<Self, String>;
7 fn from_bytes_as_u16(bytes: &[u8]) -> Result<Self, String>;
8 fn from_bytes_as_i32(bytes: &[u8]) -> Result<Self, String>;
9 fn from_bytes_as_u32(bytes: &[u8]) -> Result<Self, String>;
10 fn from_bytes_as_i64(bytes: &[u8]) -> Result<Self, String>;
11 fn from_bytes_as_u64(bytes: &[u8]) -> Result<Self, String>;
12 fn from_bytes_as_f32(bytes: &[u8]) -> Result<Self, String>;
13 fn from_bytes_as_f64(bytes: &[u8]) -> Result<Self, String>;
14 fn from_bytes_as_string(bytes: &[u8]) -> Result<Self, String>;
15}
16
17impl GetParameterValue for bool {
18 fn from_bytes_as_bool(bytes: &[u8]) -> Result<Self, String> {
19 Ok(bytes[0] != 0)
20 }
21 fn from_bytes_as_i8(bytes: &[u8]) -> Result<Self, String> {
22 Ok(bytes[0] != 0)
23 }
24 fn from_bytes_as_u8(bytes: &[u8]) -> Result<Self, String> {
25 Ok(bytes[0] != 0)
26 }
27 fn from_bytes_as_i16(bytes: &[u8]) -> Result<Self, String> {
28 Ok(bytes[0] != 0)
29 }
30 fn from_bytes_as_u16(bytes: &[u8]) -> Result<Self, String> {
31 Ok(bytes[0] != 0)
32 }
33 fn from_bytes_as_i32(bytes: &[u8]) -> Result<Self, String> {
34 Ok(bytes[0] != 0)
35 }
36 fn from_bytes_as_u32(bytes: &[u8]) -> Result<Self, String> {
37 Ok(bytes[0] != 0)
38 }
39 fn from_bytes_as_i64(bytes: &[u8]) -> Result<Self, String> {
40 Ok(bytes[0] != 0)
41 }
42 fn from_bytes_as_u64(bytes: &[u8]) -> Result<Self, String> {
43 Ok(bytes[0] != 0)
44 }
45 fn from_bytes_as_f32(bytes: &[u8]) -> Result<Self, String> {
46 Ok(bytes[0] != 0)
47 }
48 fn from_bytes_as_f64(bytes: &[u8]) -> Result<Self, String> {
49 Ok(bytes[0] != 0)
50 }
51 fn from_bytes_as_string(bytes: &[u8]) -> Result<Self, String> {
52 Ok(bytes[0] != 0)
53 }
54}
55
56impl GetParameterValue for String {
57 fn from_bytes_as_bool(bytes: &[u8]) -> Result<Self, String> {
58 Ok(if bytes[0] != 0 {
59 "true".to_string()
60 } else {
61 "false".to_string()
62 })
63 }
64 fn from_bytes_as_i8(bytes: &[u8]) -> Result<Self, String> {
65 Ok(i8::from_le_bytes(bytes.try_into().unwrap()).to_string())
66 }
67 fn from_bytes_as_u8(bytes: &[u8]) -> Result<Self, String> {
68 Ok(u8::from_le_bytes(bytes.try_into().unwrap()).to_string())
69 }
70 fn from_bytes_as_i16(bytes: &[u8]) -> Result<Self, String> {
71 Ok(i16::from_le_bytes(bytes.try_into().unwrap()).to_string())
72 }
73 fn from_bytes_as_u16(bytes: &[u8]) -> Result<Self, String> {
74 Ok(u16::from_le_bytes(bytes.try_into().unwrap()).to_string())
75 }
76 fn from_bytes_as_i32(bytes: &[u8]) -> Result<Self, String> {
77 Ok(i32::from_le_bytes(bytes.try_into().unwrap()).to_string())
78 }
79 fn from_bytes_as_u32(bytes: &[u8]) -> Result<Self, String> {
80 Ok(u32::from_le_bytes(bytes.try_into().unwrap()).to_string())
81 }
82 fn from_bytes_as_i64(bytes: &[u8]) -> Result<Self, String> {
83 Ok(i64::from_le_bytes(bytes.try_into().unwrap()).to_string())
84 }
85 fn from_bytes_as_u64(bytes: &[u8]) -> Result<Self, String> {
86 Ok(u64::from_le_bytes(bytes.try_into().unwrap()).to_string())
87 }
88 fn from_bytes_as_f32(bytes: &[u8]) -> Result<Self, String> {
89 Ok(f32::from_le_bytes(bytes.try_into().unwrap()).to_string())
90 }
91 fn from_bytes_as_f64(bytes: &[u8]) -> Result<Self, String> {
92 Ok(f64::from_le_bytes(bytes.try_into().unwrap()).to_string())
93 }
94 fn from_bytes_as_string(bytes: &[u8]) -> Result<Self, String> {
95 String::from_utf8(bytes.to_vec()).map_err(|e| e.to_string())
96 }
97}
98
99macro_rules! impl_get_parameter_value {
100 ($t:ty) => {
101 impl GetParameterValue for $t {
102 fn from_bytes_as_bool(bytes: &[u8]) -> Result<Self, String> {
103 let value = if bytes[0] != 0 { 1u8 } else { 0u8 };
104 Ok(value as Self)
105 }
106 fn from_bytes_as_i8(bytes: &[u8]) -> Result<Self, String> {
107 Ok(i8::from_le_bytes(bytes.try_into().unwrap()) as Self)
108 }
109 fn from_bytes_as_u8(bytes: &[u8]) -> Result<Self, String> {
110 Ok(u8::from_le_bytes(bytes.try_into().unwrap()) as Self)
111 }
112 fn from_bytes_as_i16(bytes: &[u8]) -> Result<Self, String> {
113 Ok(i16::from_le_bytes(bytes.try_into().unwrap()) as Self)
114 }
115 fn from_bytes_as_u16(bytes: &[u8]) -> Result<Self, String> {
116 Ok(u16::from_le_bytes(bytes.try_into().unwrap()) as Self)
117 }
118 fn from_bytes_as_i32(bytes: &[u8]) -> Result<Self, String> {
119 Ok(i32::from_le_bytes(bytes.try_into().unwrap()) as Self)
120 }
121 fn from_bytes_as_u32(bytes: &[u8]) -> Result<Self, String> {
122 Ok(u32::from_le_bytes(bytes.try_into().unwrap()) as Self)
123 }
124 fn from_bytes_as_i64(bytes: &[u8]) -> Result<Self, String> {
125 Ok(i64::from_le_bytes(bytes.try_into().unwrap()) as Self)
126 }
127 fn from_bytes_as_u64(bytes: &[u8]) -> Result<Self, String> {
128 Ok(u64::from_le_bytes(bytes.try_into().unwrap()) as Self)
129 }
130 fn from_bytes_as_f32(bytes: &[u8]) -> Result<Self, String> {
131 Ok(f32::from_le_bytes(bytes.try_into().unwrap()) as Self)
132 }
133 fn from_bytes_as_f64(bytes: &[u8]) -> Result<Self, String> {
134 Ok(f64::from_le_bytes(bytes.try_into().unwrap()) as Self)
135 }
136 fn from_bytes_as_string(_: &[u8]) -> Result<Self, String> {
137 Err("Not supported: string -> f64".to_string())
138 }
139 }
140 };
141}
142
143impl_get_parameter_value!(i8);
144impl_get_parameter_value!(u8);
145impl_get_parameter_value!(i16);
146impl_get_parameter_value!(u16);
147impl_get_parameter_value!(i32);
148impl_get_parameter_value!(u32);
149impl_get_parameter_value!(i64);
150impl_get_parameter_value!(u64);
151impl_get_parameter_value!(f32);
152impl_get_parameter_value!(f64);
153
154macro_rules! impl_get_parameter_array {
155 ($t:ty) => {
156 impl<const N: usize> GetParameterValue for [$t; N] {
157 fn from_bytes_as_bool(bytes: &[u8]) -> Result<Self, String> {
158 let mut result: Self = [Default::default(); N];
159 for i in 0..N {
160 let start = i;
161 let end = start + 1;
162 let chunk = &bytes[start..end]; result[i] = (if chunk[0] != 0 { 1u8 } else { 0u8 }) as $t;
164 }
165 Ok(result)
166 }
167 fn from_bytes_as_i8(bytes: &[u8]) -> Result<Self, String> {
168 let mut result: Self = [Default::default(); N];
169 for i in 0..N {
170 let start = i;
171 let end = start + 1;
172 let chunk = &bytes[start..end]; result[i] = i8::from_le_bytes(chunk.try_into().unwrap()) as $t; }
175 Ok(result)
176 }
177 fn from_bytes_as_u8(bytes: &[u8]) -> Result<Self, String> {
178 let mut result: Self = [Default::default(); N];
179 for i in 0..N {
180 let start = i;
181 let end = start + 1;
182 let chunk = &bytes[start..end]; result[i] = u8::from_le_bytes(chunk.try_into().unwrap()) as $t; }
185 Ok(result)
186 }
187 fn from_bytes_as_i16(bytes: &[u8]) -> Result<Self, String> {
188 let mut result: Self = [Default::default(); N];
189 for i in 0..N {
190 let start = i * 2;
191 let end = start + 2;
192 let chunk = &bytes[start..end]; result[i] = i16::from_le_bytes(chunk.try_into().unwrap()) as $t; }
195 Ok(result)
196 }
197 fn from_bytes_as_u16(bytes: &[u8]) -> Result<Self, String> {
198 let mut result: Self = [Default::default(); N];
199 for i in 0..N {
200 let start = i * 2;
201 let end = start + 2;
202 let chunk = &bytes[start..end]; result[i] = u16::from_le_bytes(chunk.try_into().unwrap()) as $t; }
205 Ok(result)
206 }
207 fn from_bytes_as_i32(bytes: &[u8]) -> Result<Self, String> {
208 let mut result: Self = [Default::default(); N];
209 for i in 0..N {
210 let start = i * 4;
211 let end = start + 4;
212 let chunk = &bytes[start..end]; result[i] = i32::from_le_bytes(chunk.try_into().unwrap()) as $t; }
215 Ok(result)
216 }
217 fn from_bytes_as_u32(bytes: &[u8]) -> Result<Self, String> {
218 let mut result: Self = [Default::default(); N];
219 for i in 0..N {
220 let start = i * 4;
221 let end = start + 4;
222 let chunk = &bytes[start..end]; result[i] = u32::from_le_bytes(chunk.try_into().unwrap()) as $t; }
225 Ok(result)
226 }
227 fn from_bytes_as_i64(bytes: &[u8]) -> Result<Self, String> {
228 let mut result: Self = [Default::default(); N];
229 for i in 0..N {
230 let start = i * 8;
231 let end = start + 8;
232 let chunk = &bytes[start..end]; result[i] = i64::from_le_bytes(chunk.try_into().unwrap()) as $t; }
235 Ok(result)
236 }
237 fn from_bytes_as_u64(bytes: &[u8]) -> Result<Self, String> {
238 let mut result: Self = [Default::default(); N];
239 for i in 0..N {
240 let start = i * 8;
241 let end = start + 8;
242 let chunk = &bytes[start..end]; result[i] = u64::from_le_bytes(chunk.try_into().unwrap()) as $t; }
245 Ok(result)
246 }
247 fn from_bytes_as_f32(bytes: &[u8]) -> Result<Self, String> {
248 let mut result: Self = [Default::default(); N];
249 for i in 0..N {
250 let start = i * 4;
251 let end = start + 4;
252 let chunk = &bytes[start..end]; result[i] = f32::from_le_bytes(chunk.try_into().unwrap()) as $t; }
255 Ok(result)
256 }
257 fn from_bytes_as_f64(bytes: &[u8]) -> Result<Self, String> {
258 let mut result: Self = [Default::default(); N];
259 for i in 0..N {
260 let start = i * 8;
261 let end = start + 8;
262 let chunk = &bytes[start..end]; result[i] = f64::from_le_bytes(chunk.try_into().unwrap()) as $t; }
265 Ok(result)
266 }
267 fn from_bytes_as_string(_: &[u8]) -> Result<Self, String> {
268 Ok([Default::default(); N])
269 }
270 }
271 };
272}
273
274impl_get_parameter_array!(i8);
275impl_get_parameter_array!(u8);
276impl_get_parameter_array!(i16);
277impl_get_parameter_array!(u16);
278impl_get_parameter_array!(i32);
279impl_get_parameter_array!(u32);
280impl_get_parameter_array!(i64);
281impl_get_parameter_array!(u64);
282impl_get_parameter_array!(f32);
283impl_get_parameter_array!(f64);
284
285impl<const N: usize> GetParameterValue for [bool; N] {
286 fn from_bytes_as_bool(bytes: &[u8]) -> Result<Self, String> {
287 let mut result: Self = [Default::default(); N];
288 for i in 0..N {
289 let start = i;
290 let end = start + 1;
291 let chunk = &bytes[start..end]; result[i] = chunk[0] != 0;
293 }
294 Ok(result)
295 }
296 fn from_bytes_as_i8(bytes: &[u8]) -> Result<Self, String> {
297 let mut result: Self = [Default::default(); N];
298 for i in 0..N {
299 let start = i;
300 let end = start + 1;
301 let chunk = &bytes[start..end]; result[i] = i8::from_le_bytes(chunk.try_into().unwrap()) != 0; }
304 Ok(result)
305 }
306 fn from_bytes_as_u8(bytes: &[u8]) -> Result<Self, String> {
307 let mut result: Self = [Default::default(); N];
308 for i in 0..N {
309 let start = i;
310 let end = start + 1;
311 let chunk = &bytes[start..end]; result[i] = u8::from_le_bytes(chunk.try_into().unwrap()) != 0; }
314 Ok(result)
315 }
316 fn from_bytes_as_i16(bytes: &[u8]) -> Result<Self, String> {
317 let mut result: Self = [Default::default(); N];
318 for i in 0..N {
319 let start = i * 2;
320 let end = start + 2;
321 let chunk = &bytes[start..end]; result[i] = i16::from_le_bytes(chunk.try_into().unwrap()) != 0; }
324 Ok(result)
325 }
326 fn from_bytes_as_u16(bytes: &[u8]) -> Result<Self, String> {
327 let mut result: Self = [Default::default(); N];
328 for i in 0..N {
329 let start = i * 2;
330 let end = start + 2;
331 let chunk = &bytes[start..end]; result[i] = u16::from_le_bytes(chunk.try_into().unwrap()) != 0; }
334 Ok(result)
335 }
336 fn from_bytes_as_i32(bytes: &[u8]) -> Result<Self, String> {
337 let mut result: Self = [Default::default(); N];
338 for i in 0..N {
339 let start = i * 4;
340 let end = start + 4;
341 let chunk = &bytes[start..end]; result[i] = i32::from_le_bytes(chunk.try_into().unwrap()) != 0; }
344 Ok(result)
345 }
346 fn from_bytes_as_u32(bytes: &[u8]) -> Result<Self, String> {
347 let mut result: Self = [Default::default(); N];
348 for i in 0..N {
349 let start = i * 4;
350 let end = start + 4;
351 let chunk = &bytes[start..end]; result[i] = u32::from_le_bytes(chunk.try_into().unwrap()) != 0; }
354 Ok(result)
355 }
356 fn from_bytes_as_i64(bytes: &[u8]) -> Result<Self, String> {
357 let mut result: Self = [Default::default(); N];
358 for i in 0..N {
359 let start = i * 8;
360 let end = start + 8;
361 let chunk = &bytes[start..end]; result[i] = i64::from_le_bytes(chunk.try_into().unwrap()) != 0; }
364 Ok(result)
365 }
366 fn from_bytes_as_u64(bytes: &[u8]) -> Result<Self, String> {
367 let mut result: Self = [Default::default(); N];
368 for i in 0..N {
369 let start = i * 8;
370 let end = start + 8;
371 let chunk = &bytes[start..end]; result[i] = u64::from_le_bytes(chunk.try_into().unwrap()) != 0; }
374 Ok(result)
375 }
376 fn from_bytes_as_f32(bytes: &[u8]) -> Result<Self, String> {
377 let mut result: Self = [Default::default(); N];
378 for i in 0..N {
379 let start = i * 4;
380 let end = start + 4;
381 let chunk = &bytes[start..end]; result[i] = f32::from_le_bytes(chunk.try_into().unwrap()) != 0.0; }
384 Ok(result)
385 }
386 fn from_bytes_as_f64(bytes: &[u8]) -> Result<Self, String> {
387 let mut result: Self = [Default::default(); N];
388 for i in 0..N {
389 let start = i * 8;
390 let end = start + 8;
391 let chunk = &bytes[start..end]; result[i] = f64::from_le_bytes(chunk.try_into().unwrap()) != 0.0; }
394 Ok(result)
395 }
396 fn from_bytes_as_string(_: &[u8]) -> Result<Self, String> {
397 Ok([Default::default(); N])
398 }
399}
400
401macro_rules! impl_get_parameter_vec {
402 ($t:ty) => {
403 impl GetParameterValue for Vec<$t> {
404 fn from_bytes_as_bool(bytes: &[u8]) -> Result<Self, String> {
405 let len = bytes.len();
406 let mut result = vec![Default::default(); len];
407 for i in 0..len {
408 let start = i;
409 let end = start + 1;
410 let chunk = &bytes[start..end]; result[i] = (if chunk[0] != 0 { 1u8 } else { 0u8 }) as $t;
412 }
413 Ok(result)
414 }
415 fn from_bytes_as_i8(bytes: &[u8]) -> Result<Self, String> {
416 let len = bytes.len();
417 let mut result = vec![Default::default(); len];
418 for i in 0..len {
419 let start = i;
420 let end = start + 1;
421 let chunk = &bytes[start..end]; result[i] = i8::from_le_bytes(chunk.try_into().unwrap()) as $t; }
424 Ok(result)
425 }
426 fn from_bytes_as_u8(bytes: &[u8]) -> Result<Self, String> {
427 let len = bytes.len() / 2;
428 let mut result = vec![Default::default(); len];
429 for i in 0..len {
430 let start = i;
431 let end = start + 1;
432 let chunk = &bytes[start..end]; result[i] = u8::from_le_bytes(chunk.try_into().unwrap()) as $t; }
435 Ok(result)
436 }
437 fn from_bytes_as_i16(bytes: &[u8]) -> Result<Self, String> {
438 let len = bytes.len() / 2;
439 let mut result = vec![Default::default(); len];
440 for i in 0..len {
441 let start = i * 2;
442 let end = start + 2;
443 let chunk = &bytes[start..end]; result[i] = i16::from_le_bytes(chunk.try_into().unwrap()) as $t; }
446 Ok(result)
447 }
448 fn from_bytes_as_u16(bytes: &[u8]) -> Result<Self, String> {
449 let len = bytes.len() / 4;
450 let mut result = vec![Default::default(); len];
451 for i in 0..len {
452 let start = i * 2;
453 let end = start + 2;
454 let chunk = &bytes[start..end]; result[i] = u16::from_le_bytes(chunk.try_into().unwrap()) as $t; }
457 Ok(result)
458 }
459 fn from_bytes_as_i32(bytes: &[u8]) -> Result<Self, String> {
460 let len = bytes.len() / 4;
461 let mut result = vec![Default::default(); len];
462 for i in 0..len {
463 let start = i * 4;
464 let end = start + 4;
465 let chunk = &bytes[start..end]; result[i] = i32::from_le_bytes(chunk.try_into().unwrap()) as $t; }
468 Ok(result)
469 }
470 fn from_bytes_as_u32(bytes: &[u8]) -> Result<Self, String> {
471 let len = bytes.len() / 4;
472 let mut result = vec![Default::default(); len];
473 for i in 0..len {
474 let start = i * 4;
475 let end = start + 4;
476 let chunk = &bytes[start..end]; result[i] = u32::from_le_bytes(chunk.try_into().unwrap()) as $t; }
479 Ok(result)
480 }
481 fn from_bytes_as_i64(bytes: &[u8]) -> Result<Self, String> {
482 let len = bytes.len() / 8;
483 let mut result = vec![Default::default(); len];
484 for i in 0..len {
485 let start = i * 8;
486 let end = start + 8;
487 let chunk = &bytes[start..end]; result[i] = i64::from_le_bytes(chunk.try_into().unwrap()) as $t; }
490 Ok(result)
491 }
492 fn from_bytes_as_u64(bytes: &[u8]) -> Result<Self, String> {
493 let len = bytes.len() / 8;
494 let mut result = vec![Default::default(); len];
495 for i in 0..len {
496 let start = i * 8;
497 let end = start + 8;
498 let chunk = &bytes[start..end]; result[i] = u64::from_le_bytes(chunk.try_into().unwrap()) as $t; }
501 Ok(result)
502 }
503 fn from_bytes_as_f32(bytes: &[u8]) -> Result<Self, String> {
504 let len = bytes.len() / 4;
505 let mut result = vec![Default::default(); len];
506 for i in 0..len {
507 let start = i * 4;
508 let end = start + 4;
509 let chunk = &bytes[start..end]; result[i] = f32::from_le_bytes(chunk.try_into().unwrap()) as $t; }
512 Ok(result)
513 }
514 fn from_bytes_as_f64(bytes: &[u8]) -> Result<Self, String> {
515 let len = bytes.len() / 8;
516 let mut result = vec![Default::default(); len];
517 for i in 0..len {
518 let start = i * 8;
519 let end = start + 8;
520 let chunk = &bytes[start..end]; result[i] = f64::from_le_bytes(chunk.try_into().unwrap()) as $t; }
523 Ok(result)
524 }
525 fn from_bytes_as_string(bytes: &[u8]) -> Result<Self, String> {
526 Ok(vec![Default::default(); bytes.len()])
527 }
528 }
529 };
530}
531
532impl_get_parameter_vec!(i8);
533impl_get_parameter_vec!(u8);
534impl_get_parameter_vec!(i16);
535impl_get_parameter_vec!(u16);
536impl_get_parameter_vec!(i32);
537impl_get_parameter_vec!(u32);
538impl_get_parameter_vec!(i64);
539impl_get_parameter_vec!(u64);
540impl_get_parameter_vec!(f32);
541impl_get_parameter_vec!(f64);
542
543impl GetParameterValue for Vec<bool> {
544 fn from_bytes_as_bool(bytes: &[u8]) -> Result<Self, String> {
545 let len = bytes.len();
546 let mut result = vec![Default::default(); len];
547 for i in 0..len {
548 let start = i;
549 let end = start + 1;
550 let chunk = &bytes[start..end]; result[i] = chunk[0] != 0;
552 }
553 Ok(result)
554 }
555 fn from_bytes_as_i8(bytes: &[u8]) -> Result<Self, String> {
556 let len = bytes.len();
557 let mut result = vec![Default::default(); len];
558 for i in 0..len {
559 let start = i;
560 let end = start + 1;
561 let chunk = &bytes[start..end]; result[i] = i8::from_le_bytes(chunk.try_into().unwrap()) != 0; }
564 Ok(result)
565 }
566 fn from_bytes_as_u8(bytes: &[u8]) -> Result<Self, String> {
567 let len = bytes.len();
568 let mut result = vec![Default::default(); len];
569 for i in 0..len {
570 let start = i;
571 let end = start + 1;
572 let chunk = &bytes[start..end]; result[i] = u8::from_le_bytes(chunk.try_into().unwrap()) != 0; }
575 Ok(result)
576 }
577 fn from_bytes_as_i16(bytes: &[u8]) -> Result<Self, String> {
578 let len = bytes.len() / 2;
579 let mut result = vec![Default::default(); len];
580 for i in 0..len {
581 let start = i * 2;
582 let end = start + 2;
583 let chunk = &bytes[start..end]; result[i] = i16::from_le_bytes(chunk.try_into().unwrap()) != 0; }
586 Ok(result)
587 }
588 fn from_bytes_as_u16(bytes: &[u8]) -> Result<Self, String> {
589 let len = bytes.len() / 2;
590 let mut result = vec![Default::default(); len];
591 for i in 0..len {
592 let start = i * 2;
593 let end = start + 2;
594 let chunk = &bytes[start..end]; result[i] = u16::from_le_bytes(chunk.try_into().unwrap()) != 0; }
597 Ok(result)
598 }
599 fn from_bytes_as_i32(bytes: &[u8]) -> Result<Self, String> {
600 let len = bytes.len() / 4;
601 let mut result = vec![Default::default(); len];
602 for i in 0..len {
603 let start = i * 4;
604 let end = start + 4;
605 let chunk = &bytes[start..end]; result[i] = i32::from_le_bytes(chunk.try_into().unwrap()) != 0; }
608 Ok(result)
609 }
610 fn from_bytes_as_u32(bytes: &[u8]) -> Result<Self, String> {
611 let len = bytes.len() / 4;
612 let mut result = vec![Default::default(); len];
613 for i in 0..len {
614 let start = i * 4;
615 let end = start + 4;
616 let chunk = &bytes[start..end]; result[i] = u32::from_le_bytes(chunk.try_into().unwrap()) != 0; }
619 Ok(result)
620 }
621 fn from_bytes_as_i64(bytes: &[u8]) -> Result<Self, String> {
622 let len = bytes.len() / 8;
623 let mut result = vec![Default::default(); len];
624 for i in 0..len {
625 let start = i * 8;
626 let end = start + 8;
627 let chunk = &bytes[start..end]; result[i] = i64::from_le_bytes(chunk.try_into().unwrap()) != 0; }
630 Ok(result)
631 }
632 fn from_bytes_as_u64(bytes: &[u8]) -> Result<Self, String> {
633 let len = bytes.len() / 8;
634 let mut result = vec![Default::default(); len];
635 for i in 0..len {
636 let start = i * 8;
637 let end = start + 8;
638 let chunk = &bytes[start..end]; result[i] = u64::from_le_bytes(chunk.try_into().unwrap()) != 0; }
641 Ok(result)
642 }
643 fn from_bytes_as_f32(bytes: &[u8]) -> Result<Self, String> {
644 let len = bytes.len() / 4;
645 let mut result = vec![Default::default(); len];
646 for i in 0..len {
647 let start = i * 4;
648 let end = start + 4;
649 let chunk = &bytes[start..end]; result[i] = f32::from_le_bytes(chunk.try_into().unwrap()) != 0.0; }
652 Ok(result)
653 }
654 fn from_bytes_as_f64(bytes: &[u8]) -> Result<Self, String> {
655 let len = bytes.len() / 8;
656 let mut result = vec![Default::default(); len];
657 for i in 0..len {
658 let start = i * 8;
659 let end = start + 8;
660 let chunk = &bytes[start..end]; result[i] = f64::from_le_bytes(chunk.try_into().unwrap()) != 0.0; }
663 Ok(result)
664 }
665 fn from_bytes_as_string(bytes: &[u8]) -> Result<Self, String> {
666 Ok(vec![false; bytes.len()])
667 }
668}