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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
use core::fmt;
use std::{
    ops::{Deref, Index},
    str::FromStr,
};

use yaserde::{DefaultYaSerde, PrimitiveYaSerde};

#[cfg(test)]
use crate::{deserialize, serialize};

use crate::traits::Validate;

/// We purposefully don't use type aliases, as our procedural macros cannot determine whether a type is a primitive using an alias to it
/// This means types that are just primitive aliases cannot be used without these primitive newtypes.
/// We require newtypes for non-standard integer types regardless.

/// Unsigned integer, max inclusive 255 (2^8-1)
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug, PrimitiveYaSerde)]
pub struct Uint8(pub u8);

impl Deref for Uint8 {
    type Target = u8;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl Validate for Uint8 {}
/// Unsigned integer, max inclusive 65535 (2^16-1)
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug, PrimitiveYaSerde)]
pub struct Uint16(pub u16);

impl Deref for Uint16 {
    type Target = u16;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl Validate for Uint16 {}
/// Unsigned integer, max inclusive 4294967295 (2^32-1)
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug, PrimitiveYaSerde)]
pub struct Uint32(pub u32);

impl Uint32 {
    pub fn get(&self) -> u32 {
        self.0
    }
}

impl Validate for Uint32 {}
/// Unsigned integer, max inclusive 1099511627775 (2^40-1)
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug, PrimitiveYaSerde)]
pub struct Uint40(pub u64);

impl Deref for Uint40 {
    type Target = u64;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl Validate for Uint40 {
    fn validate(&self) -> Result<(), String> {
        if self.0 > "281474976710655".parse::<u64>().unwrap() {
            return Err(format!("MaxInclusive validation error: invalid value of 0! \nExpected: 0 <= 281474976710655.\nActual: 0 == {}", self.0));
        }
        Ok(())
    }
}

/// Unsigned integer, max inclusive 281474976710655 (2^48-1)
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug, PrimitiveYaSerde)]
pub struct Uint48(pub u64);

impl Deref for Uint48 {
    type Target = u64;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl Validate for Uint48 {
    fn validate(&self) -> Result<(), String> {
        if self.0 > "281474976710655".parse::<u64>().unwrap() {
            return Err(format!("MaxInclusive validation error: invalid value of 0! \nExpected: 0 <= 281474976710655.\nActual: 0 == {}", self.0));
        }
        Ok(())
    }
}

/// Unsigned integer, max inclusive 18446744073709551615 (2^64-1)
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug, PrimitiveYaSerde)]
pub struct Uint64(pub u64);

impl Deref for Uint64 {
    type Target = u64;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl Validate for Uint64 {}
/// Signed integer, min -128 max +127
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug, PrimitiveYaSerde)]
pub struct Int8(pub i8);

impl Deref for Int8 {
    type Target = i8;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl Validate for Int8 {}
/// Signed integer, min -32768 max +32767
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug, PrimitiveYaSerde)]
pub struct Int16(pub i16);

impl Deref for Int16 {
    type Target = i16;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl Validate for Int16 {}
/// Signed integer, max inclusive 2147483647 (2^31), min inclusive -2147483647
/// (same as xs:int)
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug, PrimitiveYaSerde)]
pub struct Int32(pub i32);

impl Deref for Int32 {
    type Target = i32;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl Validate for Int32 {}
/// Signed integer, max inclusive 140737488355328 (2^47), min inclusive
/// -140737488355328
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug, PrimitiveYaSerde)]
pub struct Int48(pub i64);

impl Deref for Int48 {
    type Target = i64;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl Validate for Int48 {
    fn validate(&self) -> Result<(), String> {
        if self.0 > "140737488355328".parse::<i64>().unwrap() {
            return Err(format!("MaxInclusive validation error: invalid value! \nExpected: 0 <= 140737488355328.\nActual: 0 == {}", self.0));
        }
        if self.0 < "-140737488355328".parse::<i64>().unwrap() {
            return Err(format!("MinInclusive validation error: invalid value! \nExpected: 0 >= -140737488355328.\nActual: 0 == {}", self.0));
        }
        Ok(())
    }
}

/// Signed integer, max inclusive 9223372036854775807 (2^63), min inclusive
/// -9223372036854775808 (same as xs:long)
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, Debug, PrimitiveYaSerde)]
pub struct Int64(pub i64);

impl Int64 {
    pub fn get(&self) -> i64 {
        self.0
    }
}

impl Validate for Int64 {}

/// An 8-bit field encoded as a hex string (2 hex characters). Where applicable,
/// bit 0, or the least significant bit, goes on the right. Note that hexBinary
/// requires pairs of hex characters, so an odd number of characters requires a
/// leading "0".
#[derive(Default, Hash, PartialEq, Eq, Debug, Clone, Copy, DefaultYaSerde)]
pub struct HexBinary8(pub u8);

impl Validate for HexBinary8 {}

impl fmt::Display for HexBinary8 {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{:#04x?}", self.0)
    }
}

impl FromStr for HexBinary8 {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(HexBinary8(
            u8::from_str_radix(&s[2..], 16).map_err(|_| "could not parse hexbinary8")?,
        ))
    }
}

/// A 16-bit field encoded as a hex string (4 hex characters max). Where
/// applicable, bit 0, or the least significant bit, goes on the right. Note that
/// hexBinary requires pairs of hex characters, so an odd number of characters
/// requires a leading "0".
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Debug, Clone, Copy, DefaultYaSerde)]
pub struct HexBinary16(pub u16);

impl Validate for HexBinary16 {}

impl fmt::Display for HexBinary16 {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{:#06x?}", self.0)
    }
}

impl FromStr for HexBinary16 {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(HexBinary16(
            u16::from_str_radix(&s[2..], 16).map_err(|_| "could not parse hexbinary16")?,
        ))
    }
}

/// A 32-bit field encoded as a hex string (8 hex characters max). Where
/// applicable, bit 0, or the least significant bit, goes on the right. Note that
/// hexBinary requires pairs of hex characters, so an odd number of characters
/// requires a leading "0".
#[derive(Default, Hash, PartialEq, Eq, Debug, Clone, Copy, DefaultYaSerde)]
pub struct HexBinary32(pub u32);

impl Validate for HexBinary32 {}

impl fmt::Display for HexBinary32 {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{:#010x?}", self.0)
    }
}

impl FromStr for HexBinary32 {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(HexBinary32(
            u32::from_str_radix(&s[2..], 16).map_err(|_| "could not parse hexbinary32")?,
        ))
    }
}

/// A 48-bit field encoded as a hex string (12 hex characters max). Where
/// applicable, bit 0, or the least significant bit, goes on the right. Note that
/// hexBinary requires pairs of hex characters, so an odd number of characters
/// requires a leading "0".
#[derive(Default, Hash, PartialEq, Eq, Debug, Clone, Copy, DefaultYaSerde)]
pub struct HexBinary48(pub u64);

impl Validate for HexBinary48 {
    fn validate(&self) -> Result<(), String> {
        let a = &self.0;
        if a > &281474976710656 {
            Err(format!("Validation error: invalid value! \nExpected: 0 <= 281474976710656.\nActual: 0 == {}", a))
        } else {
            Ok(())
        }
    }
}

impl fmt::Display for HexBinary48 {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let a = &self.0;
        write!(f, "{:#014x?}", a)
    }
}

impl FromStr for HexBinary48 {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(HexBinary48(
            u64::from_str_radix(&s[2..], 16).map_err(|_| "could not parse hexbinary48")?,
        ))
    }
}

/// A 64-bit field encoded as a hex string (16 hex characters max). Where
/// applicable, bit 0, or the least significant bit, goes on the right. Note that
/// hexBinary requires pairs of hex characters, so an odd number of characters
/// requires a leading "0".
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Debug, Clone, Copy, DefaultYaSerde)]
pub struct HexBinary64(pub u64);

impl Validate for HexBinary64 {}

impl fmt::Display for HexBinary64 {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let a = &self.0;
        write!(f, "{:#018x?}", a)
    }
}

impl FromStr for HexBinary64 {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(HexBinary64(
            u64::from_str_radix(&s[2..], 16).map_err(|_| "could not parse hexbinary48")?,
        ))
    }
}

/// A 128-bit field encoded as a hex string (32 hex characters max). Where
/// applicable, bit 0, or the least significant bit, goes on the right. Note that
/// hexBinary requires pairs of hex characters, so an odd number of characters
/// requires a leading "0".
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Debug, Clone, Copy, DefaultYaSerde)]

pub struct HexBinary128(pub u128);

impl Validate for HexBinary128 {}

impl fmt::Display for HexBinary128 {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{:#034x?}", self.0)
    }
}

impl FromStr for HexBinary128 {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(HexBinary128(
            u128::from_str_radix(&s[2..], 16).map_err(|_| "could not parse hexbinary128")?,
        ))
    }
}

#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Debug, Clone, Copy, DefaultYaSerde)]
pub struct HexBinary160(pub [u8; 20]); // TODO: Can this use a Cow?

impl Validate for HexBinary160 {}

impl Index<usize> for HexBinary160 {
    type Output = u8;

    fn index(&self, index: usize) -> &Self::Output {
        &self.0[index]
    }
}

impl AsRef<[u8]> for HexBinary160 {
    fn as_ref(&self) -> &[u8] {
        &self.0
    }
}

impl fmt::Display for HexBinary160 {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let a = self
            .0
            .iter()
            .map(|byte| format!("{:02X}", byte))
            .collect::<Vec<String>>()
            .join("");
        write!(f, "{a}")
    }
}

impl FromStr for HexBinary160 {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        if s.len() % 2 != 0 {
            return Err("Hex string must be even".to_owned());
        }
        let mut out: [u8; 20] = [0; 20];
        let s = format!("{:0>40}", s);
        for i in (0..s.len()).step_by(2) {
            let hex_pair = &s[i..(i + 2)];
            if let Ok(byte) = u8::from_str_radix(hex_pair, 16) {
                out[i / 2] = byte;
            } else {
                return Err("Invalid Hex String".to_owned());
            }
        }

        Ok(HexBinary160(out))
    }
}

#[derive(Default, Hash, PartialEq, Eq, Debug, Clone, DefaultYaSerde)]
pub struct LFDI(pub HexBinary160);

impl Validate for LFDI {}

impl fmt::Display for LFDI {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let hexstring = format!("{}", self.0);
        write!(
            f,
            "{}",
            hexstring
                .chars()
                .enumerate()
                .flat_map(|(i, c)| {
                    if i > 0 && i % 4 == 0 { Some('-') } else { None }
                        .into_iter()
                        .chain(Some(c))
                })
                .collect::<String>()
        )
    }
}

impl FromStr for LFDI {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let s = s.replace('-', "");
        Ok(LFDI(HexBinary160::from_str(&s)?))
    }
}

/// Character string of max length 6. In order to limit internal storage,
/// implementations SHALL reduce the length of strings using multi-byte
/// characters so that the string may be stored using "maxLength" octets in the
/// given encoding.
#[derive(Default, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, Clone, PrimitiveYaSerde)]
pub struct String6(pub String);

impl Validate for String6 {
    fn validate(&self) -> Result<(), String> {
        if self.0.len() > 6 {
            return Err(format!(
                "MaxLength validation error. \nExpected: 0 length <= 6 \nActual: 0 length == {}",
                self.0.len()
            ));
        }
        Ok(())
    }
}

/// Character string of max length 16. In order to limit internal storage,
/// implementations SHALL reduce the length of strings using multi-byte
/// characters so that the string may be stored using "maxLength" octets in the
/// given encoding.
#[derive(Default, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, Clone, PrimitiveYaSerde)]
pub struct String16(pub String);

impl Validate for String16 {
    fn validate(&self) -> Result<(), String> {
        if self.0.len() > 16 {
            return Err(format!(
                "MaxLength validation error. \nExpected: 0 length <= 16 \nActual: 0 length == {}",
                self.0.len()
            ));
        }
        Ok(())
    }
}

/// Character string of max length 20. In order to limit internal storage,
/// implementations SHALL reduce the length of strings using multi-byte
/// characters so that the string may be stored using "maxLength" octets in the
/// given encoding.
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Debug, Clone, PrimitiveYaSerde)]
pub struct String20(pub String);

impl Validate for String20 {
    fn validate(&self) -> Result<(), String> {
        if self.0.len() > 20 {
            return Err(format!(
                "MaxLength validation error. \nExpected: 0 length <= 20 \nActual: 0 length == {}",
                self.0.len()
            ));
        }
        Ok(())
    }
}

/// Character string of max length 32. In order to limit internal storage,
/// implementations SHALL reduce the length of strings using multi-byte
/// characters so that the string may be stored using "maxLength" octets in the
/// given encoding.
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Debug, Clone, PrimitiveYaSerde)]
pub struct String32(pub String);

impl Validate for String32 {
    fn validate(&self) -> Result<(), String> {
        if self.0.len() > 32 {
            return Err(format!(
                "MaxLength validation error. \nExpected: 0 length <= 32 \nActual: 0 length == {}",
                self.0.len()
            ));
        }
        Ok(())
    }
}

/// Character string of max length 42. In order to limit internal storage,
/// implementations SHALL reduce the length of strings using multi-byte
/// characters so that the string may be stored using "maxLength" octets in the
/// given encoding.
#[derive(Default, Hash, PartialEq, PartialOrd, Eq, Ord, Debug, Clone, PrimitiveYaSerde)]
pub struct String42(pub String);

impl Validate for String42 {
    fn validate(&self) -> Result<(), String> {
        if self.0.len() > 42 {
            return Err(format!(
                "MaxLength validation error. \nExpected: 0 length <= 42 \nActual: 0 length == {}",
                self.0.len()
            ));
        }
        Ok(())
    }
}

/// Character string of max length 192. For all string types, in order to limit
/// internal storage, implementations SHALL reduce the length of strings using
/// multi-byte characters so that the string may be stored using "maxLength"
/// octets in the given encoding.
#[derive(Default, Hash, PartialEq, Eq, Debug, Clone, PrimitiveYaSerde)]
pub struct String192(pub String);

impl Validate for String192 {
    fn validate(&self) -> Result<(), String> {
        if self.0.len() > 192 {
            return Err(format!(
                "MaxLength validation error. \nExpected: 0 length <= 192 \nActual: 0 length == {}",
                self.0.len()
            ));
        }
        Ok(())
    }
}

#[test]
fn default_hexbinary8() {
    let orig = HexBinary8::default();
    let new: HexBinary8 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_hexbinary16() {
    let orig = HexBinary16::default();
    let new: HexBinary16 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_hexbinary32() {
    let orig = HexBinary32::default();
    let new: HexBinary32 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_hexbinary48() {
    let orig = HexBinary48::default();
    let new: HexBinary48 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_hexbinary64() {
    let orig = HexBinary64::default();
    let new: HexBinary64 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_hexbinary128() {
    let orig = HexBinary128::default();
    let new: HexBinary128 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_hexbinary160() {
    let orig = HexBinary160::default();
    let new: HexBinary160 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_lfdi() {
    let orig = LFDI::default();
    let new: LFDI = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn example_hexbinary160() {
    let orig: HexBinary160 = HexBinary160::from_str("C0FFEE00").unwrap();
    let new = orig.to_string();
    assert_eq!(orig, HexBinary160::from_str(&new).unwrap());
}

#[test]
fn example_lfdi() {
    let orig: LFDI = LFDI::from_str("C0FFEE00").unwrap();
    let new = orig.to_string();
    assert_eq!(orig, LFDI::from_str(&new).unwrap());
}

#[test]
fn default_uint8() {
    let orig = Uint8::default();
    let new: Uint8 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_uint16() {
    let orig = Uint16::default();
    let new: Uint16 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_uint32() {
    let orig = Uint32::default();
    let new: Uint32 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_uint40() {
    let orig = Uint40::default();
    let new: Uint40 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_uint48() {
    let orig = Uint48::default();
    let new: Uint48 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_uint64() {
    let orig = Uint64::default();
    let new: Uint64 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_int8() {
    let orig = Int8::default();
    let new: Int8 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_int16() {
    let orig = Int16::default();
    let new: Int16 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_int32() {
    let orig = Int32::default();
    let new: Int32 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_int48() {
    let orig = Int48::default();
    let new: Int48 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_int64() {
    let orig = Int64::default();
    let new: Int64 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_string6() {
    let orig = String6::default();
    let new: String6 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_string16() {
    let orig = String16::default();
    let new: String16 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_string20() {
    let orig = String20::default();
    let new: String20 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_string32() {
    let orig = String32::default();
    let new: String32 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_string42() {
    let orig = String42::default();
    let new: String42 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}

#[test]
fn default_string192() {
    let orig = String192::default();
    let new: String192 = deserialize(&serialize(&orig).unwrap()).unwrap();
    assert_eq!(orig, new);
}