1use core::num::NonZeroI64;
298use std::string::ToString;
302
303use ::buffa::{
304 DecodeContext, DecodeError, DefaultInstance, EncodeSink, Message, SizeCache,
305 bytes::Buf,
306 encoding::{Tag, WireType, encode_varint, skip_field_depth, varint_len},
307 types::{
308 FIXED32_ENCODED_LEN, bytes_encoded_len, decode_bytes, decode_double, decode_float,
309 decode_int64, decode_string, decode_uint32, decode_uint64, encode_bytes, encode_double,
310 encode_float, encode_int64, encode_string, encode_uint32, encode_uint64, int64_encoded_len,
311 string_encoded_len, uint32_encoded_len, uint64_encoded_len,
312 },
313};
314use smol_bytes::Utf8Bytes;
315
316use crate::{
317 audio::{
318 BitRateMode, ChannelLayout, ChannelLayoutDescription, ChannelOrder, ChannelSpec,
319 ContainerFormat, CoverArt, Fingerprint, Loudness, ReplayGain, SampleFormat, Tags,
320 },
321 capture::{Device, GeoLocation},
322 color::{
323 ChromaCoord, ChromaLocation, ContentLightLevel, DcpTargetGamut, DolbyVisionConfig,
324 DynamicRange, HdrStaticMetadata, Info, MasteringDisplay, Matrix, Primaries, Transfer,
325 },
326 container::Format,
327 disposition::TrackDisposition,
328 frame::{
329 DEN_ONE, Dimensions, FieldOrder, FrameRate, Rational, Rect, Rotation, SampleAspectRatio,
330 StereoMode,
331 },
332 lang::LanguageId,
333 pixel_format::PixelFormat,
334};
335
336const VARINT: u8 = WireType::Varint as u8;
337const LEN: u8 = WireType::LengthDelimited as u8;
338
339impl DefaultInstance for Dimensions {
351 fn default_instance() -> &'static Self {
352 static VALUE: buffa::__private::OnceBox<Dimensions> = buffa::__private::OnceBox::new();
353 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Dimensions::default()))
354 }
355}
356
357impl Message for Dimensions {
358 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
359 let mut size = 0u32;
360 if self.width() != 0 {
362 size += 1 + uint32_encoded_len(self.width()) as u32;
363 }
364 if self.height() != 0 {
365 size += 1 + uint32_encoded_len(self.height()) as u32;
366 }
367 size
368 }
369
370 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
371 if self.width() != 0 {
373 Tag::new(1, WireType::Varint).encode(buf);
374 encode_uint32(self.width(), buf);
375 }
376 if self.height() != 0 {
377 Tag::new(2, WireType::Varint).encode(buf);
378 encode_uint32(self.height(), buf);
379 }
380 }
381
382 fn merge_field(
383 &mut self,
384 tag: Tag,
385 buf: &mut impl Buf,
386 ctx: DecodeContext<'_>,
387 ) -> Result<(), DecodeError> {
388 match tag.field_number() {
389 1 => {
390 if tag.wire_type() != WireType::Varint {
391 return Err(DecodeError::WireTypeMismatch {
392 field_number: 1,
393 expected: VARINT,
394 actual: tag.wire_type() as u8,
395 });
396 }
397 let w = decode_uint32(buf)?;
398 self.set_width(w);
399 }
400 2 => {
401 if tag.wire_type() != WireType::Varint {
402 return Err(DecodeError::WireTypeMismatch {
403 field_number: 2,
404 expected: VARINT,
405 actual: tag.wire_type() as u8,
406 });
407 }
408 let h = decode_uint32(buf)?;
409 self.set_height(h);
410 }
411 _ => skip_field_depth(tag, buf, ctx.depth())?,
412 }
413 Ok(())
414 }
415
416 fn clear(&mut self) {
417 *self = Dimensions::default();
418 }
419}
420
421impl DefaultInstance for Rect {
427 fn default_instance() -> &'static Self {
428 static VALUE: buffa::__private::OnceBox<Rect> = buffa::__private::OnceBox::new();
429 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Rect::default()))
430 }
431}
432
433impl Message for Rect {
434 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
435 let mut size = 0u32;
436 if self.x() != 0 {
438 size += 1 + uint32_encoded_len(self.x()) as u32;
439 }
440 if self.y() != 0 {
441 size += 1 + uint32_encoded_len(self.y()) as u32;
442 }
443 if self.width() != 0 {
444 size += 1 + uint32_encoded_len(self.width()) as u32;
445 }
446 if self.height() != 0 {
447 size += 1 + uint32_encoded_len(self.height()) as u32;
448 }
449 size
450 }
451
452 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
453 if self.x() != 0 {
455 Tag::new(1, WireType::Varint).encode(buf);
456 encode_uint32(self.x(), buf);
457 }
458 if self.y() != 0 {
459 Tag::new(2, WireType::Varint).encode(buf);
460 encode_uint32(self.y(), buf);
461 }
462 if self.width() != 0 {
463 Tag::new(3, WireType::Varint).encode(buf);
464 encode_uint32(self.width(), buf);
465 }
466 if self.height() != 0 {
467 Tag::new(4, WireType::Varint).encode(buf);
468 encode_uint32(self.height(), buf);
469 }
470 }
471
472 fn merge_field(
473 &mut self,
474 tag: Tag,
475 buf: &mut impl Buf,
476 ctx: DecodeContext<'_>,
477 ) -> Result<(), DecodeError> {
478 match tag.field_number() {
479 1 => {
480 if tag.wire_type() != WireType::Varint {
481 return Err(DecodeError::WireTypeMismatch {
482 field_number: 1,
483 expected: VARINT,
484 actual: tag.wire_type() as u8,
485 });
486 }
487 let v = decode_uint32(buf)?;
488 self.set_x(v);
489 }
490 2 => {
491 if tag.wire_type() != WireType::Varint {
492 return Err(DecodeError::WireTypeMismatch {
493 field_number: 2,
494 expected: VARINT,
495 actual: tag.wire_type() as u8,
496 });
497 }
498 let v = decode_uint32(buf)?;
499 self.set_y(v);
500 }
501 3 => {
502 if tag.wire_type() != WireType::Varint {
503 return Err(DecodeError::WireTypeMismatch {
504 field_number: 3,
505 expected: VARINT,
506 actual: tag.wire_type() as u8,
507 });
508 }
509 let v = decode_uint32(buf)?;
510 self.set_width(v);
511 }
512 4 => {
513 if tag.wire_type() != WireType::Varint {
514 return Err(DecodeError::WireTypeMismatch {
515 field_number: 4,
516 expected: VARINT,
517 actual: tag.wire_type() as u8,
518 });
519 }
520 let v = decode_uint32(buf)?;
521 self.set_height(v);
522 }
523 _ => skip_field_depth(tag, buf, ctx.depth())?,
524 }
525 Ok(())
526 }
527
528 fn clear(&mut self) {
529 *self = Rect::default();
530 }
531}
532
533impl DefaultInstance for SampleAspectRatio {
554 fn default_instance() -> &'static Self {
555 static VALUE: buffa::__private::OnceBox<SampleAspectRatio> = buffa::__private::OnceBox::new();
556 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(SampleAspectRatio::default()))
557 }
558}
559
560impl Message for SampleAspectRatio {
561 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
562 2 + int64_encoded_len(self.num()) as u32 + int64_encoded_len(self.den().get()) as u32
563 }
564
565 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
566 Tag::new(1, WireType::Varint).encode(buf);
567 encode_int64(self.num(), buf);
568 Tag::new(2, WireType::Varint).encode(buf);
569 encode_int64(self.den().get(), buf);
570 }
571
572 fn merge_field(
573 &mut self,
574 tag: Tag,
575 buf: &mut impl Buf,
576 ctx: DecodeContext<'_>,
577 ) -> Result<(), DecodeError> {
578 match tag.field_number() {
579 1 => {
580 if tag.wire_type() != WireType::Varint {
581 return Err(DecodeError::WireTypeMismatch {
582 field_number: 1,
583 expected: VARINT,
584 actual: tag.wire_type() as u8,
585 });
586 }
587 let num = decode_int64(buf)?.max(0);
594 self.set_num(num);
595 }
596 2 => {
597 if tag.wire_type() != WireType::Varint {
598 return Err(DecodeError::WireTypeMismatch {
599 field_number: 2,
600 expected: VARINT,
601 actual: tag.wire_type() as u8,
602 });
603 }
604 let den = NonZeroI64::new(decode_int64(buf)?)
615 .filter(|d| d.get() > 0)
616 .unwrap_or(DEN_ONE);
617 self.set_den(den);
618 }
619 _ => skip_field_depth(tag, buf, ctx.depth())?,
620 }
621 Ok(())
622 }
623
624 fn clear(&mut self) {
625 *self = SampleAspectRatio::default();
626 }
627}
628
629impl DefaultInstance for Rational {
643 fn default_instance() -> &'static Self {
644 static VALUE: buffa::__private::OnceBox<Rational> = buffa::__private::OnceBox::new();
645 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Rational::default()))
646 }
647}
648
649impl Message for Rational {
650 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
651 2 + int64_encoded_len(self.num()) as u32 + int64_encoded_len(self.den().get()) as u32
652 }
653
654 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
655 Tag::new(1, WireType::Varint).encode(buf);
656 encode_int64(self.num(), buf);
657 Tag::new(2, WireType::Varint).encode(buf);
658 encode_int64(self.den().get(), buf);
659 }
660
661 fn merge_field(
662 &mut self,
663 tag: Tag,
664 buf: &mut impl Buf,
665 ctx: DecodeContext<'_>,
666 ) -> Result<(), DecodeError> {
667 match tag.field_number() {
668 1 => {
669 if tag.wire_type() != WireType::Varint {
670 return Err(DecodeError::WireTypeMismatch {
671 field_number: 1,
672 expected: VARINT,
673 actual: tag.wire_type() as u8,
674 });
675 }
676 let num = decode_int64(buf)?.max(0);
679 self.set_num(num);
680 }
681 2 => {
682 if tag.wire_type() != WireType::Varint {
683 return Err(DecodeError::WireTypeMismatch {
684 field_number: 2,
685 expected: VARINT,
686 actual: tag.wire_type() as u8,
687 });
688 }
689 let den = NonZeroI64::new(decode_int64(buf)?)
694 .filter(|d| d.get() > 0)
695 .unwrap_or(DEN_ONE);
696 self.set_den(den);
697 }
698 _ => skip_field_depth(tag, buf, ctx.depth())?,
699 }
700 Ok(())
701 }
702
703 fn clear(&mut self) {
704 *self = Rational::default();
705 }
706}
707
708impl DefaultInstance for FrameRate {
721 fn default_instance() -> &'static Self {
722 static VALUE: buffa::__private::OnceBox<FrameRate> = buffa::__private::OnceBox::new();
723 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(FrameRate::default()))
724 }
725}
726
727impl Message for FrameRate {
728 fn compute_size(&self, cache: &mut SizeCache) -> u32 {
729 let mut size = 0u32;
730 {
732 let slot = cache.reserve();
733 let inner = self.rate().compute_size(cache);
734 cache.set(slot, inner);
735 size += 1 + varint_len(inner as u64) as u32 + inner;
736 }
737 if self.is_vfr() {
739 size += 1 + 1; }
741 size
742 }
743
744 fn write_to(&self, cache: &mut SizeCache, buf: &mut impl EncodeSink) {
745 Tag::new(1, WireType::LengthDelimited).encode(buf);
746 encode_varint(cache.consume_next() as u64, buf);
747 self.rate().write_to(cache, buf);
748 if self.is_vfr() {
750 Tag::new(2, WireType::Varint).encode(buf);
751 encode_varint(1, buf);
752 }
753 }
754
755 fn merge_field(
756 &mut self,
757 tag: Tag,
758 buf: &mut impl Buf,
759 ctx: DecodeContext<'_>,
760 ) -> Result<(), DecodeError> {
761 match tag.field_number() {
762 1 => {
763 if tag.wire_type() != WireType::LengthDelimited {
764 return Err(DecodeError::WireTypeMismatch {
765 field_number: 1,
766 expected: LEN,
767 actual: tag.wire_type() as u8,
768 });
769 }
770 let mut rate = self.rate();
771 buffa::Message::merge_length_delimited(&mut rate, buf, ctx)?;
772 self.set_rate(rate);
773 }
774 2 => {
775 if tag.wire_type() != WireType::Varint {
776 return Err(DecodeError::WireTypeMismatch {
777 field_number: 2,
778 expected: VARINT,
779 actual: tag.wire_type() as u8,
780 });
781 }
782 self.update_is_vfr(decode_uint32(buf)? != 0);
783 }
784 _ => skip_field_depth(tag, buf, ctx.depth())?,
785 }
786 Ok(())
787 }
788
789 fn clear(&mut self) {
790 *self = FrameRate::default();
791 }
792}
793
794impl DefaultInstance for DolbyVisionConfig {
805 fn default_instance() -> &'static Self {
806 static VALUE: buffa::__private::OnceBox<DolbyVisionConfig> = buffa::__private::OnceBox::new();
807 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(DolbyVisionConfig::default()))
808 }
809}
810
811impl Message for DolbyVisionConfig {
812 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
813 let mut size = 0u32;
814 if self.profile() != 0 {
816 size += 1 + uint32_encoded_len(self.profile() as u32) as u32;
817 }
818 if self.level() != 0 {
819 size += 1 + uint32_encoded_len(self.level() as u32) as u32;
820 }
821 if self.rpu_present() {
822 size += 1 + 1;
823 }
824 if self.el_present() {
825 size += 1 + 1;
826 }
827 if self.bl_signal_compat_id() != 0 {
828 size += 1 + uint32_encoded_len(self.bl_signal_compat_id() as u32) as u32;
829 }
830 size
831 }
832
833 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
834 if self.profile() != 0 {
836 Tag::new(1, WireType::Varint).encode(buf);
837 encode_uint32(self.profile() as u32, buf);
838 }
839 if self.level() != 0 {
840 Tag::new(2, WireType::Varint).encode(buf);
841 encode_uint32(self.level() as u32, buf);
842 }
843 if self.rpu_present() {
844 Tag::new(3, WireType::Varint).encode(buf);
845 encode_varint(1, buf);
846 }
847 if self.el_present() {
848 Tag::new(4, WireType::Varint).encode(buf);
849 encode_varint(1, buf);
850 }
851 if self.bl_signal_compat_id() != 0 {
852 Tag::new(5, WireType::Varint).encode(buf);
853 encode_uint32(self.bl_signal_compat_id() as u32, buf);
854 }
855 }
856
857 fn merge_field(
858 &mut self,
859 tag: Tag,
860 buf: &mut impl Buf,
861 ctx: DecodeContext<'_>,
862 ) -> Result<(), DecodeError> {
863 match tag.field_number() {
864 1 => {
865 if tag.wire_type() != WireType::Varint {
866 return Err(DecodeError::WireTypeMismatch {
867 field_number: 1,
868 expected: VARINT,
869 actual: tag.wire_type() as u8,
870 });
871 }
872 self.set_profile(decode_uint32(buf)? as u8);
873 }
874 2 => {
875 if tag.wire_type() != WireType::Varint {
876 return Err(DecodeError::WireTypeMismatch {
877 field_number: 2,
878 expected: VARINT,
879 actual: tag.wire_type() as u8,
880 });
881 }
882 self.set_level(decode_uint32(buf)? as u8);
883 }
884 3 => {
885 if tag.wire_type() != WireType::Varint {
886 return Err(DecodeError::WireTypeMismatch {
887 field_number: 3,
888 expected: VARINT,
889 actual: tag.wire_type() as u8,
890 });
891 }
892 self.update_rpu_present(decode_uint32(buf)? != 0);
893 }
894 4 => {
895 if tag.wire_type() != WireType::Varint {
896 return Err(DecodeError::WireTypeMismatch {
897 field_number: 4,
898 expected: VARINT,
899 actual: tag.wire_type() as u8,
900 });
901 }
902 self.update_el_present(decode_uint32(buf)? != 0);
903 }
904 5 => {
905 if tag.wire_type() != WireType::Varint {
906 return Err(DecodeError::WireTypeMismatch {
907 field_number: 5,
908 expected: VARINT,
909 actual: tag.wire_type() as u8,
910 });
911 }
912 self.set_bl_signal_compat_id(decode_uint32(buf)? as u8);
913 }
914 _ => skip_field_depth(tag, buf, ctx.depth())?,
915 }
916 Ok(())
917 }
918
919 fn clear(&mut self) {
920 *self = DolbyVisionConfig::default();
921 }
922}
923
924impl DefaultInstance for Info {
934 fn default_instance() -> &'static Self {
935 static VALUE: buffa::__private::OnceBox<Info> = buffa::__private::OnceBox::new();
936 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Info::UNSPECIFIED))
937 }
938}
939
940impl Message for Info {
941 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
942 5 + string_encoded_len(self.primaries().as_str()) as u32
944 + string_encoded_len(self.transfer().as_str()) as u32
945 + string_encoded_len(self.matrix().as_str()) as u32
946 + string_encoded_len(self.range().as_str()) as u32
947 + string_encoded_len(self.chroma_location().as_str()) as u32
948 }
949
950 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
951 Tag::new(1, WireType::LengthDelimited).encode(buf);
952 encode_string(self.primaries().as_str(), buf);
953 Tag::new(2, WireType::LengthDelimited).encode(buf);
954 encode_string(self.transfer().as_str(), buf);
955 Tag::new(3, WireType::LengthDelimited).encode(buf);
956 encode_string(self.matrix().as_str(), buf);
957 Tag::new(4, WireType::LengthDelimited).encode(buf);
958 encode_string(self.range().as_str(), buf);
959 Tag::new(5, WireType::LengthDelimited).encode(buf);
960 encode_string(self.chroma_location().as_str(), buf);
961 }
962
963 fn merge_field(
964 &mut self,
965 tag: Tag,
966 buf: &mut impl Buf,
967 ctx: DecodeContext<'_>,
968 ) -> Result<(), DecodeError> {
969 match tag.field_number() {
970 1 => {
971 if tag.wire_type() != WireType::LengthDelimited {
972 return Err(DecodeError::WireTypeMismatch {
973 field_number: 1,
974 expected: LEN,
975 actual: tag.wire_type() as u8,
976 });
977 }
978 let s = decode_string(buf)?;
979 self.set_primaries(s.parse().unwrap_or_else(|_| unreachable!()));
980 }
981 2 => {
982 if tag.wire_type() != WireType::LengthDelimited {
983 return Err(DecodeError::WireTypeMismatch {
984 field_number: 2,
985 expected: LEN,
986 actual: tag.wire_type() as u8,
987 });
988 }
989 let s = decode_string(buf)?;
990 self.set_transfer(s.parse().unwrap_or_else(|_| unreachable!()));
991 }
992 3 => {
993 if tag.wire_type() != WireType::LengthDelimited {
994 return Err(DecodeError::WireTypeMismatch {
995 field_number: 3,
996 expected: LEN,
997 actual: tag.wire_type() as u8,
998 });
999 }
1000 let s = decode_string(buf)?;
1001 self.set_matrix(s.parse().unwrap_or_else(|_| unreachable!()));
1002 }
1003 4 => {
1004 if tag.wire_type() != WireType::LengthDelimited {
1005 return Err(DecodeError::WireTypeMismatch {
1006 field_number: 4,
1007 expected: LEN,
1008 actual: tag.wire_type() as u8,
1009 });
1010 }
1011 let s = decode_string(buf)?;
1012 self.set_range(s.parse().unwrap_or_else(|_| unreachable!()));
1013 }
1014 5 => {
1015 if tag.wire_type() != WireType::LengthDelimited {
1016 return Err(DecodeError::WireTypeMismatch {
1017 field_number: 5,
1018 expected: LEN,
1019 actual: tag.wire_type() as u8,
1020 });
1021 }
1022 let s = decode_string(buf)?;
1023 self.set_chroma_location(s.parse().unwrap_or_else(|_| unreachable!()));
1024 }
1025 _ => skip_field_depth(tag, buf, ctx.depth())?,
1026 }
1027 Ok(())
1028 }
1029
1030 fn clear(&mut self) {
1031 *self = Info::UNSPECIFIED;
1032 }
1033}
1034
1035impl DefaultInstance for ContentLightLevel {
1041 fn default_instance() -> &'static Self {
1042 static VALUE: buffa::__private::OnceBox<ContentLightLevel> = buffa::__private::OnceBox::new();
1043 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(ContentLightLevel::default()))
1044 }
1045}
1046
1047impl Message for ContentLightLevel {
1048 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
1049 let mut size = 0u32;
1050 if self.max_cll() != 0 {
1052 size += 1 + uint32_encoded_len(self.max_cll()) as u32;
1053 }
1054 if self.max_fall() != 0 {
1055 size += 1 + uint32_encoded_len(self.max_fall()) as u32;
1056 }
1057 size
1058 }
1059
1060 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
1061 if self.max_cll() != 0 {
1063 Tag::new(1, WireType::Varint).encode(buf);
1064 encode_uint32(self.max_cll(), buf);
1065 }
1066 if self.max_fall() != 0 {
1067 Tag::new(2, WireType::Varint).encode(buf);
1068 encode_uint32(self.max_fall(), buf);
1069 }
1070 }
1071
1072 fn merge_field(
1073 &mut self,
1074 tag: Tag,
1075 buf: &mut impl Buf,
1076 ctx: DecodeContext<'_>,
1077 ) -> Result<(), DecodeError> {
1078 match tag.field_number() {
1079 1 => {
1080 if tag.wire_type() != WireType::Varint {
1081 return Err(DecodeError::WireTypeMismatch {
1082 field_number: 1,
1083 expected: VARINT,
1084 actual: tag.wire_type() as u8,
1085 });
1086 }
1087 let v = decode_uint32(buf)?;
1088 self.set_max_cll(v);
1089 }
1090 2 => {
1091 if tag.wire_type() != WireType::Varint {
1092 return Err(DecodeError::WireTypeMismatch {
1093 field_number: 2,
1094 expected: VARINT,
1095 actual: tag.wire_type() as u8,
1096 });
1097 }
1098 let v = decode_uint32(buf)?;
1099 self.set_max_fall(v);
1100 }
1101 _ => skip_field_depth(tag, buf, ctx.depth())?,
1102 }
1103 Ok(())
1104 }
1105
1106 fn clear(&mut self) {
1107 *self = ContentLightLevel::default();
1108 }
1109}
1110
1111impl DefaultInstance for ChromaCoord {
1120 fn default_instance() -> &'static Self {
1121 static VALUE: buffa::__private::OnceBox<ChromaCoord> = buffa::__private::OnceBox::new();
1122 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(ChromaCoord::default()))
1123 }
1124}
1125
1126impl Message for ChromaCoord {
1127 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
1128 let mut size = 0u32;
1129 if self.x() != 0 {
1131 size += 1 + uint32_encoded_len(self.x()) as u32;
1132 }
1133 if self.y() != 0 {
1134 size += 1 + uint32_encoded_len(self.y()) as u32;
1135 }
1136 size
1137 }
1138
1139 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
1140 if self.x() != 0 {
1142 Tag::new(1, WireType::Varint).encode(buf);
1143 encode_uint32(self.x(), buf);
1144 }
1145 if self.y() != 0 {
1146 Tag::new(2, WireType::Varint).encode(buf);
1147 encode_uint32(self.y(), buf);
1148 }
1149 }
1150
1151 fn merge_field(
1152 &mut self,
1153 tag: Tag,
1154 buf: &mut impl Buf,
1155 ctx: DecodeContext<'_>,
1156 ) -> Result<(), DecodeError> {
1157 match tag.field_number() {
1158 1 => {
1159 if tag.wire_type() != WireType::Varint {
1160 return Err(DecodeError::WireTypeMismatch {
1161 field_number: 1,
1162 expected: VARINT,
1163 actual: tag.wire_type() as u8,
1164 });
1165 }
1166 self.set_x(decode_uint32(buf)?);
1169 }
1170 2 => {
1171 if tag.wire_type() != WireType::Varint {
1172 return Err(DecodeError::WireTypeMismatch {
1173 field_number: 2,
1174 expected: VARINT,
1175 actual: tag.wire_type() as u8,
1176 });
1177 }
1178 self.set_y(decode_uint32(buf)?);
1179 }
1180 _ => skip_field_depth(tag, buf, ctx.depth())?,
1181 }
1182 Ok(())
1183 }
1184
1185 fn clear(&mut self) {
1186 *self = ChromaCoord::default();
1187 }
1188}
1189
1190impl DefaultInstance for MasteringDisplay {
1203 fn default_instance() -> &'static Self {
1204 static VALUE: buffa::__private::OnceBox<MasteringDisplay> = buffa::__private::OnceBox::new();
1205 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(MasteringDisplay::default()))
1206 }
1207}
1208
1209impl Message for MasteringDisplay {
1210 fn compute_size(&self, cache: &mut SizeCache) -> u32 {
1211 let mut size = 0u32;
1212 let primaries = self.display_primaries();
1213 for cc in &primaries {
1215 let slot = cache.reserve();
1216 let inner = cc.compute_size(cache);
1217 cache.set(slot, inner);
1218 size += 1 + varint_len(inner as u64) as u32 + inner;
1219 }
1220 {
1222 let slot = cache.reserve();
1223 let inner = self.white_point().compute_size(cache);
1224 cache.set(slot, inner);
1225 size += 1 + varint_len(inner as u64) as u32 + inner;
1226 }
1227 if self.max_luminance() != 0 {
1230 size += 1 + uint32_encoded_len(self.max_luminance()) as u32;
1231 }
1232 if self.min_luminance() != 0 {
1233 size += 1 + uint32_encoded_len(self.min_luminance()) as u32;
1234 }
1235 size
1236 }
1237
1238 fn write_to(&self, cache: &mut SizeCache, buf: &mut impl EncodeSink) {
1239 let primaries = self.display_primaries();
1240 for (i, cc) in primaries.iter().enumerate() {
1241 Tag::new(1 + i as u32, WireType::LengthDelimited).encode(buf);
1242 encode_varint(cache.consume_next() as u64, buf);
1243 cc.write_to(cache, buf);
1244 }
1245 Tag::new(4, WireType::LengthDelimited).encode(buf);
1246 encode_varint(cache.consume_next() as u64, buf);
1247 self.white_point().write_to(cache, buf);
1248 if self.max_luminance() != 0 {
1250 Tag::new(5, WireType::Varint).encode(buf);
1251 encode_uint32(self.max_luminance(), buf);
1252 }
1253 if self.min_luminance() != 0 {
1254 Tag::new(6, WireType::Varint).encode(buf);
1255 encode_uint32(self.min_luminance(), buf);
1256 }
1257 }
1258
1259 fn merge_field(
1260 &mut self,
1261 tag: Tag,
1262 buf: &mut impl Buf,
1263 ctx: DecodeContext<'_>,
1264 ) -> Result<(), DecodeError> {
1265 match tag.field_number() {
1266 n @ 1..=3 => {
1267 if tag.wire_type() != WireType::LengthDelimited {
1268 return Err(DecodeError::WireTypeMismatch {
1269 field_number: n,
1270 expected: LEN,
1271 actual: tag.wire_type() as u8,
1272 });
1273 }
1274 let mut primaries = self.display_primaries();
1275 let mut cc = primaries[(n - 1) as usize];
1276 buffa::Message::merge_length_delimited(&mut cc, buf, ctx)?;
1277 primaries[(n - 1) as usize] = cc;
1278 self.set_display_primaries(primaries);
1279 }
1280 4 => {
1281 if tag.wire_type() != WireType::LengthDelimited {
1282 return Err(DecodeError::WireTypeMismatch {
1283 field_number: 4,
1284 expected: LEN,
1285 actual: tag.wire_type() as u8,
1286 });
1287 }
1288 let mut wp = self.white_point();
1289 buffa::Message::merge_length_delimited(&mut wp, buf, ctx)?;
1290 self.set_white_point(wp);
1291 }
1292 5 => {
1293 if tag.wire_type() != WireType::Varint {
1294 return Err(DecodeError::WireTypeMismatch {
1295 field_number: 5,
1296 expected: VARINT,
1297 actual: tag.wire_type() as u8,
1298 });
1299 }
1300 let v = decode_uint32(buf)?;
1301 self.set_max_luminance(v);
1302 }
1303 6 => {
1304 if tag.wire_type() != WireType::Varint {
1305 return Err(DecodeError::WireTypeMismatch {
1306 field_number: 6,
1307 expected: VARINT,
1308 actual: tag.wire_type() as u8,
1309 });
1310 }
1311 let v = decode_uint32(buf)?;
1312 self.set_min_luminance(v);
1313 }
1314 _ => skip_field_depth(tag, buf, ctx.depth())?,
1315 }
1316 Ok(())
1317 }
1318
1319 fn clear(&mut self) {
1320 *self = MasteringDisplay::default();
1321 }
1322}
1323
1324impl DefaultInstance for HdrStaticMetadata {
1335 fn default_instance() -> &'static Self {
1336 static VALUE: buffa::__private::OnceBox<HdrStaticMetadata> = buffa::__private::OnceBox::new();
1337 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(HdrStaticMetadata::default()))
1338 }
1339}
1340
1341impl Message for HdrStaticMetadata {
1342 fn compute_size(&self, cache: &mut SizeCache) -> u32 {
1343 let mut size = 0u32;
1344 if let Some(md) = self.mastering() {
1345 let slot = cache.reserve();
1346 let inner = md.compute_size(cache);
1347 cache.set(slot, inner);
1348 size += 1 + varint_len(inner as u64) as u32 + inner;
1349 }
1350 if let Some(cll) = self.content_light() {
1351 let slot = cache.reserve();
1352 let inner = cll.compute_size(cache);
1353 cache.set(slot, inner);
1354 size += 1 + varint_len(inner as u64) as u32 + inner;
1355 }
1356 size
1357 }
1358
1359 fn write_to(&self, cache: &mut SizeCache, buf: &mut impl EncodeSink) {
1360 if let Some(md) = self.mastering() {
1361 Tag::new(1, WireType::LengthDelimited).encode(buf);
1362 encode_varint(cache.consume_next() as u64, buf);
1363 md.write_to(cache, buf);
1364 }
1365 if let Some(cll) = self.content_light() {
1366 Tag::new(2, WireType::LengthDelimited).encode(buf);
1367 encode_varint(cache.consume_next() as u64, buf);
1368 cll.write_to(cache, buf);
1369 }
1370 }
1371
1372 fn merge_field(
1373 &mut self,
1374 tag: Tag,
1375 buf: &mut impl Buf,
1376 ctx: DecodeContext<'_>,
1377 ) -> Result<(), DecodeError> {
1378 match tag.field_number() {
1379 1 => {
1380 if tag.wire_type() != WireType::LengthDelimited {
1381 return Err(DecodeError::WireTypeMismatch {
1382 field_number: 1,
1383 expected: LEN,
1384 actual: tag.wire_type() as u8,
1385 });
1386 }
1387 let mut md = self.mastering().unwrap_or_default();
1388 buffa::Message::merge_length_delimited(&mut md, buf, ctx)?;
1389 self.set_mastering(Some(md));
1390 }
1391 2 => {
1392 if tag.wire_type() != WireType::LengthDelimited {
1393 return Err(DecodeError::WireTypeMismatch {
1394 field_number: 2,
1395 expected: LEN,
1396 actual: tag.wire_type() as u8,
1397 });
1398 }
1399 let mut cll = self.content_light().unwrap_or_default();
1400 buffa::Message::merge_length_delimited(&mut cll, buf, ctx)?;
1401 self.set_content_light(Some(cll));
1402 }
1403 _ => skip_field_depth(tag, buf, ctx.depth())?,
1404 }
1405 Ok(())
1406 }
1407
1408 fn clear(&mut self) {
1409 *self = HdrStaticMetadata::default();
1410 }
1411}
1412
1413macro_rules! impl_string_enum_message {
1431 ($ty:ty, $default_expr:expr) => {
1432 impl DefaultInstance for $ty {
1433 fn default_instance() -> &'static Self {
1434 static VALUE: buffa::__private::OnceBox<$ty> = buffa::__private::OnceBox::new();
1435 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new($default_expr))
1436 }
1437 }
1438
1439 impl Message for $ty {
1440 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
1441 if *self != $default_expr {
1446 1 + string_encoded_len(self.as_str()) as u32
1447 } else {
1448 0
1449 }
1450 }
1451
1452 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
1453 if *self != $default_expr {
1454 Tag::new(1, WireType::LengthDelimited).encode(buf);
1455 encode_string(self.as_str(), buf);
1456 }
1457 }
1458
1459 fn merge_field(
1460 &mut self,
1461 tag: Tag,
1462 buf: &mut impl Buf,
1463 ctx: DecodeContext<'_>,
1464 ) -> Result<(), DecodeError> {
1465 match tag.field_number() {
1466 1 => {
1467 if tag.wire_type() != WireType::LengthDelimited {
1468 return Err(DecodeError::WireTypeMismatch {
1469 field_number: 1,
1470 expected: LEN,
1471 actual: tag.wire_type() as u8,
1472 });
1473 }
1474 let s = decode_string(buf)?;
1475 let Ok(parsed) = <$ty as core::str::FromStr>::from_str(&s);
1484 *self = parsed;
1485 }
1486 _ => skip_field_depth(tag, buf, ctx.depth())?,
1487 }
1488 Ok(())
1489 }
1490
1491 fn clear(&mut self) {
1492 *self = $default_expr;
1493 }
1494 }
1495 };
1496}
1497
1498impl_string_enum_message!(ChannelLayout, ChannelLayout::Other(Utf8Bytes::new()));
1502impl_string_enum_message!(ContainerFormat, ContainerFormat::Other(Utf8Bytes::new()));
1503impl_string_enum_message!(Format, Format::Other(Utf8Bytes::new()));
1504
1505impl_string_enum_message!(Matrix, Matrix::default());
1509impl_string_enum_message!(Primaries, Primaries::default());
1510impl_string_enum_message!(Transfer, Transfer::default());
1511impl_string_enum_message!(DynamicRange, DynamicRange::default());
1512impl_string_enum_message!(ChromaLocation, ChromaLocation::default());
1513impl_string_enum_message!(DcpTargetGamut, DcpTargetGamut::default());
1514impl_string_enum_message!(Rotation, Rotation::default());
1515impl_string_enum_message!(FieldOrder, FieldOrder::default());
1516impl_string_enum_message!(StereoMode, StereoMode::default());
1517impl_string_enum_message!(PixelFormat, PixelFormat::default());
1518impl_string_enum_message!(SampleFormat, SampleFormat::default());
1519
1520impl DefaultInstance for BitRateMode {
1529 fn default_instance() -> &'static Self {
1530 static VALUE: buffa::__private::OnceBox<BitRateMode> = buffa::__private::OnceBox::new();
1531 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(BitRateMode::default()))
1532 }
1533}
1534
1535impl Message for BitRateMode {
1536 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
1537 let v = self.to_u32();
1538 if v != 0 {
1539 1 + uint32_encoded_len(v) as u32
1540 } else {
1541 0
1542 }
1543 }
1544
1545 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
1546 let v = self.to_u32();
1547 if v != 0 {
1548 Tag::new(1, WireType::Varint).encode(buf);
1549 encode_uint32(v, buf);
1550 }
1551 }
1552
1553 fn merge_field(
1554 &mut self,
1555 tag: Tag,
1556 buf: &mut impl Buf,
1557 ctx: DecodeContext<'_>,
1558 ) -> Result<(), DecodeError> {
1559 match tag.field_number() {
1560 1 => {
1561 if tag.wire_type() != WireType::Varint {
1562 return Err(DecodeError::WireTypeMismatch {
1563 field_number: 1,
1564 expected: VARINT,
1565 actual: tag.wire_type() as u8,
1566 });
1567 }
1568 *self = BitRateMode::from_u32(decode_uint32(buf)?);
1569 }
1570 _ => skip_field_depth(tag, buf, ctx.depth())?,
1571 }
1572 Ok(())
1573 }
1574
1575 fn clear(&mut self) {
1576 *self = BitRateMode::default();
1577 }
1578}
1579
1580impl DefaultInstance for ChannelOrder {
1590 fn default_instance() -> &'static Self {
1591 static VALUE: buffa::__private::OnceBox<ChannelOrder> = buffa::__private::OnceBox::new();
1592 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(ChannelOrder::default()))
1593 }
1594}
1595
1596impl Message for ChannelOrder {
1597 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
1598 let v = self.to_u32();
1599 if v != 0 {
1600 1 + uint32_encoded_len(v) as u32
1601 } else {
1602 0
1603 }
1604 }
1605
1606 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
1607 let v = self.to_u32();
1608 if v != 0 {
1609 Tag::new(1, WireType::Varint).encode(buf);
1610 encode_uint32(v, buf);
1611 }
1612 }
1613
1614 fn merge_field(
1615 &mut self,
1616 tag: Tag,
1617 buf: &mut impl Buf,
1618 ctx: DecodeContext<'_>,
1619 ) -> Result<(), DecodeError> {
1620 match tag.field_number() {
1621 1 => {
1622 if tag.wire_type() != WireType::Varint {
1623 return Err(DecodeError::WireTypeMismatch {
1624 field_number: 1,
1625 expected: VARINT,
1626 actual: tag.wire_type() as u8,
1627 });
1628 }
1629 *self = ChannelOrder::from_u32(decode_uint32(buf)?);
1630 }
1631 _ => skip_field_depth(tag, buf, ctx.depth())?,
1632 }
1633 Ok(())
1634 }
1635
1636 fn clear(&mut self) {
1637 *self = ChannelOrder::default();
1638 }
1639}
1640
1641impl DefaultInstance for ChannelSpec {
1649 fn default_instance() -> &'static Self {
1650 static VALUE: buffa::__private::OnceBox<ChannelSpec> = buffa::__private::OnceBox::new();
1651 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(ChannelSpec::default()))
1652 }
1653}
1654
1655impl Message for ChannelSpec {
1656 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
1657 let mut size = 0u32;
1658 if self.index() != 0 {
1659 size += 1 + uint32_encoded_len(self.index()) as u32;
1660 }
1661 if self.raw_id() != 0 {
1662 size += 1 + uint32_encoded_len(self.raw_id()) as u32;
1663 }
1664 if !self.label().is_empty() {
1665 size += 1 + string_encoded_len(self.label()) as u32;
1666 }
1667 size
1668 }
1669
1670 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
1671 if self.index() != 0 {
1672 Tag::new(1, WireType::Varint).encode(buf);
1673 encode_uint32(self.index(), buf);
1674 }
1675 if self.raw_id() != 0 {
1676 Tag::new(2, WireType::Varint).encode(buf);
1677 encode_uint32(self.raw_id(), buf);
1678 }
1679 if !self.label().is_empty() {
1680 Tag::new(3, WireType::LengthDelimited).encode(buf);
1681 encode_string(self.label(), buf);
1682 }
1683 }
1684
1685 fn merge_field(
1686 &mut self,
1687 tag: Tag,
1688 buf: &mut impl Buf,
1689 ctx: DecodeContext<'_>,
1690 ) -> Result<(), DecodeError> {
1691 match tag.field_number() {
1692 n @ 1..=2 => {
1693 if tag.wire_type() != WireType::Varint {
1694 return Err(DecodeError::WireTypeMismatch {
1695 field_number: n,
1696 expected: VARINT,
1697 actual: tag.wire_type() as u8,
1698 });
1699 }
1700 let v = decode_uint32(buf)?;
1701 match n {
1702 1 => {
1703 self.set_index(v);
1704 }
1705 2 => {
1706 self.set_raw_id(v);
1707 }
1708 _ => unreachable!(),
1709 }
1710 }
1711 3 => {
1712 if tag.wire_type() != WireType::LengthDelimited {
1713 return Err(DecodeError::WireTypeMismatch {
1714 field_number: 3,
1715 expected: LEN,
1716 actual: tag.wire_type() as u8,
1717 });
1718 }
1719 let s = decode_string(buf)?;
1720 self.set_label(Utf8Bytes::from(s));
1721 }
1722 _ => skip_field_depth(tag, buf, ctx.depth())?,
1723 }
1724 Ok(())
1725 }
1726
1727 fn clear(&mut self) {
1728 *self = ChannelSpec::default();
1729 }
1730}
1731
1732impl DefaultInstance for ChannelLayoutDescription {
1755 fn default_instance() -> &'static Self {
1756 static VALUE: buffa::__private::OnceBox<ChannelLayoutDescription> =
1757 buffa::__private::OnceBox::new();
1758 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(ChannelLayoutDescription::default()))
1759 }
1760}
1761
1762impl Message for ChannelLayoutDescription {
1763 fn compute_size(&self, cache: &mut SizeCache) -> u32 {
1764 let mut size = 0u32;
1765 if self.order().to_u32() != 0 {
1766 size += 1 + uint32_encoded_len(self.order().to_u32()) as u32;
1767 }
1768 if self.channels() != 0 {
1769 size += 1 + uint32_encoded_len(self.channels()) as u32;
1770 }
1771 if !self.known_kind().as_str().is_empty() {
1772 size += 1 + string_encoded_len(self.known_kind().as_str()) as u32;
1773 }
1774 if let Some(mask) = self.native_mask() {
1775 size += 1 + uint64_encoded_len(mask) as u32;
1776 }
1777 for spec in self.custom_channels() {
1778 let slot = cache.reserve();
1779 let inner = spec.compute_size(cache);
1780 cache.set(slot, inner);
1781 size += 1 + varint_len(inner as u64) as u32 + inner;
1782 }
1783 if !self.text().is_empty() {
1784 size += 1 + string_encoded_len(self.text()) as u32;
1785 }
1786 size
1787 }
1788
1789 fn write_to(&self, cache: &mut SizeCache, buf: &mut impl EncodeSink) {
1790 if self.order().to_u32() != 0 {
1791 Tag::new(1, WireType::Varint).encode(buf);
1792 encode_uint32(self.order().to_u32(), buf);
1793 }
1794 if self.channels() != 0 {
1795 Tag::new(2, WireType::Varint).encode(buf);
1796 encode_uint32(self.channels(), buf);
1797 }
1798 if !self.known_kind().as_str().is_empty() {
1799 Tag::new(3, WireType::LengthDelimited).encode(buf);
1800 encode_string(self.known_kind().as_str(), buf);
1801 }
1802 if let Some(mask) = self.native_mask() {
1803 Tag::new(4, WireType::Varint).encode(buf);
1804 encode_uint64(mask, buf);
1805 }
1806 for spec in self.custom_channels() {
1807 Tag::new(5, WireType::LengthDelimited).encode(buf);
1808 encode_varint(cache.consume_next() as u64, buf);
1809 spec.write_to(cache, buf);
1810 }
1811 if !self.text().is_empty() {
1812 Tag::new(6, WireType::LengthDelimited).encode(buf);
1813 encode_string(self.text(), buf);
1814 }
1815 }
1816
1817 fn merge_field(
1818 &mut self,
1819 tag: Tag,
1820 buf: &mut impl Buf,
1821 ctx: DecodeContext<'_>,
1822 ) -> Result<(), DecodeError> {
1823 match tag.field_number() {
1824 n @ (1 | 2 | 4) => {
1825 if tag.wire_type() != WireType::Varint {
1826 return Err(DecodeError::WireTypeMismatch {
1827 field_number: n,
1828 expected: VARINT,
1829 actual: tag.wire_type() as u8,
1830 });
1831 }
1832 match n {
1833 1 => {
1834 self.set_order(ChannelOrder::from_u32(decode_uint32(buf)?));
1835 }
1836 2 => {
1837 self.set_channels(decode_uint32(buf)?);
1838 }
1839 4 => {
1840 self.set_native_mask(Some(decode_uint64(buf)?));
1841 }
1842 _ => unreachable!(),
1843 }
1844 }
1845 n @ (3 | 5 | 6) => {
1846 if tag.wire_type() != WireType::LengthDelimited {
1847 return Err(DecodeError::WireTypeMismatch {
1848 field_number: n,
1849 expected: LEN,
1850 actual: tag.wire_type() as u8,
1851 });
1852 }
1853 match n {
1854 3 => {
1855 let s = decode_string(buf)?;
1856 let Ok(parsed) = <ChannelLayout as core::str::FromStr>::from_str(&s);
1862 self.set_known_kind(parsed);
1863 }
1864 5 => {
1865 let mut spec = ChannelSpec::default();
1866 buffa::Message::merge_length_delimited(&mut spec, buf, ctx)?;
1867 self.push_custom_channel(spec);
1868 }
1869 6 => {
1870 let s = decode_string(buf)?;
1871 self.set_text(Utf8Bytes::from(s));
1872 }
1873 _ => unreachable!(),
1874 }
1875 }
1876 _ => skip_field_depth(tag, buf, ctx.depth())?,
1877 }
1878 Ok(())
1879 }
1880
1881 fn clear(&mut self) {
1882 *self = ChannelLayoutDescription::default();
1883 }
1884}
1885
1886const FIXED32: u8 = WireType::Fixed32 as u8;
1893
1894impl DefaultInstance for Loudness {
1895 fn default_instance() -> &'static Self {
1896 static VALUE: buffa::__private::OnceBox<Loudness> = buffa::__private::OnceBox::new();
1897 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Loudness::default()))
1898 }
1899}
1900
1901impl Message for Loudness {
1902 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
1903 let mut size = 0u32;
1904 if self.integrated_lufs() != 0.0 {
1907 size += 1 + FIXED32_ENCODED_LEN as u32;
1908 }
1909 if self.range_lu() != 0.0 {
1910 size += 1 + FIXED32_ENCODED_LEN as u32;
1911 }
1912 if self.true_peak_dbtp() != 0.0 {
1913 size += 1 + FIXED32_ENCODED_LEN as u32;
1914 }
1915 if self.sample_peak_dbfs() != 0.0 {
1916 size += 1 + FIXED32_ENCODED_LEN as u32;
1917 }
1918 size
1919 }
1920
1921 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
1922 if self.integrated_lufs() != 0.0 {
1923 Tag::new(1, WireType::Fixed32).encode(buf);
1924 encode_float(self.integrated_lufs(), buf);
1925 }
1926 if self.range_lu() != 0.0 {
1927 Tag::new(2, WireType::Fixed32).encode(buf);
1928 encode_float(self.range_lu(), buf);
1929 }
1930 if self.true_peak_dbtp() != 0.0 {
1931 Tag::new(3, WireType::Fixed32).encode(buf);
1932 encode_float(self.true_peak_dbtp(), buf);
1933 }
1934 if self.sample_peak_dbfs() != 0.0 {
1935 Tag::new(4, WireType::Fixed32).encode(buf);
1936 encode_float(self.sample_peak_dbfs(), buf);
1937 }
1938 }
1939
1940 fn merge_field(
1941 &mut self,
1942 tag: Tag,
1943 buf: &mut impl Buf,
1944 ctx: DecodeContext<'_>,
1945 ) -> Result<(), DecodeError> {
1946 match tag.field_number() {
1947 n @ 1..=4 => {
1948 if tag.wire_type() != WireType::Fixed32 {
1949 return Err(DecodeError::WireTypeMismatch {
1950 field_number: n,
1951 expected: FIXED32,
1952 actual: tag.wire_type() as u8,
1953 });
1954 }
1955 let v = decode_float(buf)?;
1956 match n {
1957 1 => {
1958 self.set_integrated_lufs(v);
1959 }
1960 2 => {
1961 self.set_range_lu(v);
1962 }
1963 3 => {
1964 self.set_true_peak_dbtp(v);
1965 }
1966 4 => {
1967 self.set_sample_peak_dbfs(v);
1968 }
1969 _ => unreachable!(),
1970 }
1971 }
1972 _ => skip_field_depth(tag, buf, ctx.depth())?,
1973 }
1974 Ok(())
1975 }
1976
1977 fn clear(&mut self) {
1978 *self = Loudness::default();
1979 }
1980}
1981
1982impl DefaultInstance for ReplayGain {
1991 fn default_instance() -> &'static Self {
1992 static VALUE: buffa::__private::OnceBox<ReplayGain> = buffa::__private::OnceBox::new();
1993 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(ReplayGain::default()))
1994 }
1995}
1996
1997impl Message for ReplayGain {
1998 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
1999 let mut size = 0u32;
2000 if self.track_gain_db() != 0.0 {
2002 size += 1 + FIXED32_ENCODED_LEN as u32;
2003 }
2004 if self.track_peak() != 0.0 {
2005 size += 1 + FIXED32_ENCODED_LEN as u32;
2006 }
2007 if self.album_gain_db().is_some() {
2009 size += 1 + FIXED32_ENCODED_LEN as u32;
2010 }
2011 if self.album_peak().is_some() {
2012 size += 1 + FIXED32_ENCODED_LEN as u32;
2013 }
2014 size
2015 }
2016
2017 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
2018 if self.track_gain_db() != 0.0 {
2019 Tag::new(1, WireType::Fixed32).encode(buf);
2020 encode_float(self.track_gain_db(), buf);
2021 }
2022 if self.track_peak() != 0.0 {
2023 Tag::new(2, WireType::Fixed32).encode(buf);
2024 encode_float(self.track_peak(), buf);
2025 }
2026 if let Some(v) = self.album_gain_db() {
2027 Tag::new(3, WireType::Fixed32).encode(buf);
2028 encode_float(v, buf);
2029 }
2030 if let Some(v) = self.album_peak() {
2031 Tag::new(4, WireType::Fixed32).encode(buf);
2032 encode_float(v, buf);
2033 }
2034 }
2035
2036 fn merge_field(
2037 &mut self,
2038 tag: Tag,
2039 buf: &mut impl Buf,
2040 ctx: DecodeContext<'_>,
2041 ) -> Result<(), DecodeError> {
2042 match tag.field_number() {
2043 n @ 1..=4 => {
2044 if tag.wire_type() != WireType::Fixed32 {
2045 return Err(DecodeError::WireTypeMismatch {
2046 field_number: n,
2047 expected: FIXED32,
2048 actual: tag.wire_type() as u8,
2049 });
2050 }
2051 let v = decode_float(buf)?;
2052 match n {
2053 1 => {
2054 self.set_track_gain_db(v);
2055 }
2056 2 => {
2057 self.set_track_peak(v);
2058 }
2059 3 => {
2060 self.set_album_gain_db(Some(v));
2061 }
2062 4 => {
2063 self.set_album_peak(Some(v));
2064 }
2065 _ => unreachable!(),
2066 }
2067 }
2068 _ => skip_field_depth(tag, buf, ctx.depth())?,
2069 }
2070 Ok(())
2071 }
2072
2073 fn clear(&mut self) {
2074 *self = ReplayGain::default();
2075 }
2076}
2077
2078fn audio_fingerprint_seed() -> Fingerprint {
2090 Fingerprint::try_new(Utf8Bytes::from_static("default"), std::vec::Vec::new())
2092 .unwrap_or_else(|_| unreachable!())
2093}
2094
2095impl DefaultInstance for Fingerprint {
2096 fn default_instance() -> &'static Self {
2097 static VALUE: buffa::__private::OnceBox<Fingerprint> = buffa::__private::OnceBox::new();
2098 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(audio_fingerprint_seed()))
2099 }
2100}
2101
2102impl Message for Fingerprint {
2103 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
2104 let mut size = 1 + string_encoded_len(self.algorithm()) as u32;
2105 if !self.value().is_empty() {
2106 size += 1 + bytes_encoded_len(self.value()) as u32;
2107 }
2108 size
2109 }
2110
2111 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
2112 Tag::new(1, WireType::LengthDelimited).encode(buf);
2113 encode_string(self.algorithm(), buf);
2114 if !self.value().is_empty() {
2115 Tag::new(2, WireType::LengthDelimited).encode(buf);
2116 encode_bytes(self.value(), buf);
2117 }
2118 }
2119
2120 fn merge_field(
2121 &mut self,
2122 tag: Tag,
2123 buf: &mut impl Buf,
2124 ctx: DecodeContext<'_>,
2125 ) -> Result<(), DecodeError> {
2126 match tag.field_number() {
2127 1 => {
2128 if tag.wire_type() != WireType::LengthDelimited {
2129 return Err(DecodeError::WireTypeMismatch {
2130 field_number: 1,
2131 expected: LEN,
2132 actual: tag.wire_type() as u8,
2133 });
2134 }
2135 let algo = decode_string(buf)?;
2136 let algo = if algo.is_empty() {
2140 Utf8Bytes::from_static("default")
2141 } else {
2142 Utf8Bytes::from(algo)
2143 };
2144 let value = self.value().to_vec();
2147 *self = Fingerprint::try_new(algo, value).unwrap_or_else(|_| audio_fingerprint_seed());
2148 }
2149 2 => {
2150 if tag.wire_type() != WireType::LengthDelimited {
2151 return Err(DecodeError::WireTypeMismatch {
2152 field_number: 2,
2153 expected: LEN,
2154 actual: tag.wire_type() as u8,
2155 });
2156 }
2157 let bytes = decode_bytes(buf)?;
2158 let algo = Utf8Bytes::from(self.algorithm());
2160 *self = Fingerprint::try_new(algo, bytes).unwrap_or_else(|_| audio_fingerprint_seed());
2161 }
2162 _ => skip_field_depth(tag, buf, ctx.depth())?,
2163 }
2164 Ok(())
2165 }
2166
2167 fn clear(&mut self) {
2168 *self = audio_fingerprint_seed();
2169 }
2170}
2171
2172fn audio_cover_art_seed() -> CoverArt {
2183 CoverArt::try_new(
2184 Utf8Bytes::from_static("application/octet-stream"),
2185 std::vec![0u8],
2186 )
2187 .unwrap_or_else(|_| unreachable!())
2188}
2189
2190impl DefaultInstance for CoverArt {
2191 fn default_instance() -> &'static Self {
2192 static VALUE: buffa::__private::OnceBox<CoverArt> = buffa::__private::OnceBox::new();
2193 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(audio_cover_art_seed()))
2194 }
2195}
2196
2197impl Message for CoverArt {
2198 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
2199 2 + string_encoded_len(self.mime()) as u32 + bytes_encoded_len(self.data()) as u32
2200 }
2201
2202 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
2203 Tag::new(1, WireType::LengthDelimited).encode(buf);
2204 encode_string(self.mime(), buf);
2205 Tag::new(2, WireType::LengthDelimited).encode(buf);
2206 encode_bytes(self.data(), buf);
2207 }
2208
2209 fn merge_field(
2210 &mut self,
2211 tag: Tag,
2212 buf: &mut impl Buf,
2213 ctx: DecodeContext<'_>,
2214 ) -> Result<(), DecodeError> {
2215 match tag.field_number() {
2216 1 => {
2217 if tag.wire_type() != WireType::LengthDelimited {
2218 return Err(DecodeError::WireTypeMismatch {
2219 field_number: 1,
2220 expected: LEN,
2221 actual: tag.wire_type() as u8,
2222 });
2223 }
2224 let mime = decode_string(buf)?;
2225 let mime = if mime.is_empty() {
2228 Utf8Bytes::from_static("application/octet-stream")
2229 } else {
2230 Utf8Bytes::from(mime)
2231 };
2232 let data = self.data().to_vec();
2233 let data = if data.is_empty() {
2234 std::vec![0u8]
2235 } else {
2236 data
2237 };
2238 *self = CoverArt::try_new(mime, data).unwrap_or_else(|_| audio_cover_art_seed());
2239 }
2240 2 => {
2241 if tag.wire_type() != WireType::LengthDelimited {
2242 return Err(DecodeError::WireTypeMismatch {
2243 field_number: 2,
2244 expected: LEN,
2245 actual: tag.wire_type() as u8,
2246 });
2247 }
2248 let data = decode_bytes(buf)?;
2249 let data = if data.is_empty() {
2252 std::vec![0u8]
2253 } else {
2254 data
2255 };
2256 let mime = Utf8Bytes::from(self.mime());
2257 *self = CoverArt::try_new(mime, data).unwrap_or_else(|_| audio_cover_art_seed());
2258 }
2259 _ => skip_field_depth(tag, buf, ctx.depth())?,
2260 }
2261 Ok(())
2262 }
2263
2264 fn clear(&mut self) {
2265 *self = audio_cover_art_seed();
2266 }
2267}
2268
2269impl DefaultInstance for Tags {
2278 fn default_instance() -> &'static Self {
2279 static VALUE: buffa::__private::OnceBox<Tags> = buffa::__private::OnceBox::new();
2280 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Tags::default()))
2281 }
2282}
2283
2284impl Message for Tags {
2285 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
2286 let mut size = 0u32;
2287 if !self.title().is_empty() {
2288 size += 1 + string_encoded_len(self.title()) as u32;
2289 }
2290 if !self.artist().is_empty() {
2291 size += 1 + string_encoded_len(self.artist()) as u32;
2292 }
2293 if !self.album_artist().is_empty() {
2294 size += 1 + string_encoded_len(self.album_artist()) as u32;
2295 }
2296 if !self.album().is_empty() {
2297 size += 1 + string_encoded_len(self.album()) as u32;
2298 }
2299 if !self.composer().is_empty() {
2300 size += 1 + string_encoded_len(self.composer()) as u32;
2301 }
2302 if !self.genre().is_empty() {
2303 size += 1 + string_encoded_len(self.genre()) as u32;
2304 }
2305 if !self.comment().is_empty() {
2306 size += 1 + string_encoded_len(self.comment()) as u32;
2307 }
2308 if self.year() != 0 {
2311 size += 1 + uint32_encoded_len(self.year() as u32) as u32;
2312 }
2313 if self.track_number() != 0 {
2314 size += 1 + uint32_encoded_len(self.track_number() as u32) as u32;
2315 }
2316 if self.track_total() != 0 {
2317 size += 1 + uint32_encoded_len(self.track_total() as u32) as u32;
2318 }
2319 if self.disc_number() != 0 {
2320 size += 1 + uint32_encoded_len(self.disc_number() as u32) as u32;
2321 }
2322 if self.disc_total() != 0 {
2323 size += 1 + uint32_encoded_len(self.disc_total() as u32) as u32;
2324 }
2325 if let Some(lang) = self.language() {
2326 size += 1 + string_encoded_len(&lang.to_string()) as u32;
2327 }
2328 size
2329 }
2330
2331 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
2332 if !self.title().is_empty() {
2333 Tag::new(1, WireType::LengthDelimited).encode(buf);
2334 encode_string(self.title(), buf);
2335 }
2336 if !self.artist().is_empty() {
2337 Tag::new(2, WireType::LengthDelimited).encode(buf);
2338 encode_string(self.artist(), buf);
2339 }
2340 if !self.album_artist().is_empty() {
2341 Tag::new(3, WireType::LengthDelimited).encode(buf);
2342 encode_string(self.album_artist(), buf);
2343 }
2344 if !self.album().is_empty() {
2345 Tag::new(4, WireType::LengthDelimited).encode(buf);
2346 encode_string(self.album(), buf);
2347 }
2348 if !self.composer().is_empty() {
2349 Tag::new(5, WireType::LengthDelimited).encode(buf);
2350 encode_string(self.composer(), buf);
2351 }
2352 if !self.genre().is_empty() {
2353 Tag::new(6, WireType::LengthDelimited).encode(buf);
2354 encode_string(self.genre(), buf);
2355 }
2356 if !self.comment().is_empty() {
2357 Tag::new(7, WireType::LengthDelimited).encode(buf);
2358 encode_string(self.comment(), buf);
2359 }
2360 if self.year() != 0 {
2361 Tag::new(8, WireType::Varint).encode(buf);
2362 encode_uint32(self.year() as u32, buf);
2363 }
2364 if self.track_number() != 0 {
2365 Tag::new(9, WireType::Varint).encode(buf);
2366 encode_uint32(self.track_number() as u32, buf);
2367 }
2368 if self.track_total() != 0 {
2369 Tag::new(10, WireType::Varint).encode(buf);
2370 encode_uint32(self.track_total() as u32, buf);
2371 }
2372 if self.disc_number() != 0 {
2373 Tag::new(11, WireType::Varint).encode(buf);
2374 encode_uint32(self.disc_number() as u32, buf);
2375 }
2376 if self.disc_total() != 0 {
2377 Tag::new(12, WireType::Varint).encode(buf);
2378 encode_uint32(self.disc_total() as u32, buf);
2379 }
2380 if let Some(lang) = self.language() {
2381 Tag::new(13, WireType::LengthDelimited).encode(buf);
2382 encode_string(&lang.to_string(), buf);
2383 }
2384 }
2385
2386 fn merge_field(
2387 &mut self,
2388 tag: Tag,
2389 buf: &mut impl Buf,
2390 ctx: DecodeContext<'_>,
2391 ) -> Result<(), DecodeError> {
2392 let n = tag.field_number();
2393 match n {
2394 1..=7 | 13 => {
2395 if tag.wire_type() != WireType::LengthDelimited {
2396 return Err(DecodeError::WireTypeMismatch {
2397 field_number: n,
2398 expected: LEN,
2399 actual: tag.wire_type() as u8,
2400 });
2401 }
2402 let s = decode_string(buf)?;
2403 let s = Utf8Bytes::from(s);
2404 match n {
2405 1 => {
2406 self.set_title(s);
2407 }
2408 2 => {
2409 self.set_artist(s);
2410 }
2411 3 => {
2412 self.set_album_artist(s);
2413 }
2414 4 => {
2415 self.set_album(s);
2416 }
2417 5 => {
2418 self.set_composer(s);
2419 }
2420 6 => {
2421 self.set_genre(s);
2422 }
2423 7 => {
2424 self.set_comment(s);
2425 }
2426 13 => {
2427 self.update_language(if s.is_empty() {
2433 None
2434 } else {
2435 Some(LanguageId::new(&s).unwrap_or_default())
2436 });
2437 }
2438 _ => unreachable!(),
2439 }
2440 }
2441 8..=12 => {
2442 if tag.wire_type() != WireType::Varint {
2443 return Err(DecodeError::WireTypeMismatch {
2444 field_number: n,
2445 expected: VARINT,
2446 actual: tag.wire_type() as u8,
2447 });
2448 }
2449 let v = decode_uint32(buf)? as u16;
2452 match n {
2453 8 => {
2454 self.set_year(v);
2455 }
2456 9 => {
2457 self.set_track_number(v);
2458 }
2459 10 => {
2460 self.set_track_total(v);
2461 }
2462 11 => {
2463 self.set_disc_number(v);
2464 }
2465 12 => {
2466 self.set_disc_total(v);
2467 }
2468 _ => unreachable!(),
2469 }
2470 }
2471 _ => skip_field_depth(tag, buf, ctx.depth())?,
2472 }
2473 Ok(())
2474 }
2475
2476 fn clear(&mut self) {
2477 *self = Tags::default();
2478 }
2479}
2480
2481impl DefaultInstance for TrackDisposition {
2490 fn default_instance() -> &'static Self {
2491 static VALUE: buffa::__private::OnceBox<TrackDisposition> = buffa::__private::OnceBox::new();
2492 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(TrackDisposition::default()))
2493 }
2494}
2495
2496impl Message for TrackDisposition {
2497 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
2498 if self.to_u32() != 0 {
2501 1 + uint32_encoded_len(self.to_u32()) as u32
2502 } else {
2503 0
2504 }
2505 }
2506
2507 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
2508 if self.to_u32() != 0 {
2509 Tag::new(1, WireType::Varint).encode(buf);
2510 encode_uint32(self.to_u32(), buf);
2511 }
2512 }
2513
2514 fn merge_field(
2515 &mut self,
2516 tag: Tag,
2517 buf: &mut impl Buf,
2518 ctx: DecodeContext<'_>,
2519 ) -> Result<(), DecodeError> {
2520 match tag.field_number() {
2521 1 => {
2522 if tag.wire_type() != WireType::Varint {
2523 return Err(DecodeError::WireTypeMismatch {
2524 field_number: 1,
2525 expected: VARINT,
2526 actual: tag.wire_type() as u8,
2527 });
2528 }
2529 let v = decode_uint32(buf)?;
2530 *self = TrackDisposition::from_u32(v);
2531 }
2532 _ => skip_field_depth(tag, buf, ctx.depth())?,
2533 }
2534 Ok(())
2535 }
2536
2537 fn clear(&mut self) {
2538 *self = TrackDisposition::default();
2539 }
2540}
2541
2542#[cfg(any(feature = "std", feature = "alloc"))]
2550mod subtitle_impls {
2551 use super::*;
2552 use ::buffa::types::{decode_string, encode_string, string_encoded_len};
2553 use core::str::FromStr;
2554
2555 use crate::subtitle::{Format, TrackOrigin};
2556
2557 impl DefaultInstance for TrackOrigin {
2567 fn default_instance() -> &'static Self {
2568 static VALUE: buffa::__private::OnceBox<TrackOrigin> = buffa::__private::OnceBox::new();
2569 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(TrackOrigin::default()))
2570 }
2571 }
2572
2573 impl Message for TrackOrigin {
2574 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
2575 1 + string_encoded_len(self.as_str()) as u32
2577 }
2578
2579 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
2580 Tag::new(1, WireType::LengthDelimited).encode(buf);
2581 encode_string(self.as_str(), buf);
2582 }
2583
2584 fn merge_field(
2585 &mut self,
2586 tag: Tag,
2587 buf: &mut impl Buf,
2588 ctx: DecodeContext<'_>,
2589 ) -> Result<(), DecodeError> {
2590 match tag.field_number() {
2591 1 => {
2592 if tag.wire_type() != WireType::LengthDelimited {
2593 return Err(DecodeError::WireTypeMismatch {
2594 field_number: 1,
2595 expected: LEN,
2596 actual: tag.wire_type() as u8,
2597 });
2598 }
2599 let s = decode_string(buf)?;
2600 let Ok(parsed) = TrackOrigin::from_str(&s);
2604 *self = parsed;
2605 }
2606 _ => skip_field_depth(tag, buf, ctx.depth())?,
2607 }
2608 Ok(())
2609 }
2610
2611 fn clear(&mut self) {
2612 *self = TrackOrigin::default();
2613 }
2614 }
2615
2616 impl DefaultInstance for Format {
2630 fn default_instance() -> &'static Self {
2631 static VALUE: buffa::__private::OnceBox<Format> = buffa::__private::OnceBox::new();
2632 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Format::default()))
2633 }
2634 }
2635
2636 impl Message for Format {
2637 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
2638 let slug = self.as_str();
2641 1 + string_encoded_len(slug) as u32
2642 }
2643
2644 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
2645 let slug = self.as_str();
2646 Tag::new(1, WireType::LengthDelimited).encode(buf);
2647 encode_string(slug, buf);
2648 }
2649
2650 fn merge_field(
2651 &mut self,
2652 tag: Tag,
2653 buf: &mut impl Buf,
2654 ctx: DecodeContext<'_>,
2655 ) -> Result<(), DecodeError> {
2656 match tag.field_number() {
2657 1 => {
2658 if tag.wire_type() != WireType::LengthDelimited {
2659 return Err(DecodeError::WireTypeMismatch {
2660 field_number: 1,
2661 expected: LEN,
2662 actual: tag.wire_type() as u8,
2663 });
2664 }
2665 let s = decode_string(buf)?;
2666 let Ok(parsed) = Format::from_str(&s);
2669 *self = parsed;
2670 }
2671 _ => skip_field_depth(tag, buf, ctx.depth())?,
2672 }
2673 Ok(())
2674 }
2675
2676 fn clear(&mut self) {
2677 *self = Format::default();
2678 }
2679 }
2680}
2681
2682#[cfg(any(feature = "std", feature = "alloc"))]
2695impl DefaultInstance for Device {
2696 fn default_instance() -> &'static Self {
2697 static VALUE: buffa::__private::OnceBox<Device> = buffa::__private::OnceBox::new();
2698 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Device::default()))
2699 }
2700}
2701
2702#[cfg(any(feature = "std", feature = "alloc"))]
2703impl Message for Device {
2704 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
2705 let mut size = 0u32;
2706 if !self.make().is_empty() {
2708 size += 1 + string_encoded_len(self.make()) as u32;
2709 }
2710 if !self.model().is_empty() {
2711 size += 1 + string_encoded_len(self.model()) as u32;
2712 }
2713 size
2714 }
2715
2716 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
2717 if !self.make().is_empty() {
2719 Tag::new(1, WireType::LengthDelimited).encode(buf);
2720 encode_string(self.make(), buf);
2721 }
2722 if !self.model().is_empty() {
2723 Tag::new(2, WireType::LengthDelimited).encode(buf);
2724 encode_string(self.model(), buf);
2725 }
2726 }
2727
2728 fn merge_field(
2729 &mut self,
2730 tag: Tag,
2731 buf: &mut impl Buf,
2732 ctx: DecodeContext<'_>,
2733 ) -> Result<(), DecodeError> {
2734 match tag.field_number() {
2735 1 => {
2736 if tag.wire_type() != WireType::LengthDelimited {
2737 return Err(DecodeError::WireTypeMismatch {
2738 field_number: 1,
2739 expected: LEN,
2740 actual: tag.wire_type() as u8,
2741 });
2742 }
2743 let s = decode_string(buf)?;
2744 self.set_make(s.as_str());
2745 }
2746 2 => {
2747 if tag.wire_type() != WireType::LengthDelimited {
2748 return Err(DecodeError::WireTypeMismatch {
2749 field_number: 2,
2750 expected: LEN,
2751 actual: tag.wire_type() as u8,
2752 });
2753 }
2754 let s = decode_string(buf)?;
2755 self.set_model(s.as_str());
2756 }
2757 _ => skip_field_depth(tag, buf, ctx.depth())?,
2758 }
2759 Ok(())
2760 }
2761
2762 fn clear(&mut self) {
2763 *self = Device::default();
2764 }
2765}
2766
2767#[cfg(any(feature = "std", feature = "alloc"))]
2782impl DefaultInstance for GeoLocation {
2783 fn default_instance() -> &'static Self {
2784 static VALUE: buffa::__private::OnceBox<GeoLocation> = buffa::__private::OnceBox::new();
2785 VALUE.get_or_init(|| {
2786 buffa::alloc::boxed::Box::new(GeoLocation::try_new(0.0, 0.0, None).expect("0,0 is valid"))
2787 })
2788 }
2789}
2790
2791#[cfg(any(feature = "std", feature = "alloc"))]
2792impl Message for GeoLocation {
2793 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
2794 let mut size = (1 + 8) + (1 + 8);
2796 if self.altitude().is_some() {
2797 size += 1 + 4;
2799 }
2800 size
2801 }
2802
2803 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
2804 Tag::new(1, WireType::Fixed64).encode(buf);
2805 encode_double(self.lat(), buf);
2806 Tag::new(2, WireType::Fixed64).encode(buf);
2807 encode_double(self.lon(), buf);
2808 if let Some(alt) = self.altitude() {
2809 Tag::new(3, WireType::Fixed32).encode(buf);
2810 encode_float(alt, buf);
2811 }
2812 }
2813
2814 fn merge_field(
2815 &mut self,
2816 tag: Tag,
2817 buf: &mut impl Buf,
2818 ctx: DecodeContext<'_>,
2819 ) -> Result<(), DecodeError> {
2820 match tag.field_number() {
2821 1 => {
2822 if tag.wire_type() != WireType::Fixed64 {
2823 return Err(DecodeError::WireTypeMismatch {
2824 field_number: 1,
2825 expected: WireType::Fixed64 as u8,
2826 actual: tag.wire_type() as u8,
2827 });
2828 }
2829 let v = decode_double(buf)?;
2830 let prev = *self;
2831 let lat = if v.is_finite() {
2836 v.clamp(-90.0, 90.0)
2837 } else {
2838 0.0
2839 };
2840 *self =
2841 GeoLocation::try_new(lat, prev.lon(), prev.altitude()).expect("clamped lat is in range");
2842 }
2843 2 => {
2844 if tag.wire_type() != WireType::Fixed64 {
2845 return Err(DecodeError::WireTypeMismatch {
2846 field_number: 2,
2847 expected: WireType::Fixed64 as u8,
2848 actual: tag.wire_type() as u8,
2849 });
2850 }
2851 let v = decode_double(buf)?;
2852 let prev = *self;
2853 let lon = if v.is_finite() {
2854 v.clamp(-180.0, 180.0)
2855 } else {
2856 0.0
2857 };
2858 *self =
2859 GeoLocation::try_new(prev.lat(), lon, prev.altitude()).expect("clamped lon is in range");
2860 }
2861 3 => {
2862 if tag.wire_type() != WireType::Fixed32 {
2863 return Err(DecodeError::WireTypeMismatch {
2864 field_number: 3,
2865 expected: WireType::Fixed32 as u8,
2866 actual: tag.wire_type() as u8,
2867 });
2868 }
2869 let v = decode_float(buf)?;
2870 self.set_altitude(v);
2871 }
2872 _ => skip_field_depth(tag, buf, ctx.depth())?,
2873 }
2874 Ok(())
2875 }
2876
2877 fn clear(&mut self) {
2878 *self = GeoLocation::try_new(0.0, 0.0, None).expect("0,0 is valid");
2879 }
2880}
2881
2882#[cfg(any(feature = "std", feature = "alloc"))]
2893impl DefaultInstance for LanguageId {
2894 fn default_instance() -> &'static Self {
2895 static VALUE: buffa::__private::OnceBox<LanguageId> = buffa::__private::OnceBox::new();
2896 VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(LanguageId::default()))
2897 }
2898}
2899
2900#[cfg(any(feature = "std", feature = "alloc"))]
2901impl Message for LanguageId {
2902 fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
2903 let tag = self.to_string();
2904 if tag.is_empty() {
2905 0
2906 } else {
2907 1 + string_encoded_len(&tag) as u32
2908 }
2909 }
2910
2911 fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
2912 let tag = self.to_string();
2913 if !tag.is_empty() {
2914 Tag::new(1, WireType::LengthDelimited).encode(buf);
2915 encode_string(&tag, buf);
2916 }
2917 }
2918
2919 fn merge_field(
2920 &mut self,
2921 tag: Tag,
2922 buf: &mut impl Buf,
2923 ctx: DecodeContext<'_>,
2924 ) -> Result<(), DecodeError> {
2925 match tag.field_number() {
2926 1 => {
2927 if tag.wire_type() != WireType::LengthDelimited {
2928 return Err(DecodeError::WireTypeMismatch {
2929 field_number: 1,
2930 expected: LEN,
2931 actual: tag.wire_type() as u8,
2932 });
2933 }
2934 let s = decode_string(buf)?;
2935 *self = LanguageId::new(&s).unwrap_or_default();
2943 }
2944 _ => skip_field_depth(tag, buf, ctx.depth())?,
2945 }
2946 Ok(())
2947 }
2948
2949 fn clear(&mut self) {
2950 *self = LanguageId::default();
2951 }
2952}
2953
2954#[cfg(test)]
2955mod tests;