1#![feature(fundamental)]
2
3use std::convert::TryInto;
73use std::io::{Read, Write};
74
75pub use ed_derive::*;
76
77#[derive(thiserror::Error, Debug)]
79pub enum Error {
80 #[error("Unexpected byte: {0}")]
81 UnexpectedByte(u8),
82 #[error("Unencodable variant")]
83 UnencodableVariant,
84 #[error(transparent)]
85 IOError(#[from] std::io::Error),
86}
87
88pub type Result<T> = std::result::Result<T, Error>;
90
91#[fundamental]
93pub trait Encode {
94 fn encode_into<W: Write>(&self, dest: &mut W) -> Result<()>;
103
104 fn encoding_length(&self) -> Result<usize>;
107
108 #[inline]
114 #[cfg_attr(test, mutate)]
115 fn encode(&self) -> Result<Vec<u8>> {
116 let length = self.encoding_length()?;
117 let mut bytes = Vec::with_capacity(length);
118 self.encode_into(&mut bytes)?;
119 Ok(bytes)
120 }
121}
122
123#[fundamental]
125pub trait Decode: Sized {
126 fn decode<R: Read>(input: R) -> Result<Self>;
132
133 #[inline]
146 #[cfg_attr(test, mutate)]
147 fn decode_into<R: Read>(&mut self, input: R) -> Result<()> {
148 let value = Self::decode(input)?;
149 *self = value;
150 Ok(())
151 }
152}
153
154pub trait Terminated {}
168
169macro_rules! int_impl {
170 ($type:ty, $length:expr) => {
171 impl Encode for $type {
172 #[doc = "Encodes the integer as fixed-size big-endian bytes."]
173 #[inline]
174 fn encode_into<W: Write>(&self, dest: &mut W) -> Result<()> {
175 let bytes = self.to_be_bytes();
176 dest.write_all(&bytes[..])?;
177 Ok(())
178 }
179
180 #[doc = "Returns the size of the integer in bytes. Will always"]
181 #[doc = " return an `Ok` result."]
182 #[inline]
183 fn encoding_length(&self) -> Result<usize> {
184 Ok($length)
185 }
186 }
187
188 impl Decode for $type {
189 #[doc = "Decodes the integer from fixed-size big-endian bytes."]
190 #[inline]
191 fn decode<R: Read>(mut input: R) -> Result<Self> {
192 let mut bytes = [0; $length];
193 input.read_exact(&mut bytes[..])?;
194 Ok(Self::from_be_bytes(bytes))
195 }
196 }
197
198 impl Terminated for $type {}
199 };
200}
201
202int_impl!(u8, 1);
203int_impl!(u16, 2);
204int_impl!(u32, 4);
205int_impl!(u64, 8);
206int_impl!(u128, 16);
207int_impl!(i8, 1);
208int_impl!(i16, 2);
209int_impl!(i32, 4);
210int_impl!(i64, 8);
211int_impl!(i128, 16);
212
213impl Encode for bool {
214 #[inline]
216 #[cfg_attr(test, mutate)]
217 fn encode_into<W: Write>(&self, dest: &mut W) -> Result<()> {
218 let bytes = [*self as u8];
219 dest.write_all(&bytes[..])?;
220 Ok(())
221 }
222
223 #[inline]
225 #[cfg_attr(test, mutate)]
226 fn encoding_length(&self) -> Result<usize> {
227 Ok(1)
228 }
229}
230
231impl Decode for bool {
232 #[inline]
235 #[cfg_attr(test, mutate)]
236 fn decode<R: Read>(mut input: R) -> Result<Self> {
237 let mut buf = [0; 1];
238 input.read_exact(&mut buf[..])?;
239 match buf[0] {
240 0 => Ok(false),
241 1 => Ok(true),
242 byte => Err(Error::UnexpectedByte(byte)),
243 }
244 }
245}
246
247impl Terminated for bool {}
248
249impl<T: Encode> Encode for Option<T> {
250 #[inline]
253 #[cfg_attr(test, mutate)]
254 fn encode_into<W: Write>(&self, dest: &mut W) -> Result<()> {
255 match self {
256 None => dest.write_all(&[0]).map_err(Error::IOError),
257 Some(value) => {
258 dest.write_all(&[1]).map_err(Error::IOError)?;
259 value.encode_into(dest)
260 }
261 }
262 }
263
264 #[inline]
267 #[cfg_attr(test, mutate)]
268 fn encoding_length(&self) -> Result<usize> {
269 match self {
270 None => Ok(1),
271 Some(value) => Ok(1 + value.encoding_length()?),
272 }
273 }
274}
275
276impl<T: Decode> Decode for Option<T> {
277 #[inline]
280 #[cfg_attr(test, mutate)]
281 fn decode<R: Read>(input: R) -> Result<Self> {
282 let mut option: Option<T> = None;
283 option.decode_into(input)?;
284 Ok(option)
285 }
286
287 #[inline]
294 #[cfg_attr(test, mutate)]
295 fn decode_into<R: Read>(&mut self, mut input: R) -> Result<()> {
296 let mut byte = [0; 1];
297 input.read_exact(&mut byte[..])?;
298
299 match byte[0] {
300 0 => *self = None,
301 1 => match self {
302 None => *self = Some(T::decode(input)?),
303 Some(value) => value.decode_into(input)?,
304 },
305 byte => {
306 return Err(Error::UnexpectedByte(byte));
307 }
308 };
309
310 Ok(())
311 }
312}
313
314impl<T: Terminated> Terminated for Option<T> {}
315
316impl Encode for () {
317 #[inline]
319 #[cfg_attr(test, mutate)]
320 fn encode_into<W: Write>(&self, _: &mut W) -> Result<()> {
321 Ok(())
322 }
323
324 #[inline]
326 #[cfg_attr(test, mutate)]
327 fn encoding_length(&self) -> Result<usize> {
328 Ok(0)
329 }
330}
331
332impl Decode for () {
333 #[inline]
335 #[cfg_attr(test, mutate)]
336 fn decode<R: Read>(_: R) -> Result<Self> {
337 Ok(())
338 }
339}
340
341impl Terminated for () {}
342
343macro_rules! tuple_impl {
344 ($( $type:ident ),*; $last_type:ident) => {
345 impl<$($type: Encode + Terminated,)* $last_type: Encode> Encode for ($($type,)* $last_type,) {
346 #[doc = "Encodes the fields of the tuple one after another, in"]
347 #[doc = " order."]
348 #[allow(non_snake_case, unused_mut)]
349 #[inline]
350 fn encode_into<W: Write>(&self, mut dest: &mut W) -> Result<()> {
351 let ($($type,)* $last_type,) = self;
352 $($type.encode_into(&mut dest)?;)*
353 $last_type.encode_into(dest)
354 }
355
356 #[doc = "Returns the sum of the encoding lengths of the fields of"]
357 #[doc = " the tuple."]
358 #[allow(non_snake_case)]
359 #[allow(clippy::needless_question_mark)]
360 #[inline]
361 fn encoding_length(&self) -> Result<usize> {
362 let ($($type,)* $last_type,) = self;
363 Ok(
364 $($type.encoding_length()? +)*
365 $last_type.encoding_length()?
366 )
367 }
368 }
369
370 impl<$($type: Decode + Terminated,)* $last_type: Decode> Decode for ($($type,)* $last_type,) {
371 #[doc = "Decodes the fields of the tuple one after another, in"]
372 #[doc = " order."]
373 #[allow(unused_mut)]
374 #[inline]
375 fn decode<R: Read>(mut input: R) -> Result<Self> {
376 Ok((
377 $($type::decode(&mut input)?,)*
378 $last_type::decode(input)?,
379 ))
380 }
381
382 #[doc = "Decodes the fields of the tuple one after another, in"]
383 #[doc = " order."]
384 #[doc = ""]
385 #[doc = "Recursively calls `decode_into` for each field."]
386 #[allow(non_snake_case, unused_mut)]
387 #[inline]
388 fn decode_into<R: Read>(&mut self, mut input: R) -> Result<()> {
389 let ($($type,)* $last_type,) = self;
390 $($type.decode_into(&mut input)?;)*
391 $last_type.decode_into(input)?;
392 Ok(())
393 }
394 }
395
396 impl<$($type: Terminated,)* $last_type: Terminated> Terminated for ($($type,)* $last_type,) {}
397 }
398}
399
400tuple_impl!(; A);
401tuple_impl!(A; B);
402tuple_impl!(A, B; C);
403tuple_impl!(A, B, C; D);
404tuple_impl!(A, B, C, D; E);
405tuple_impl!(A, B, C, D, E; F);
406tuple_impl!(A, B, C, D, E, F; G);
407tuple_impl!(A, B, C, D, E, F, G; H);
408tuple_impl!(A, B, C, D, E, F, G, H; I);
409tuple_impl!(A, B, C, D, E, F, G, H, I; J);
410tuple_impl!(A, B, C, D, E, F, G, H, I, J; K);
411tuple_impl!(A, B, C, D, E, F, G, H, I, J, K; L);
412
413impl<T: Encode + Terminated, const N: usize> Encode for [T; N] {
414 #[inline]
415 fn encode_into<W: Write>(&self, mut dest: &mut W) -> Result<()> {
416 for element in self[..].iter() {
417 element.encode_into(&mut dest)?;
418 }
419 Ok(())
420 }
421
422 #[inline]
423 fn encoding_length(&self) -> Result<usize> {
424 let mut sum = 0;
425 for element in self[..].iter() {
426 sum += element.encoding_length()?;
427 }
428 Ok(sum)
429 }
430}
431
432impl<T: Decode + Terminated, const N: usize> Decode for [T; N] {
433 #[allow(unused_variables, unused_mut)]
434 #[inline]
435 fn decode<R: Read>(mut input: R) -> Result<Self> {
436 let mut v: Vec<T> = Vec::with_capacity(N);
437 for i in 0..N {
438 v.push(T::decode(&mut input)?);
439 }
440 Ok(v.try_into()
441 .unwrap_or_else(|v: Vec<T>| panic!("Input Vec not of length {}", N)))
442 }
443
444 #[inline]
445 fn decode_into<R: Read>(&mut self, mut input: R) -> Result<()> {
446 for item in self.iter_mut().take(N) {
447 T::decode_into(item, &mut input)?;
448 }
449 Ok(())
450 }
451}
452
453impl<T: Terminated, const N: usize> Terminated for [T; N] {}
454
455impl<T: Encode + Terminated> Encode for Vec<T> {
456 #[doc = "Encodes the elements of the vector one after another, in order."]
457 #[inline]
458 fn encode_into<W: Write>(&self, dest: &mut W) -> Result<()> {
459 for element in self.iter() {
460 element.encode_into(dest)?;
461 }
462 Ok(())
463 }
464
465 #[doc = "Returns the sum of the encoding lengths of all elements."]
466 #[cfg_attr(test, mutate)]
467 #[inline]
468 fn encoding_length(&self) -> Result<usize> {
469 let mut sum = 0;
470 for element in self.iter() {
471 sum += element.encoding_length()?;
472 }
473 Ok(sum)
474 }
475}
476
477impl<T: Decode + Terminated> Decode for Vec<T> {
478 #[doc = "Decodes the elements of the vector one after another, in order."]
479 #[cfg_attr(test, mutate)]
480 #[inline]
481 fn decode<R: Read>(input: R) -> Result<Self> {
482 let mut vec = Vec::with_capacity(128);
483 vec.decode_into(input)?;
484 Ok(vec)
485 }
486
487 #[doc = "Encodes the elements of the vector one after another, in order."]
488 #[doc = ""]
489 #[doc = "Recursively calls `decode_into` for each element."]
490 #[cfg_attr(test, mutate)]
491 #[inline]
492 fn decode_into<R: Read>(&mut self, mut input: R) -> Result<()> {
493 let old_len = self.len();
494
495 let mut bytes = Vec::with_capacity(256);
496 input.read_to_end(&mut bytes)?;
497
498 let mut slice = bytes.as_slice();
499 let mut i = 0;
500 while !slice.is_empty() {
501 if i < old_len {
502 self[i].decode_into(&mut slice)?;
503 } else {
504 let el = T::decode(&mut slice)?;
505 self.push(el);
506 }
507
508 i += 1;
509 }
510
511 if i < old_len {
512 self.truncate(i);
513 }
514
515 Ok(())
516 }
517}
518
519impl<T: Encode + Terminated> Encode for [T] {
520 #[doc = "Encodes the elements of the slice one after another, in order."]
521 #[cfg_attr(test, mutate)]
522 #[inline]
523 fn encode_into<W: Write>(&self, mut dest: &mut W) -> Result<()> {
524 for element in self[..].iter() {
525 element.encode_into(&mut dest)?;
526 }
527 Ok(())
528 }
529
530 #[doc = "Returns the sum of the encoding lengths of all elements."]
531 #[cfg_attr(test, mutate)]
532 #[inline]
533 fn encoding_length(&self) -> Result<usize> {
534 let mut sum = 0;
535 for element in self[..].iter() {
536 sum += element.encoding_length()?;
537 }
538 Ok(sum)
539 }
540}
541
542impl<T: Encode> Encode for Box<T> {
543 #[doc = "Encodes the inner value."]
544 #[cfg_attr(test, mutate)]
545 #[inline]
546 fn encode_into<W: Write>(&self, dest: &mut W) -> Result<()> {
547 (**self).encode_into(dest)
548 }
549
550 #[doc = "Returns the encoding length of the inner value."]
551 #[cfg_attr(test, mutate)]
552 #[inline]
553 fn encoding_length(&self) -> Result<usize> {
554 (**self).encoding_length()
555 }
556}
557
558impl<T: Decode> Decode for Box<T> {
559 #[doc = "Decodes the inner value into a new Box."]
560 #[cfg_attr(test, mutate)]
561 #[inline]
562 fn decode<R: Read>(input: R) -> Result<Self> {
563 T::decode(input).map(|v| v.into())
564 }
565
566 #[doc = "Decodes the inner value into the existing Box."]
567 #[doc = ""]
568 #[doc = "Recursively calls `decode_into` on the inner value."]
569 #[cfg_attr(test, mutate)]
570 #[inline]
571 fn decode_into<R: Read>(&mut self, input: R) -> Result<()> {
572 (**self).decode_into(input)
573 }
574}
575
576impl<T> Encode for std::marker::PhantomData<T> {
577 #[inline]
579 #[cfg_attr(test, mutate)]
580 fn encode_into<W: Write>(&self, _: &mut W) -> Result<()> {
581 Ok(())
582 }
583
584 #[inline]
586 #[cfg_attr(test, mutate)]
587 fn encoding_length(&self) -> Result<usize> {
588 Ok(0)
589 }
590}
591
592impl<T> Decode for std::marker::PhantomData<T> {
593 #[inline]
595 #[cfg_attr(test, mutate)]
596 fn decode<R: Read>(_: R) -> Result<Self> {
597 Ok(Self {})
598 }
599}
600
601impl<T> Terminated for std::marker::PhantomData<T> {}
602
603#[cfg(test)]
604use mutagen::mutate;
605mod tests {
606 #[allow(unused_imports)]
607 use super::*;
608
609 #[test]
610 fn encode_decode_u8() {
611 let value = 0x12u8;
612 let bytes = value.encode().unwrap();
613 assert_eq!(bytes.as_slice(), &[0x12]);
614 let decoded_value = u8::decode(bytes.as_slice()).unwrap();
615 assert_eq!(decoded_value, value);
616 }
617
618 #[test]
619 fn encode_decode_u64() {
620 let value = 0x1234567890u64;
621 let bytes = value.encode().unwrap();
622 assert_eq!(bytes.as_slice(), &[0, 0, 0, 0x12, 0x34, 0x56, 0x78, 0x90]);
623 let decoded_value = u64::decode(bytes.as_slice()).unwrap();
624 assert_eq!(decoded_value, value);
625 }
626
627 #[test]
628 fn encode_decode_option() {
629 let value = Some(0x1234567890u64);
630 let bytes = value.encode().unwrap();
631 assert_eq!(
632 bytes.as_slice(),
633 &[1, 0, 0, 0, 0x12, 0x34, 0x56, 0x78, 0x90]
634 );
635 let decoded_value: Option<u64> = Decode::decode(bytes.as_slice()).unwrap();
636 assert_eq!(decoded_value, value);
637
638 let value: Option<u64> = None;
639 let bytes = value.encode().unwrap();
640 assert_eq!(bytes.as_slice(), &[0]);
641 let decoded_value: Option<u64> = Decode::decode(bytes.as_slice()).unwrap();
642 assert_eq!(decoded_value, None);
643 }
644
645 #[test]
646 fn encode_decode_tuple() {
647 let value: (u16, u16) = (1, 2);
648 let bytes = value.encode().unwrap();
649 assert_eq!(bytes.as_slice(), &[0, 1, 0, 2]);
650 let decoded_value: (u16, u16) = Decode::decode(bytes.as_slice()).unwrap();
651 assert_eq!(decoded_value, value);
652
653 let value = ();
654 let bytes = value.encode().unwrap();
655 assert_eq!(bytes.as_slice().len(), 0);
656 let decoded_value: () = Decode::decode(bytes.as_slice()).unwrap();
657 assert_eq!(decoded_value, value);
658 }
659
660 #[test]
661 fn encode_decode_array() {
662 let value: [u16; 4] = [1, 2, 3, 4];
663 let bytes = value.encode().unwrap();
664 assert_eq!(bytes.as_slice(), &[0, 1, 0, 2, 0, 3, 0, 4]);
665 let decoded_value: [u16; 4] = Decode::decode(bytes.as_slice()).unwrap();
666 assert_eq!(decoded_value, value);
667 }
668
669 #[test]
670 #[should_panic(expected = "failed to fill whole buffer")]
671 fn encode_decode_array_eof_length() {
672 let bytes = [0, 1, 0, 2, 0, 3];
673 let _: [u16; 4] = Decode::decode(&bytes[..]).unwrap();
674 }
675
676 #[test]
677 #[should_panic(expected = "failed to fill whole buffer")]
678 fn encode_decode_array_eof_element() {
679 let bytes = [0, 1, 0, 2, 0, 3, 0];
680 let _: [u16; 4] = Decode::decode(&bytes[..]).unwrap();
681 }
682
683 #[test]
684 fn encode_decode_vec() {
685 let value: Vec<u16> = vec![1, 2, 3, 4];
686 let bytes = value.encode().unwrap();
687 assert_eq!(bytes.as_slice(), &[0, 1, 0, 2, 0, 3, 0, 4]);
688 let decoded_value: Vec<u16> = Decode::decode(bytes.as_slice()).unwrap();
689 assert_eq!(decoded_value, value);
690 }
691
692 #[test]
693 #[should_panic(expected = "failed to fill whole buffer")]
694 fn encode_decode_vec_eof_element() {
695 let bytes = [0, 1, 0, 2, 0, 3, 0];
696 let _: Vec<u16> = Decode::decode(&bytes[..]).unwrap();
697 }
698
699 #[test]
700 fn test_encode_bool() {
701 let value: bool = true;
702 let bytes = value.encode().unwrap();
703 assert_eq!(bytes.as_slice(), &[1]);
704 }
705
706 #[test]
707 fn test_encoding_length_bool() {
708 let value: bool = true;
709 let enc_length = value.encoding_length().unwrap();
710 assert!(enc_length == 1);
711 }
712 #[test]
713 fn test_decode_bool_true() {
714 let bytes = vec![1];
715 let decoded_value: bool = Decode::decode(bytes.as_slice()).unwrap();
716 assert_eq!(decoded_value, true);
717 }
718
719 #[test]
720 fn test_decode_bool_false() {
721 let bytes = vec![0];
722 let decoded_value: bool = Decode::decode(bytes.as_slice()).unwrap();
723 assert_eq!(decoded_value, false);
724 }
725
726 #[test]
727 fn test_decode_bool_bail() {
728 let bytes = vec![42];
729 let result: Result<bool> = Decode::decode(bytes.as_slice());
730 assert_eq!(result.unwrap_err().to_string(), "Unexpected byte: 42");
731 }
732
733 #[test]
734 fn test_encode_decode_phantom_data() {
735 use std::marker::PhantomData;
736 let pd: PhantomData<u8> = PhantomData;
737 let bytes = pd.encode().unwrap();
738 assert_eq!(bytes.len(), 0);
739 let decoded_value: PhantomData<u8> = Decode::decode(bytes.as_slice()).unwrap();
740 assert_eq!(decoded_value, PhantomData);
741 }
742
743 #[test]
744 fn test_default_decode() {
745 struct Foo {
746 bar: u8,
747 }
748
749 impl Decode for Foo {
750 fn decode<R: Read>(_input: R) -> Result<Self> {
751 Ok(Foo { bar: 42 })
752 }
753 }
754
755 let bytes = vec![42, 12, 68];
756 let mut foo: Foo = Foo { bar: 41 };
757 foo.decode_into(bytes.as_slice()).unwrap();
758 assert_eq!(foo.bar, 42);
759 }
760
761 #[test]
762 fn test_option_encode_into() {
763 let option = Some(0x12u8);
764 let mut vec: Vec<u8> = vec![];
765 option.encode_into(&mut vec).unwrap();
766 assert_eq!(vec, vec![1, 18]);
767 }
768
769 #[test]
770 fn test_option_encoding_length() {
771 let val = 0x12u8;
772 let option = Some(val);
773 let option_length = option.encoding_length().unwrap();
774 let val_length = val.encoding_length().unwrap();
775 assert!(option_length == val_length + 1);
776 }
777 #[test]
778 fn test_option_none_encode_into() {
779 let option: Option<u8> = None;
780 let mut vec: Vec<u8> = vec![];
781 option.encode_into(&mut vec).unwrap();
782 assert_eq!(vec, vec![0]);
783 }
784
785 #[test]
786 fn test_option_none_encoding_length() {
787 let option: Option<u8> = None;
788 let length = option.encoding_length().unwrap();
789 assert!(length == 1);
790 }
791
792 #[test]
793 fn test_bail_option_decode_into() {
794 let mut option: Option<u8> = Some(42);
795 let bytes = vec![42];
796 let err = option.decode_into(bytes.as_slice()).unwrap_err();
797 assert_eq!(err.to_string(), "Unexpected byte: 42");
798 }
799
800 #[test]
801 fn test_some_option_decode_into() {
802 let mut option: Option<u8> = Some(0);
803 let bytes = vec![1, 0x12u8];
804 option.decode_into(bytes.as_slice()).unwrap();
805 assert_eq!(option.unwrap(), 18);
806 }
807
808 #[test]
809 fn test_vec_decode_into() {
810 let mut vec: Vec<u8> = vec![42, 42, 42];
811 let bytes = vec![12, 13];
812 vec.decode_into(bytes.as_slice()).unwrap();
813 assert_eq!(vec, vec![12, 13]);
814 }
815
816 #[test]
817 fn test_vec_encoding_length() {
818 let forty_two: u8 = 42;
819 let vec: Vec<u8> = vec![42, 42, 42];
820 let vec_length = vec.encoding_length().unwrap();
821 let indv_num_length = forty_two.encoding_length().unwrap();
822 assert!(vec_length == indv_num_length * 3);
823 }
824
825 #[test]
826 fn test_box_encoding_length() {
827 let forty_two = Box::new(42);
828 let length = forty_two.encoding_length().unwrap();
829 assert_eq!(length, 4);
830 }
831
832 #[test]
833 fn test_box_encode_into() {
834 let test = Box::new(42);
835 let mut vec = vec![12];
836 test.encode_into(&mut vec).unwrap();
837 assert_eq!(*test, 42);
838 }
839
840 #[test]
841 fn test_box_decode() {
842 let bytes = vec![1];
843 let test = Box::new(bytes.as_slice());
844 let decoded_value: Box<bool> = Decode::decode(test).unwrap();
845 assert_eq!(*decoded_value, true);
846 }
847
848 #[test]
849 fn test_box_decode_into() {
850 let mut test = Box::new(false);
851 let bytes = vec![1];
852 test.decode_into(bytes.as_slice()).unwrap();
853 assert_eq!(*test, true);
854 }
855
856 #[test]
857 fn test_slice_encode_into() {
858 let vec = vec![1, 2, 1];
859 let slice = &vec[0..3];
860 let mut vec: Vec<u8> = vec![];
861 slice.encode_into(&mut vec).unwrap();
862 assert_eq!(vec, vec![0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 1]);
863 }
864
865 #[test]
866 fn test_slice_encoding_length() {
867 let vec = vec![1, 2, 1];
868 let slice = &vec[0..3];
869 let size = slice.encoding_length().unwrap();
870 assert_eq!(size, 12);
871 }
872
873 #[test]
874 fn test_unit_encoding_length() {
875 let unit = ();
876 let length = unit.encoding_length().unwrap();
877 assert!(length == 0);
878 }
879
880 #[test]
881 fn test_phantom_data_encoding_length() {
882 use std::marker::PhantomData;
883 let pd: PhantomData<u8> = PhantomData;
884 let length = pd.encoding_length().unwrap();
885 assert_eq!(length, 0);
886 }
887}