dlt_parse 0.10.1

A library for parsing the "Diagnostic Log and Trace" network protocol (currently without payload interpretation).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
use arrayvec::{ArrayVec, CapacityError};

use crate::verbose::{Scaling, VariableInfoUnit};

/// Verbose 64 bit unsigned integer.
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct U64Value<'a> {
    pub variable_info: Option<VariableInfoUnit<'a>>,
    pub scaling: Option<Scaling<i64>>,
    pub value: u64,
}

impl<'a> U64Value<'a> {
    /// Adds the verbose value to the given dlt mesage buffer.
    pub fn add_to_msg<const CAP: usize>(
        &self,
        buf: &mut ArrayVec<u8, CAP>,
        is_big_endian: bool,
    ) -> Result<(), CapacityError> {
        if let Some(var_info) = &self.variable_info {
            let name_len;
            let unit_len;
            if is_big_endian {
                name_len = (var_info.name.len() as u16 + 1).to_be_bytes();
                unit_len = (var_info.unit.len() as u16 + 1).to_be_bytes();
            } else {
                name_len = (var_info.name.len() as u16 + 1).to_le_bytes();
                unit_len = (var_info.unit.len() as u16 + 1).to_le_bytes();
            };

            if let Some(scaler) = &self.scaling {
                let type_info = [0b0100_0100, 0b0001_1000, 0b0000_0000, 0b0000_0000];
                let quantization;
                let offset: [u8; 8];

                if is_big_endian {
                    quantization = scaler.quantization.to_be_bytes();
                    offset = scaler.offset.to_be_bytes();
                } else {
                    quantization = scaler.quantization.to_le_bytes();
                    offset = scaler.offset.to_le_bytes();
                }
                buf.try_extend_from_slice(&type_info)?;
                buf.try_extend_from_slice(&[name_len[0], name_len[1], unit_len[0], unit_len[1]])?;
                buf.try_extend_from_slice(var_info.name.as_bytes())?;
                if buf.remaining_capacity() > var_info.unit.len() + 2 {
                    // Safe as capacity is checked earlier
                    unsafe { buf.push_unchecked(0) };
                    let _ = buf.try_extend_from_slice(var_info.unit.as_bytes());
                    unsafe { buf.push_unchecked(0) };
                } else {
                    return Err(CapacityError::new(()));
                }

                buf.try_extend_from_slice(&quantization)?;
                buf.try_extend_from_slice(&offset)?;
            } else {
                let type_info = [0b0100_0100, 0b0000_1000, 0b0000_0000, 0b0000_0000];

                buf.try_extend_from_slice(&type_info)?;
                buf.try_extend_from_slice(&[name_len[0], name_len[1], unit_len[0], unit_len[1]])?;
                buf.try_extend_from_slice(var_info.name.as_bytes())?;
                if buf.remaining_capacity() > var_info.unit.len() + 2 {
                    // Safe as capacity is checked earlier
                    unsafe { buf.push_unchecked(0) };
                    let _ = buf.try_extend_from_slice(var_info.unit.as_bytes());
                    unsafe { buf.push_unchecked(0) };
                } else {
                    return Err(CapacityError::new(()));
                }
            }
        }
        // No name & unit
        else if let Some(scaler) = &self.scaling {
            let type_info: [u8; 4] = [0b0100_0100, 0b0001_0000, 0b0000_0000, 0b0000_0000];

            let quantization;
            let offset: [u8; 8];
            if is_big_endian {
                quantization = scaler.quantization.to_be_bytes();
                offset = scaler.offset.to_be_bytes();
            } else {
                quantization = scaler.quantization.to_le_bytes();
                offset = scaler.offset.to_le_bytes();
            }
            buf.try_extend_from_slice(&type_info)?;
            buf.try_extend_from_slice(&quantization)?;
            buf.try_extend_from_slice(&offset)?;
        } else {
            let type_info: [u8; 4] = [0b0100_0100, 0b0000_0000, 0b0000_0000, 0b0000_0000];
            buf.try_extend_from_slice(&type_info)?;
        }

        // value
        if is_big_endian {
            buf.try_extend_from_slice(&self.value.to_be_bytes())
        } else {
            buf.try_extend_from_slice(&self.value.to_le_bytes())
        }
    }
}

#[cfg(test)]
mod test {
    use super::*;
    use crate::verbose::VerboseValue;
    use crate::verbose::VerboseValue::U64;
    use alloc::vec::Vec;
    use proptest::prelude::*;
    use std::format;

    proptest! {
        #[test]
        fn write_read(value in any::<u64>(), ref name in "\\pc{0,20}", ref unit in "\\pc{0,20}", quantization in any::<f32>(), offset in any::<i64>()) {
            const MAX_SYMBOL_LENGTH_NAME: usize = 20;
            const MAX_SYMBOL_LENGTH_UNIT: usize = 20;
            const FIXED_POINT_LENGTH: usize = 12;
            const BYTES_NEEDED: usize = 12;
            const BYTES_NEEDED_WITH_NAME: usize = 6 + BYTES_NEEDED;

            // The buffer needs to be sized the (max len of the name + max len unit) * 4 + 11 bits. (11 Byte: 4 Byte TypeInfo + 2 Bytes Length of Name + 1 Byte Null Terminator of Name + 2 Byte unit Length + 1 Byte Null Terminator Unit + 1 Byte Data)
            // As Proptest only generates chars by characters (which can be up to 4 bytes), the buffer needs to be 4 * len of name
            const BUFFER_SIZE_NO_FIXED_POINT: usize = MAX_SYMBOL_LENGTH_NAME * 4 + MAX_SYMBOL_LENGTH_UNIT * 4 + BYTES_NEEDED_WITH_NAME;
            const BUFFER_SIZE_FIXED_POINT: usize = BUFFER_SIZE_NO_FIXED_POINT + FIXED_POINT_LENGTH;

            // test big endian with name and fixed point
            {
                let mut msg_buff: ArrayVec<u8, BUFFER_SIZE_FIXED_POINT> = ArrayVec::new();
                let slice_len = name.len() + unit.len() + FIXED_POINT_LENGTH + BYTES_NEEDED_WITH_NAME;
                let is_big_endian = true;

                let variable_info = Some(VariableInfoUnit { name , unit });
                let scaling = Some(Scaling { quantization, offset });

                let u64_value = U64Value {variable_info, scaling, value};
                let mut content_buff = Vec::with_capacity(slice_len);

                let len_name_be = (name.len() as u16 + 1).to_be_bytes();
                let len_unit_be = (unit.len() as u16 + 1).to_be_bytes();

                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Ok(()));

                content_buff.extend_from_slice(&[0b0100_0100, 0b0001_1000, 0b0000_0000, 0b0000_0000, len_name_be[0], len_name_be[1], len_unit_be[0], len_unit_be[1]]);
                content_buff.extend_from_slice(name.as_bytes());
                content_buff.push(0);
                content_buff.extend_from_slice(unit.as_bytes());
                content_buff.push(0);
                content_buff.extend_from_slice(&quantization.to_be_bytes());
                content_buff.extend_from_slice(&offset.to_be_bytes());
                content_buff.extend_from_slice(&value.to_be_bytes());

                prop_assert_eq!(&msg_buff[..slice_len], &content_buff[..]);

                // Now wrap back
                let parsed_back = VerboseValue::from_slice(&msg_buff, is_big_endian);
                prop_assert_eq!(parsed_back, Ok((U64(u64_value),&[] as &[u8])));

            }

                        // test big endian with name and fixed point
            {
                let mut msg_buff: ArrayVec<u8, BUFFER_SIZE_FIXED_POINT> = ArrayVec::new();
                let slice_len = name.len() + unit.len() + FIXED_POINT_LENGTH + BYTES_NEEDED_WITH_NAME;
                let is_big_endian = true;

                let variable_info = Some(VariableInfoUnit { name , unit });
                let scaling = Some(Scaling { quantization, offset });

                let u64_value = U64Value {variable_info, scaling, value};
                let mut content_buff = Vec::with_capacity(slice_len);

                let len_name_be = (name.len() as u16 + 1).to_be_bytes();
                let len_unit_be = (unit.len() as u16 + 1).to_be_bytes();

                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Ok(()));

                content_buff.extend_from_slice(&[0b0100_0100, 0b0001_1000, 0b0000_0000, 0b0000_0000, len_name_be[0], len_name_be[1], len_unit_be[0], len_unit_be[1]]);
                content_buff.extend_from_slice(name.as_bytes());
                content_buff.push(0);
                content_buff.extend_from_slice(unit.as_bytes());
                content_buff.push(0);
                content_buff.extend_from_slice(&quantization.to_be_bytes());
                content_buff.extend_from_slice(&offset.to_be_bytes());
                content_buff.extend_from_slice(&value.to_be_bytes());

                prop_assert_eq!(&msg_buff[..slice_len], &content_buff[..]);

                // Now wrap back
                let parsed_back = VerboseValue::from_slice(&msg_buff, is_big_endian);
                prop_assert_eq!(parsed_back, Ok((U64(u64_value),&[] as &[u8])));

            }
            // test little endian with name and fixed point
            {
                let mut msg_buff: ArrayVec<u8, BUFFER_SIZE_FIXED_POINT> = ArrayVec::new();
                let slice_len = name.len() + unit.len() + FIXED_POINT_LENGTH + BYTES_NEEDED_WITH_NAME;
                let is_big_endian = false;

                let variable_info = Some(VariableInfoUnit { name , unit });
                let scaling = Some(Scaling { quantization, offset });

                let u64_value = U64Value {variable_info, scaling, value};
                let mut content_buff = Vec::with_capacity(slice_len);

                let len_name_le = (name.len() as u16 + 1).to_le_bytes();
                let len_unit_le = (unit.len() as u16 + 1).to_le_bytes();

                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Ok(()));

                content_buff.extend_from_slice(&[0b0100_0100, 0b0001_1000, 0b0000_0000, 0b0000_0000, len_name_le[0], len_name_le[1], len_unit_le[0], len_unit_le[1]]);
                content_buff.extend_from_slice(name.as_bytes());
                content_buff.push(0);
                content_buff.extend_from_slice(unit.as_bytes());
                content_buff.push(0);
                content_buff.extend_from_slice(&quantization.to_le_bytes());
                content_buff.extend_from_slice(&offset.to_le_bytes());
                content_buff.extend_from_slice(&value.to_le_bytes());

                prop_assert_eq!(&msg_buff[..slice_len], &content_buff[..]);

                // Now wrap back
                let parsed_back = VerboseValue::from_slice(&msg_buff, is_big_endian);
                prop_assert_eq!(parsed_back, Ok((U64(u64_value),&[] as &[u8])));

            }

            // test big endian with name without fixed point
          {
            let mut msg_buff: ArrayVec<u8, BUFFER_SIZE_NO_FIXED_POINT> = ArrayVec::new();
            let slice_len = name.len() + unit.len() + BYTES_NEEDED_WITH_NAME;
            let is_big_endian = true;

            let variable_info = Some(VariableInfoUnit { name , unit });
            let scaling = None;

            let u64_value = U64Value {variable_info, scaling, value};
            let mut content_buff = Vec::with_capacity(slice_len);

            let len_name_be = (name.len() as u16 + 1).to_be_bytes();
            let len_unit_be = (unit.len() as u16 + 1).to_be_bytes();

            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Ok(()));

            content_buff.extend_from_slice(&[0b0100_0100, 0b0000_1000, 0b0000_0000, 0b0000_0000, len_name_be[0], len_name_be[1], len_unit_be[0], len_unit_be[1]]);
            content_buff.extend_from_slice(name.as_bytes());
            content_buff.push(0);
            content_buff.extend_from_slice(unit.as_bytes());
            content_buff.push(0);
            content_buff.extend_from_slice(&value.to_be_bytes());

            prop_assert_eq!(&msg_buff[..slice_len], &content_buff[..]);

            // Now wrap back
            let parsed_back = VerboseValue::from_slice(&msg_buff, is_big_endian);
            prop_assert_eq!(parsed_back, Ok((U64(u64_value),&[] as &[u8])));

         }

            // test little endian with name without fixed point
            {
                let mut msg_buff: ArrayVec<u8, BUFFER_SIZE_NO_FIXED_POINT> = ArrayVec::new();
                let slice_len = name.len() + unit.len() + BYTES_NEEDED_WITH_NAME;
                let is_big_endian = false;

                let variable_info = Some(VariableInfoUnit { name , unit });
                let scaling = None;

                let u64_value = U64Value {variable_info, scaling, value};
                let mut content_buff = Vec::with_capacity(slice_len);

                let len_name_le = (name.len() as u16 + 1).to_le_bytes();
                let len_unit_le = (unit.len() as u16 + 1).to_le_bytes();

                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Ok(()));

                content_buff.extend_from_slice(&[0b0100_0100, 0b0000_1000, 0b0000_0000, 0b0000_0000, len_name_le[0], len_name_le[1], len_unit_le[0], len_unit_le[1]]);
                content_buff.extend_from_slice(name.as_bytes());
                content_buff.push(0);
                content_buff.extend_from_slice(unit.as_bytes());
                content_buff.push(0);
                content_buff.extend_from_slice(&value.to_le_bytes());

                prop_assert_eq!(&msg_buff[..slice_len], &content_buff[..]);

                // Now wrap back
                let parsed_back = VerboseValue::from_slice(&msg_buff, is_big_endian);
                prop_assert_eq!(parsed_back, Ok((U64(u64_value),&[] as &[u8])));

             }


        // test big endian without name, unit and without fixed point
        {
            let mut msg_buff: ArrayVec<u8, BUFFER_SIZE_NO_FIXED_POINT> = ArrayVec::new();
            let slice_len = BYTES_NEEDED;
            let is_big_endian = true;

            let variable_info = None;
            let scaling = None;

            let u64_value = U64Value {variable_info, scaling, value};
            let mut content_buff = Vec::with_capacity(slice_len);

            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Ok(()));

            content_buff.extend_from_slice(&[0b0100_0100, 0b0000_0000, 0b0000_0000, 0b0000_0000]);
            content_buff.extend_from_slice(&value.to_be_bytes());

            prop_assert_eq!(&msg_buff[..slice_len], &content_buff[..]);

            // Now wrap back
            let parsed_back = VerboseValue::from_slice(&msg_buff, is_big_endian);
            prop_assert_eq!(parsed_back, Ok((U64(u64_value),&[] as &[u8])));

            }

        // test little endian without name, unit and without fixed point
        {
            let mut msg_buff: ArrayVec<u8, BUFFER_SIZE_NO_FIXED_POINT> = ArrayVec::new();
            let slice_len = BYTES_NEEDED;
            let is_big_endian = false;

            let variable_info = None;
            let scaling = None;

            let u64_value = U64Value {variable_info, scaling, value};
            let mut content_buff = Vec::with_capacity(slice_len);

            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Ok(()));

            content_buff.extend_from_slice(&[0b0100_0100, 0b0000_0000, 0b0000_0000, 0b0000_0000]);
            content_buff.extend_from_slice(&value.to_le_bytes());

            prop_assert_eq!(&msg_buff[..slice_len], &content_buff[..]);

            // Now wrap back
            let parsed_back = VerboseValue::from_slice(&msg_buff, is_big_endian);
            prop_assert_eq!(parsed_back, Ok((U64(u64_value),&[] as &[u8])));

            }


        // test big endian with fixed point and without name
        {
            let mut msg_buff: ArrayVec<u8, BUFFER_SIZE_FIXED_POINT> = ArrayVec::new();
            let slice_len = FIXED_POINT_LENGTH + BYTES_NEEDED;
            let is_big_endian = true;

            let variable_info = None;
            let scaling = Some(Scaling { quantization, offset });

            let u64_value = U64Value {variable_info, scaling, value};
            let mut content_buff = Vec::with_capacity(slice_len);

            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Ok(()));

            content_buff.extend_from_slice(&[0b0100_0100, 0b0001_0000, 0b0000_0000, 0b0000_0000]);
            content_buff.extend_from_slice(&quantization.to_be_bytes());
            content_buff.extend_from_slice(&offset.to_be_bytes());
            content_buff.extend_from_slice(&value.to_be_bytes());

            prop_assert_eq!(&msg_buff[..slice_len], &content_buff[..]);

            // Now wrap back
            let parsed_back = VerboseValue::from_slice(&msg_buff, is_big_endian);
            prop_assert_eq!(parsed_back, Ok((U64(u64_value),&[] as &[u8])));

        }

        // test little endian with fixed point and without name
        {
            let mut msg_buff: ArrayVec<u8, BUFFER_SIZE_FIXED_POINT> = ArrayVec::new();
            let slice_len = FIXED_POINT_LENGTH + BYTES_NEEDED;
            let is_big_endian = false;

            let variable_info = None;
            let scaling = Some(Scaling { quantization, offset });

            let u64_value = U64Value {variable_info, scaling, value};
            let mut content_buff = Vec::with_capacity(slice_len);

            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Ok(()));

            content_buff.extend_from_slice(&[0b0100_0100, 0b0001_0000, 0b0000_0000, 0b0000_0000]);
            content_buff.extend_from_slice(&quantization.to_le_bytes());
            content_buff.extend_from_slice(&offset.to_le_bytes());
            content_buff.extend_from_slice(&value.to_le_bytes());

            prop_assert_eq!(&msg_buff[..slice_len], &content_buff[..]);

            // Now wrap back
            let parsed_back = VerboseValue::from_slice(&msg_buff, is_big_endian);
            prop_assert_eq!(parsed_back, Ok((U64(u64_value),&[] as &[u8])));

        }

         // Capacity error big endian with name and scaling
         {
            const SLICE_LEN: usize = FIXED_POINT_LENGTH + BYTES_NEEDED_WITH_NAME - 1;
            let variable_info = Some(VariableInfoUnit { name , unit });
            let scaling = Some(Scaling { quantization, offset });

            let u64_value = U64Value {variable_info, scaling, value};
            let is_big_endian = true;

            let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

        }

        // Capacity error little endian with name and scaling
        {
            const SLICE_LEN: usize = FIXED_POINT_LENGTH + BYTES_NEEDED_WITH_NAME - 1;
            let variable_info = Some(VariableInfoUnit { name , unit });
            let scaling = Some(Scaling { quantization, offset });

            let u64_value = U64Value {variable_info, scaling, value};
            let is_big_endian = false;

            let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

        }

        // Capacity error big endian with name, without scaling
        {
            const SLICE_LEN: usize = BYTES_NEEDED_WITH_NAME - 1;
            let variable_info = Some(VariableInfoUnit { name , unit });
            let scaling = None;

            let u64_value = U64Value {variable_info, scaling, value};
            let is_big_endian = true;

            let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

        }

        // Capacity error big endian with name, without scaling
        {
            const SLICE_LEN: usize = BYTES_NEEDED_WITH_NAME - 1;
            let variable_info = Some(VariableInfoUnit { name , unit });
            let scaling = None;

            let u64_value = U64Value {variable_info, scaling, value};
            let is_big_endian = false;

            let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

        }

        // Capacity error big endian without name, without scaling
        {
            const SLICE_LEN: usize = BYTES_NEEDED - 1;
            let variable_info = None;
            let scaling = None;

            let u64_value = U64Value {variable_info, scaling, value};
            let is_big_endian = true;

            let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

        }

        // Capacity error little endian without name, without scaling
        {
            const SLICE_LEN: usize = BYTES_NEEDED - 1;
            let variable_info = None;
            let scaling = None;

            let u64_value = U64Value {variable_info, scaling, value};
            let is_big_endian = false;

            let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

        }

        // Capacity error big endian with scaling and without name
        {
            const SLICE_LEN: usize = FIXED_POINT_LENGTH + BYTES_NEEDED - 1;
            let variable_info = None;
            let scaling = Some(Scaling { quantization, offset });

            let u64_value = U64Value {variable_info, scaling, value};
            let is_big_endian = true;

            let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

        }

        // Capacity error little endian with scaling and without name
        {
            const SLICE_LEN: usize = FIXED_POINT_LENGTH + BYTES_NEEDED - 1;
            let variable_info = None;
            let scaling = Some(Scaling { quantization, offset });

            let u64_value = U64Value {variable_info, scaling, value};
            let is_big_endian = false;

            let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
            prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

        }


            // Capacity error 2 with name & scaling: Type info only
            {
                const SLICE_LEN: usize = 4; // Only type info fits in
                let variable_info = Some(VariableInfoUnit { name , unit });
                let scaling = Some(Scaling { quantization, offset });

                let u64_value = U64Value {variable_info, scaling, value};
                let is_big_endian = true;

                let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

                let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            }

            // Capacity error 2 without name & scaling: Type info only
            {
                const SLICE_LEN: usize = 4; // Only type info fits in
                let variable_info = Some(VariableInfoUnit { name , unit });
                let scaling = None;

                let u64_value = U64Value {variable_info, scaling, value};
                let is_big_endian = true;

                let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

                let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            }

            // Capacity error 3: With name & unit: Offset does not fit in
            {
                const SLICE_LEN: usize = BYTES_NEEDED + FIXED_POINT_LENGTH + 5;
                let variable_info = Some(VariableInfoUnit { name:"Abc" , unit:"defg" });
                let scaling = Some(Scaling { quantization, offset });

                let u64_value = U64Value {variable_info, scaling, value};
                let is_big_endian = true;

                let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

                let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            }

            // Capacity error 3: Without name & unit: Offset does not fit in
            {
                const SLICE_LEN: usize = BYTES_NEEDED + FIXED_POINT_LENGTH - 9;
                let variable_info = None;
                let scaling = Some(Scaling { quantization, offset });

                let u64_value = U64Value {variable_info, scaling, value};
                let is_big_endian = true;

                let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

                let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            }

            // Capacity error 4: With name & unit: Quantization does not fit in
            {
                const SLICE_LEN: usize = 17;
                let variable_info = Some(VariableInfoUnit { name:"Abc" , unit:"defg" });
                let scaling = Some(Scaling { quantization, offset });

                let u64_value = U64Value {variable_info, scaling, value};
                let is_big_endian = true;

                let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

                let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            }

            // Capacity error 4: Without name & unit: Quantization does not fit in
            {
                const SLICE_LEN: usize = 7;
                let variable_info = None;
                let scaling = Some(Scaling { quantization, offset });

                let u64_value = U64Value {variable_info, scaling, value};
                let is_big_endian = true;

                let mut msg_buff: ArrayVec<u8, SLICE_LEN> = ArrayVec::new();
                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

                let mut msg_buff: ArrayVec<u8, 0> = ArrayVec::new();
                prop_assert_eq!(u64_value.add_to_msg(&mut msg_buff, is_big_endian), Err(CapacityError::new(())));

            }

        }
    }
    proptest! {
        #[test]
        fn debug(value in any::<u64>(), ref name in "\\pc{0,20}", ref unit in "\\pc{0,20}", quantization in any::<f32>(), offset in any::<i64>()) {
            { // Test with name, unit & scaling
            let value_struct: U64Value = U64Value {variable_info: Some(VariableInfoUnit { name, unit }), scaling: Some(Scaling { quantization, offset }), value};
            assert_eq!(
                    format!(
                        "U64Value {{ variable_info: {:?}, scaling: {:?}, value: {:?} }}",
                        value_struct.variable_info,
                        value_struct.scaling,
                        value_struct.value,
                    ),
                    format!("{:?}", value_struct)
                );
            }

            { // Test with name, unit & without scaling
                let value_struct: U64Value = U64Value {variable_info: Some(VariableInfoUnit { name, unit }), scaling: None, value};
                assert_eq!(
                        format!(
                            "U64Value {{ variable_info: {:?}, scaling: {:?}, value: {:?} }}",
                            value_struct.variable_info,
                            value_struct.scaling,
                            value_struct.value,
                        ),
                        format!("{:?}", value_struct)
                    );
                }

            { // Test without name, unit & without scaling
                let value_struct: U64Value = U64Value {variable_info: None, scaling: None, value};
                assert_eq!(
                        format!(
                            "U64Value {{ variable_info: {:?}, scaling: {:?}, value: {:?} }}",
                            value_struct.variable_info,
                            value_struct.scaling,
                            value_struct.value,
                        ),
                        format!("{:?}", value_struct)
                    );
                }

           { // Test with scaling, but without name & unit
            let value_struct: U64Value = U64Value {variable_info: None, scaling: Some(Scaling { quantization, offset }), value};
            assert_eq!(
                    format!(
                        "U64Value {{ variable_info: {:?}, scaling: {:?}, value: {:?} }}",
                        value_struct.variable_info,
                        value_struct.scaling,
                        value_struct.value,
                    ),
                    format!("{:?}", value_struct)
                );
            }
        }
    }
}