use core::num::NonZeroI64;
use ::buffa::{
DecodeContext, DecodeError, DefaultInstance, EncodeSink, Message, SizeCache,
bytes::Buf,
encoding::{Tag, WireType, encode_varint, skip_field_depth, varint_len},
types::{
FIXED32_ENCODED_LEN, bytes_encoded_len, decode_bytes, decode_double, decode_float,
decode_int64, decode_string, decode_uint32, decode_uint64, encode_bytes, encode_double,
encode_float, encode_int64, encode_string, encode_uint32, encode_uint64, int64_encoded_len,
string_encoded_len, uint32_encoded_len, uint64_encoded_len,
},
};
use smol_str::SmolStr;
use crate::{
audio::{
BitRateMode, ChannelLayout, ChannelLayoutDescription, ChannelOrder, ChannelSpec,
ContainerFormat, CoverArt, Fingerprint, Loudness, ReplayGain, SampleFormat, Tags,
},
capture::{Device, GeoLocation},
color::{
ChromaCoord, ChromaLocation, ContentLightLevel, DcpTargetGamut, DolbyVisionConfig,
DynamicRange, HdrStaticMetadata, Info, MasteringDisplay, Matrix, Primaries, Transfer,
},
container::Format,
disposition::TrackDisposition,
frame::{
DEN_ONE, Dimensions, FieldOrder, FrameRate, Rational, Rect, Rotation, SampleAspectRatio,
StereoMode,
},
lang::Language,
pixel_format::PixelFormat,
};
const VARINT: u8 = WireType::Varint as u8;
const LEN: u8 = WireType::LengthDelimited as u8;
impl DefaultInstance for Dimensions {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<Dimensions> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Dimensions::default()))
}
}
impl Message for Dimensions {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
if self.width() != 0 {
size += 1 + uint32_encoded_len(self.width()) as u32;
}
if self.height() != 0 {
size += 1 + uint32_encoded_len(self.height()) as u32;
}
size
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if self.width() != 0 {
Tag::new(1, WireType::Varint).encode(buf);
encode_uint32(self.width(), buf);
}
if self.height() != 0 {
Tag::new(2, WireType::Varint).encode(buf);
encode_uint32(self.height(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let w = decode_uint32(buf)?;
self.set_width(w);
}
2 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let h = decode_uint32(buf)?;
self.set_height(h);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = Dimensions::default();
}
}
impl DefaultInstance for Rect {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<Rect> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Rect::default()))
}
}
impl Message for Rect {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
if self.x() != 0 {
size += 1 + uint32_encoded_len(self.x()) as u32;
}
if self.y() != 0 {
size += 1 + uint32_encoded_len(self.y()) as u32;
}
if self.width() != 0 {
size += 1 + uint32_encoded_len(self.width()) as u32;
}
if self.height() != 0 {
size += 1 + uint32_encoded_len(self.height()) as u32;
}
size
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if self.x() != 0 {
Tag::new(1, WireType::Varint).encode(buf);
encode_uint32(self.x(), buf);
}
if self.y() != 0 {
Tag::new(2, WireType::Varint).encode(buf);
encode_uint32(self.y(), buf);
}
if self.width() != 0 {
Tag::new(3, WireType::Varint).encode(buf);
encode_uint32(self.width(), buf);
}
if self.height() != 0 {
Tag::new(4, WireType::Varint).encode(buf);
encode_uint32(self.height(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let v = decode_uint32(buf)?;
self.set_x(v);
}
2 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let v = decode_uint32(buf)?;
self.set_y(v);
}
3 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 3,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let v = decode_uint32(buf)?;
self.set_width(v);
}
4 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 4,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let v = decode_uint32(buf)?;
self.set_height(v);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = Rect::default();
}
}
impl DefaultInstance for SampleAspectRatio {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<SampleAspectRatio> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(SampleAspectRatio::default()))
}
}
impl Message for SampleAspectRatio {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
2 + int64_encoded_len(self.num()) as u32 + int64_encoded_len(self.den().get()) as u32
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
Tag::new(1, WireType::Varint).encode(buf);
encode_int64(self.num(), buf);
Tag::new(2, WireType::Varint).encode(buf);
encode_int64(self.den().get(), buf);
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let num = decode_int64(buf)?.max(0);
self.set_num(num);
}
2 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let den = NonZeroI64::new(decode_int64(buf)?)
.filter(|d| d.get() > 0)
.unwrap_or(DEN_ONE);
self.set_den(den);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = SampleAspectRatio::default();
}
}
impl DefaultInstance for Rational {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<Rational> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Rational::default()))
}
}
impl Message for Rational {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
2 + int64_encoded_len(self.num()) as u32 + int64_encoded_len(self.den().get()) as u32
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
Tag::new(1, WireType::Varint).encode(buf);
encode_int64(self.num(), buf);
Tag::new(2, WireType::Varint).encode(buf);
encode_int64(self.den().get(), buf);
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let num = decode_int64(buf)?.max(0);
self.set_num(num);
}
2 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let den = NonZeroI64::new(decode_int64(buf)?)
.filter(|d| d.get() > 0)
.unwrap_or(DEN_ONE);
self.set_den(den);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = Rational::default();
}
}
impl DefaultInstance for FrameRate {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<FrameRate> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(FrameRate::default()))
}
}
impl Message for FrameRate {
fn compute_size(&self, cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
{
let slot = cache.reserve();
let inner = self.rate().compute_size(cache);
cache.set(slot, inner);
size += 1 + varint_len(inner as u64) as u32 + inner;
}
if self.is_vfr() {
size += 1 + 1; }
size
}
fn write_to(&self, cache: &mut SizeCache, buf: &mut impl EncodeSink) {
Tag::new(1, WireType::LengthDelimited).encode(buf);
encode_varint(cache.consume_next() as u64, buf);
self.rate().write_to(cache, buf);
if self.is_vfr() {
Tag::new(2, WireType::Varint).encode(buf);
encode_varint(1, buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let mut rate = self.rate();
buffa::Message::merge_length_delimited(&mut rate, buf, ctx)?;
self.set_rate(rate);
}
2 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
self.update_is_vfr(decode_uint32(buf)? != 0);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = FrameRate::default();
}
}
impl DefaultInstance for DolbyVisionConfig {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<DolbyVisionConfig> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(DolbyVisionConfig::default()))
}
}
impl Message for DolbyVisionConfig {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
if self.profile() != 0 {
size += 1 + uint32_encoded_len(self.profile() as u32) as u32;
}
if self.level() != 0 {
size += 1 + uint32_encoded_len(self.level() as u32) as u32;
}
if self.rpu_present() {
size += 1 + 1;
}
if self.el_present() {
size += 1 + 1;
}
if self.bl_signal_compat_id() != 0 {
size += 1 + uint32_encoded_len(self.bl_signal_compat_id() as u32) as u32;
}
size
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if self.profile() != 0 {
Tag::new(1, WireType::Varint).encode(buf);
encode_uint32(self.profile() as u32, buf);
}
if self.level() != 0 {
Tag::new(2, WireType::Varint).encode(buf);
encode_uint32(self.level() as u32, buf);
}
if self.rpu_present() {
Tag::new(3, WireType::Varint).encode(buf);
encode_varint(1, buf);
}
if self.el_present() {
Tag::new(4, WireType::Varint).encode(buf);
encode_varint(1, buf);
}
if self.bl_signal_compat_id() != 0 {
Tag::new(5, WireType::Varint).encode(buf);
encode_uint32(self.bl_signal_compat_id() as u32, buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
self.set_profile(decode_uint32(buf)? as u8);
}
2 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
self.set_level(decode_uint32(buf)? as u8);
}
3 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 3,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
self.update_rpu_present(decode_uint32(buf)? != 0);
}
4 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 4,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
self.update_el_present(decode_uint32(buf)? != 0);
}
5 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 5,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
self.set_bl_signal_compat_id(decode_uint32(buf)? as u8);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = DolbyVisionConfig::default();
}
}
impl DefaultInstance for Info {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<Info> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Info::UNSPECIFIED))
}
}
impl Message for Info {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
5 + string_encoded_len(self.primaries().as_str()) as u32
+ string_encoded_len(self.transfer().as_str()) as u32
+ string_encoded_len(self.matrix().as_str()) as u32
+ string_encoded_len(self.range().as_str()) as u32
+ string_encoded_len(self.chroma_location().as_str()) as u32
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
Tag::new(1, WireType::LengthDelimited).encode(buf);
encode_string(self.primaries().as_str(), buf);
Tag::new(2, WireType::LengthDelimited).encode(buf);
encode_string(self.transfer().as_str(), buf);
Tag::new(3, WireType::LengthDelimited).encode(buf);
encode_string(self.matrix().as_str(), buf);
Tag::new(4, WireType::LengthDelimited).encode(buf);
encode_string(self.range().as_str(), buf);
Tag::new(5, WireType::LengthDelimited).encode(buf);
encode_string(self.chroma_location().as_str(), buf);
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
self.set_primaries(s.parse().unwrap_or_else(|_| unreachable!()));
}
2 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
self.set_transfer(s.parse().unwrap_or_else(|_| unreachable!()));
}
3 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 3,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
self.set_matrix(s.parse().unwrap_or_else(|_| unreachable!()));
}
4 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 4,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
self.set_range(s.parse().unwrap_or_else(|_| unreachable!()));
}
5 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 5,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
self.set_chroma_location(s.parse().unwrap_or_else(|_| unreachable!()));
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = Info::UNSPECIFIED;
}
}
impl DefaultInstance for ContentLightLevel {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<ContentLightLevel> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(ContentLightLevel::default()))
}
}
impl Message for ContentLightLevel {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
if self.max_cll() != 0 {
size += 1 + uint32_encoded_len(self.max_cll()) as u32;
}
if self.max_fall() != 0 {
size += 1 + uint32_encoded_len(self.max_fall()) as u32;
}
size
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if self.max_cll() != 0 {
Tag::new(1, WireType::Varint).encode(buf);
encode_uint32(self.max_cll(), buf);
}
if self.max_fall() != 0 {
Tag::new(2, WireType::Varint).encode(buf);
encode_uint32(self.max_fall(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let v = decode_uint32(buf)?;
self.set_max_cll(v);
}
2 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let v = decode_uint32(buf)?;
self.set_max_fall(v);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = ContentLightLevel::default();
}
}
impl DefaultInstance for ChromaCoord {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<ChromaCoord> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(ChromaCoord::default()))
}
}
impl Message for ChromaCoord {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
if self.x() != 0 {
size += 1 + uint32_encoded_len(self.x()) as u32;
}
if self.y() != 0 {
size += 1 + uint32_encoded_len(self.y()) as u32;
}
size
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if self.x() != 0 {
Tag::new(1, WireType::Varint).encode(buf);
encode_uint32(self.x(), buf);
}
if self.y() != 0 {
Tag::new(2, WireType::Varint).encode(buf);
encode_uint32(self.y(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
self.set_x(decode_uint32(buf)?);
}
2 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
self.set_y(decode_uint32(buf)?);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = ChromaCoord::default();
}
}
impl DefaultInstance for MasteringDisplay {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<MasteringDisplay> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(MasteringDisplay::default()))
}
}
impl Message for MasteringDisplay {
fn compute_size(&self, cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
let primaries = self.display_primaries();
for cc in &primaries {
let slot = cache.reserve();
let inner = cc.compute_size(cache);
cache.set(slot, inner);
size += 1 + varint_len(inner as u64) as u32 + inner;
}
{
let slot = cache.reserve();
let inner = self.white_point().compute_size(cache);
cache.set(slot, inner);
size += 1 + varint_len(inner as u64) as u32 + inner;
}
if self.max_luminance() != 0 {
size += 1 + uint32_encoded_len(self.max_luminance()) as u32;
}
if self.min_luminance() != 0 {
size += 1 + uint32_encoded_len(self.min_luminance()) as u32;
}
size
}
fn write_to(&self, cache: &mut SizeCache, buf: &mut impl EncodeSink) {
let primaries = self.display_primaries();
for (i, cc) in primaries.iter().enumerate() {
Tag::new(1 + i as u32, WireType::LengthDelimited).encode(buf);
encode_varint(cache.consume_next() as u64, buf);
cc.write_to(cache, buf);
}
Tag::new(4, WireType::LengthDelimited).encode(buf);
encode_varint(cache.consume_next() as u64, buf);
self.white_point().write_to(cache, buf);
if self.max_luminance() != 0 {
Tag::new(5, WireType::Varint).encode(buf);
encode_uint32(self.max_luminance(), buf);
}
if self.min_luminance() != 0 {
Tag::new(6, WireType::Varint).encode(buf);
encode_uint32(self.min_luminance(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
n @ 1..=3 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: n,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let mut primaries = self.display_primaries();
let mut cc = primaries[(n - 1) as usize];
buffa::Message::merge_length_delimited(&mut cc, buf, ctx)?;
primaries[(n - 1) as usize] = cc;
self.set_display_primaries(primaries);
}
4 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 4,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let mut wp = self.white_point();
buffa::Message::merge_length_delimited(&mut wp, buf, ctx)?;
self.set_white_point(wp);
}
5 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 5,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let v = decode_uint32(buf)?;
self.set_max_luminance(v);
}
6 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 6,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let v = decode_uint32(buf)?;
self.set_min_luminance(v);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = MasteringDisplay::default();
}
}
impl DefaultInstance for HdrStaticMetadata {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<HdrStaticMetadata> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(HdrStaticMetadata::default()))
}
}
impl Message for HdrStaticMetadata {
fn compute_size(&self, cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
if let Some(md) = self.mastering() {
let slot = cache.reserve();
let inner = md.compute_size(cache);
cache.set(slot, inner);
size += 1 + varint_len(inner as u64) as u32 + inner;
}
if let Some(cll) = self.content_light() {
let slot = cache.reserve();
let inner = cll.compute_size(cache);
cache.set(slot, inner);
size += 1 + varint_len(inner as u64) as u32 + inner;
}
size
}
fn write_to(&self, cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if let Some(md) = self.mastering() {
Tag::new(1, WireType::LengthDelimited).encode(buf);
encode_varint(cache.consume_next() as u64, buf);
md.write_to(cache, buf);
}
if let Some(cll) = self.content_light() {
Tag::new(2, WireType::LengthDelimited).encode(buf);
encode_varint(cache.consume_next() as u64, buf);
cll.write_to(cache, buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let mut md = self.mastering().unwrap_or_default();
buffa::Message::merge_length_delimited(&mut md, buf, ctx)?;
self.set_mastering(Some(md));
}
2 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let mut cll = self.content_light().unwrap_or_default();
buffa::Message::merge_length_delimited(&mut cll, buf, ctx)?;
self.set_content_light(Some(cll));
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = HdrStaticMetadata::default();
}
}
macro_rules! impl_string_enum_message {
($ty:ty, $default_expr:expr) => {
impl DefaultInstance for $ty {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<$ty> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new($default_expr))
}
}
impl Message for $ty {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
if *self != $default_expr {
1 + string_encoded_len(self.as_str()) as u32
} else {
0
}
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if *self != $default_expr {
Tag::new(1, WireType::LengthDelimited).encode(buf);
encode_string(self.as_str(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
let Ok(parsed) = <$ty as core::str::FromStr>::from_str(&s);
*self = parsed;
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = $default_expr;
}
}
};
}
impl_string_enum_message!(ChannelLayout, ChannelLayout::Other(SmolStr::new_inline("")));
impl_string_enum_message!(
ContainerFormat,
ContainerFormat::Other(SmolStr::new_inline(""))
);
impl_string_enum_message!(Format, Format::Other(SmolStr::new_inline("")));
impl_string_enum_message!(Matrix, Matrix::default());
impl_string_enum_message!(Primaries, Primaries::default());
impl_string_enum_message!(Transfer, Transfer::default());
impl_string_enum_message!(DynamicRange, DynamicRange::default());
impl_string_enum_message!(ChromaLocation, ChromaLocation::default());
impl_string_enum_message!(DcpTargetGamut, DcpTargetGamut::default());
impl_string_enum_message!(Rotation, Rotation::default());
impl_string_enum_message!(FieldOrder, FieldOrder::default());
impl_string_enum_message!(StereoMode, StereoMode::default());
impl_string_enum_message!(PixelFormat, PixelFormat::default());
impl_string_enum_message!(SampleFormat, SampleFormat::default());
impl DefaultInstance for BitRateMode {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<BitRateMode> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(BitRateMode::default()))
}
}
impl Message for BitRateMode {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let v = self.to_u32();
if v != 0 {
1 + uint32_encoded_len(v) as u32
} else {
0
}
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
let v = self.to_u32();
if v != 0 {
Tag::new(1, WireType::Varint).encode(buf);
encode_uint32(v, buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
*self = BitRateMode::from_u32(decode_uint32(buf)?);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = BitRateMode::default();
}
}
impl DefaultInstance for ChannelOrder {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<ChannelOrder> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(ChannelOrder::default()))
}
}
impl Message for ChannelOrder {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let v = self.to_u32();
if v != 0 {
1 + uint32_encoded_len(v) as u32
} else {
0
}
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
let v = self.to_u32();
if v != 0 {
Tag::new(1, WireType::Varint).encode(buf);
encode_uint32(v, buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
*self = ChannelOrder::from_u32(decode_uint32(buf)?);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = ChannelOrder::default();
}
}
impl DefaultInstance for ChannelSpec {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<ChannelSpec> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(ChannelSpec::default()))
}
}
impl Message for ChannelSpec {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
if self.index() != 0 {
size += 1 + uint32_encoded_len(self.index()) as u32;
}
if self.raw_id() != 0 {
size += 1 + uint32_encoded_len(self.raw_id()) as u32;
}
if !self.label().is_empty() {
size += 1 + string_encoded_len(self.label()) as u32;
}
size
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if self.index() != 0 {
Tag::new(1, WireType::Varint).encode(buf);
encode_uint32(self.index(), buf);
}
if self.raw_id() != 0 {
Tag::new(2, WireType::Varint).encode(buf);
encode_uint32(self.raw_id(), buf);
}
if !self.label().is_empty() {
Tag::new(3, WireType::LengthDelimited).encode(buf);
encode_string(self.label(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
n @ 1..=2 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: n,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let v = decode_uint32(buf)?;
match n {
1 => {
self.set_index(v);
}
2 => {
self.set_raw_id(v);
}
_ => unreachable!(),
}
}
3 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 3,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
self.set_label(SmolStr::new(s));
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = ChannelSpec::default();
}
}
impl DefaultInstance for ChannelLayoutDescription {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<ChannelLayoutDescription> =
buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(ChannelLayoutDescription::default()))
}
}
impl Message for ChannelLayoutDescription {
fn compute_size(&self, cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
if self.order().to_u32() != 0 {
size += 1 + uint32_encoded_len(self.order().to_u32()) as u32;
}
if self.channels() != 0 {
size += 1 + uint32_encoded_len(self.channels()) as u32;
}
if !self.known_kind().as_str().is_empty() {
size += 1 + string_encoded_len(self.known_kind().as_str()) as u32;
}
if let Some(mask) = self.native_mask() {
size += 1 + uint64_encoded_len(mask) as u32;
}
for spec in self.custom_channels() {
let slot = cache.reserve();
let inner = spec.compute_size(cache);
cache.set(slot, inner);
size += 1 + varint_len(inner as u64) as u32 + inner;
}
if !self.text().is_empty() {
size += 1 + string_encoded_len(self.text()) as u32;
}
size
}
fn write_to(&self, cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if self.order().to_u32() != 0 {
Tag::new(1, WireType::Varint).encode(buf);
encode_uint32(self.order().to_u32(), buf);
}
if self.channels() != 0 {
Tag::new(2, WireType::Varint).encode(buf);
encode_uint32(self.channels(), buf);
}
if !self.known_kind().as_str().is_empty() {
Tag::new(3, WireType::LengthDelimited).encode(buf);
encode_string(self.known_kind().as_str(), buf);
}
if let Some(mask) = self.native_mask() {
Tag::new(4, WireType::Varint).encode(buf);
encode_uint64(mask, buf);
}
for spec in self.custom_channels() {
Tag::new(5, WireType::LengthDelimited).encode(buf);
encode_varint(cache.consume_next() as u64, buf);
spec.write_to(cache, buf);
}
if !self.text().is_empty() {
Tag::new(6, WireType::LengthDelimited).encode(buf);
encode_string(self.text(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
n @ (1 | 2 | 4) => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: n,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
match n {
1 => {
self.set_order(ChannelOrder::from_u32(decode_uint32(buf)?));
}
2 => {
self.set_channels(decode_uint32(buf)?);
}
4 => {
self.set_native_mask(Some(decode_uint64(buf)?));
}
_ => unreachable!(),
}
}
n @ (3 | 5 | 6) => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: n,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
match n {
3 => {
let s = decode_string(buf)?;
let Ok(parsed) = <ChannelLayout as core::str::FromStr>::from_str(&s);
self.set_known_kind(parsed);
}
5 => {
let mut spec = ChannelSpec::default();
buffa::Message::merge_length_delimited(&mut spec, buf, ctx)?;
self.push_custom_channel(spec);
}
6 => {
let s = decode_string(buf)?;
self.set_text(SmolStr::new(s));
}
_ => unreachable!(),
}
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = ChannelLayoutDescription::default();
}
}
const FIXED32: u8 = WireType::Fixed32 as u8;
impl DefaultInstance for Loudness {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<Loudness> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Loudness::default()))
}
}
impl Message for Loudness {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
if self.integrated_lufs() != 0.0 {
size += 1 + FIXED32_ENCODED_LEN as u32;
}
if self.range_lu() != 0.0 {
size += 1 + FIXED32_ENCODED_LEN as u32;
}
if self.true_peak_dbtp() != 0.0 {
size += 1 + FIXED32_ENCODED_LEN as u32;
}
if self.sample_peak_dbfs() != 0.0 {
size += 1 + FIXED32_ENCODED_LEN as u32;
}
size
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if self.integrated_lufs() != 0.0 {
Tag::new(1, WireType::Fixed32).encode(buf);
encode_float(self.integrated_lufs(), buf);
}
if self.range_lu() != 0.0 {
Tag::new(2, WireType::Fixed32).encode(buf);
encode_float(self.range_lu(), buf);
}
if self.true_peak_dbtp() != 0.0 {
Tag::new(3, WireType::Fixed32).encode(buf);
encode_float(self.true_peak_dbtp(), buf);
}
if self.sample_peak_dbfs() != 0.0 {
Tag::new(4, WireType::Fixed32).encode(buf);
encode_float(self.sample_peak_dbfs(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
n @ 1..=4 => {
if tag.wire_type() != WireType::Fixed32 {
return Err(DecodeError::WireTypeMismatch {
field_number: n,
expected: FIXED32,
actual: tag.wire_type() as u8,
});
}
let v = decode_float(buf)?;
match n {
1 => {
self.set_integrated_lufs(v);
}
2 => {
self.set_range_lu(v);
}
3 => {
self.set_true_peak_dbtp(v);
}
4 => {
self.set_sample_peak_dbfs(v);
}
_ => unreachable!(),
}
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = Loudness::default();
}
}
impl DefaultInstance for ReplayGain {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<ReplayGain> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(ReplayGain::default()))
}
}
impl Message for ReplayGain {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
if self.track_gain_db() != 0.0 {
size += 1 + FIXED32_ENCODED_LEN as u32;
}
if self.track_peak() != 0.0 {
size += 1 + FIXED32_ENCODED_LEN as u32;
}
if self.album_gain_db().is_some() {
size += 1 + FIXED32_ENCODED_LEN as u32;
}
if self.album_peak().is_some() {
size += 1 + FIXED32_ENCODED_LEN as u32;
}
size
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if self.track_gain_db() != 0.0 {
Tag::new(1, WireType::Fixed32).encode(buf);
encode_float(self.track_gain_db(), buf);
}
if self.track_peak() != 0.0 {
Tag::new(2, WireType::Fixed32).encode(buf);
encode_float(self.track_peak(), buf);
}
if let Some(v) = self.album_gain_db() {
Tag::new(3, WireType::Fixed32).encode(buf);
encode_float(v, buf);
}
if let Some(v) = self.album_peak() {
Tag::new(4, WireType::Fixed32).encode(buf);
encode_float(v, buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
n @ 1..=4 => {
if tag.wire_type() != WireType::Fixed32 {
return Err(DecodeError::WireTypeMismatch {
field_number: n,
expected: FIXED32,
actual: tag.wire_type() as u8,
});
}
let v = decode_float(buf)?;
match n {
1 => {
self.set_track_gain_db(v);
}
2 => {
self.set_track_peak(v);
}
3 => {
self.set_album_gain_db(Some(v));
}
4 => {
self.set_album_peak(Some(v));
}
_ => unreachable!(),
}
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = ReplayGain::default();
}
}
fn audio_fingerprint_seed() -> Fingerprint {
Fingerprint::try_new(SmolStr::new_inline("default"), std::vec::Vec::new())
.unwrap_or_else(|_| unreachable!())
}
impl DefaultInstance for Fingerprint {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<Fingerprint> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(audio_fingerprint_seed()))
}
}
impl Message for Fingerprint {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let mut size = 1 + string_encoded_len(self.algorithm()) as u32;
if !self.value().is_empty() {
size += 1 + bytes_encoded_len(self.value()) as u32;
}
size
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
Tag::new(1, WireType::LengthDelimited).encode(buf);
encode_string(self.algorithm(), buf);
if !self.value().is_empty() {
Tag::new(2, WireType::LengthDelimited).encode(buf);
encode_bytes(self.value(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let algo = decode_string(buf)?;
let algo = if algo.is_empty() {
SmolStr::new_inline("default")
} else {
SmolStr::new(&algo)
};
let value = self.value().to_vec();
*self = Fingerprint::try_new(algo, value).unwrap_or_else(|_| audio_fingerprint_seed());
}
2 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let bytes = decode_bytes(buf)?;
let algo = SmolStr::from(self.algorithm());
*self = Fingerprint::try_new(algo, bytes).unwrap_or_else(|_| audio_fingerprint_seed());
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = audio_fingerprint_seed();
}
}
fn audio_cover_art_seed() -> CoverArt {
CoverArt::try_new(
SmolStr::new_static("application/octet-stream"),
std::vec![0u8],
)
.unwrap_or_else(|_| unreachable!())
}
impl DefaultInstance for CoverArt {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<CoverArt> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(audio_cover_art_seed()))
}
}
impl Message for CoverArt {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
2 + string_encoded_len(self.mime()) as u32 + bytes_encoded_len(self.data()) as u32
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
Tag::new(1, WireType::LengthDelimited).encode(buf);
encode_string(self.mime(), buf);
Tag::new(2, WireType::LengthDelimited).encode(buf);
encode_bytes(self.data(), buf);
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let mime = decode_string(buf)?;
let mime = if mime.is_empty() {
SmolStr::new_static("application/octet-stream")
} else {
SmolStr::new(&mime)
};
let data = self.data().to_vec();
let data = if data.is_empty() {
std::vec![0u8]
} else {
data
};
*self = CoverArt::try_new(mime, data).unwrap_or_else(|_| audio_cover_art_seed());
}
2 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let data = decode_bytes(buf)?;
let data = if data.is_empty() {
std::vec![0u8]
} else {
data
};
let mime = SmolStr::from(self.mime());
*self = CoverArt::try_new(mime, data).unwrap_or_else(|_| audio_cover_art_seed());
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = audio_cover_art_seed();
}
}
impl DefaultInstance for Tags {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<Tags> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Tags::default()))
}
}
impl Message for Tags {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
if !self.title().is_empty() {
size += 1 + string_encoded_len(self.title()) as u32;
}
if !self.artist().is_empty() {
size += 1 + string_encoded_len(self.artist()) as u32;
}
if !self.album_artist().is_empty() {
size += 1 + string_encoded_len(self.album_artist()) as u32;
}
if !self.album().is_empty() {
size += 1 + string_encoded_len(self.album()) as u32;
}
if !self.composer().is_empty() {
size += 1 + string_encoded_len(self.composer()) as u32;
}
if !self.genre().is_empty() {
size += 1 + string_encoded_len(self.genre()) as u32;
}
if !self.comment().is_empty() {
size += 1 + string_encoded_len(self.comment()) as u32;
}
if self.year() != 0 {
size += 1 + uint32_encoded_len(self.year() as u32) as u32;
}
if self.track_number() != 0 {
size += 1 + uint32_encoded_len(self.track_number() as u32) as u32;
}
if self.track_total() != 0 {
size += 1 + uint32_encoded_len(self.track_total() as u32) as u32;
}
if self.disc_number() != 0 {
size += 1 + uint32_encoded_len(self.disc_number() as u32) as u32;
}
if self.disc_total() != 0 {
size += 1 + uint32_encoded_len(self.disc_total() as u32) as u32;
}
if let Some(lang) = self.language() {
size += 1 + string_encoded_len(&lang.to_bcp47()) as u32;
}
size
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if !self.title().is_empty() {
Tag::new(1, WireType::LengthDelimited).encode(buf);
encode_string(self.title(), buf);
}
if !self.artist().is_empty() {
Tag::new(2, WireType::LengthDelimited).encode(buf);
encode_string(self.artist(), buf);
}
if !self.album_artist().is_empty() {
Tag::new(3, WireType::LengthDelimited).encode(buf);
encode_string(self.album_artist(), buf);
}
if !self.album().is_empty() {
Tag::new(4, WireType::LengthDelimited).encode(buf);
encode_string(self.album(), buf);
}
if !self.composer().is_empty() {
Tag::new(5, WireType::LengthDelimited).encode(buf);
encode_string(self.composer(), buf);
}
if !self.genre().is_empty() {
Tag::new(6, WireType::LengthDelimited).encode(buf);
encode_string(self.genre(), buf);
}
if !self.comment().is_empty() {
Tag::new(7, WireType::LengthDelimited).encode(buf);
encode_string(self.comment(), buf);
}
if self.year() != 0 {
Tag::new(8, WireType::Varint).encode(buf);
encode_uint32(self.year() as u32, buf);
}
if self.track_number() != 0 {
Tag::new(9, WireType::Varint).encode(buf);
encode_uint32(self.track_number() as u32, buf);
}
if self.track_total() != 0 {
Tag::new(10, WireType::Varint).encode(buf);
encode_uint32(self.track_total() as u32, buf);
}
if self.disc_number() != 0 {
Tag::new(11, WireType::Varint).encode(buf);
encode_uint32(self.disc_number() as u32, buf);
}
if self.disc_total() != 0 {
Tag::new(12, WireType::Varint).encode(buf);
encode_uint32(self.disc_total() as u32, buf);
}
if let Some(lang) = self.language() {
Tag::new(13, WireType::LengthDelimited).encode(buf);
encode_string(&lang.to_bcp47(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
let n = tag.field_number();
match n {
1..=7 | 13 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: n,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
let s = SmolStr::new(&s);
match n {
1 => {
self.set_title(s);
}
2 => {
self.set_artist(s);
}
3 => {
self.set_album_artist(s);
}
4 => {
self.set_album(s);
}
5 => {
self.set_composer(s);
}
6 => {
self.set_genre(s);
}
7 => {
self.set_comment(s);
}
13 => {
self.update_language(if s.is_empty() {
None
} else {
Some(Language::from_bcp47(&s).unwrap_or_default())
});
}
_ => unreachable!(),
}
}
8..=12 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: n,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let v = decode_uint32(buf)? as u16;
match n {
8 => {
self.set_year(v);
}
9 => {
self.set_track_number(v);
}
10 => {
self.set_track_total(v);
}
11 => {
self.set_disc_number(v);
}
12 => {
self.set_disc_total(v);
}
_ => unreachable!(),
}
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = Tags::default();
}
}
impl DefaultInstance for TrackDisposition {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<TrackDisposition> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(TrackDisposition::default()))
}
}
impl Message for TrackDisposition {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
if self.to_u32() != 0 {
1 + uint32_encoded_len(self.to_u32()) as u32
} else {
0
}
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if self.to_u32() != 0 {
Tag::new(1, WireType::Varint).encode(buf);
encode_uint32(self.to_u32(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::Varint {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: VARINT,
actual: tag.wire_type() as u8,
});
}
let v = decode_uint32(buf)?;
*self = TrackDisposition::from_u32(v);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = TrackDisposition::default();
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
mod subtitle_impls {
use super::*;
use ::buffa::types::{decode_string, encode_string, string_encoded_len};
use core::str::FromStr;
use crate::subtitle::{Format, TrackOrigin};
impl DefaultInstance for TrackOrigin {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<TrackOrigin> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(TrackOrigin::default()))
}
}
impl Message for TrackOrigin {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
1 + string_encoded_len(self.as_str()) as u32
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
Tag::new(1, WireType::LengthDelimited).encode(buf);
encode_string(self.as_str(), buf);
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
let Ok(parsed) = TrackOrigin::from_str(&s);
*self = parsed;
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = TrackOrigin::default();
}
}
impl DefaultInstance for Format {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<Format> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Format::default()))
}
}
impl Message for Format {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let slug = self.as_str();
1 + string_encoded_len(slug) as u32
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
let slug = self.as_str();
Tag::new(1, WireType::LengthDelimited).encode(buf);
encode_string(slug, buf);
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
let Ok(parsed) = Format::from_str(&s);
*self = parsed;
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = Format::default();
}
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl DefaultInstance for Device {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<Device> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Device::default()))
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl Message for Device {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let mut size = 0u32;
if !self.make().is_empty() {
size += 1 + string_encoded_len(self.make()) as u32;
}
if !self.model().is_empty() {
size += 1 + string_encoded_len(self.model()) as u32;
}
size
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
if !self.make().is_empty() {
Tag::new(1, WireType::LengthDelimited).encode(buf);
encode_string(self.make(), buf);
}
if !self.model().is_empty() {
Tag::new(2, WireType::LengthDelimited).encode(buf);
encode_string(self.model(), buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
self.set_make(s.as_str());
}
2 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
self.set_model(s.as_str());
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = Device::default();
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl DefaultInstance for GeoLocation {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<GeoLocation> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| {
buffa::alloc::boxed::Box::new(GeoLocation::try_new(0.0, 0.0, None).expect("0,0 is valid"))
})
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl Message for GeoLocation {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let mut size = (1 + 8) + (1 + 8);
if self.altitude().is_some() {
size += 1 + 4;
}
size
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
Tag::new(1, WireType::Fixed64).encode(buf);
encode_double(self.lat(), buf);
Tag::new(2, WireType::Fixed64).encode(buf);
encode_double(self.lon(), buf);
if let Some(alt) = self.altitude() {
Tag::new(3, WireType::Fixed32).encode(buf);
encode_float(alt, buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::Fixed64 {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: WireType::Fixed64 as u8,
actual: tag.wire_type() as u8,
});
}
let v = decode_double(buf)?;
let prev = *self;
let lat = if v.is_finite() {
v.clamp(-90.0, 90.0)
} else {
0.0
};
*self =
GeoLocation::try_new(lat, prev.lon(), prev.altitude()).expect("clamped lat is in range");
}
2 => {
if tag.wire_type() != WireType::Fixed64 {
return Err(DecodeError::WireTypeMismatch {
field_number: 2,
expected: WireType::Fixed64 as u8,
actual: tag.wire_type() as u8,
});
}
let v = decode_double(buf)?;
let prev = *self;
let lon = if v.is_finite() {
v.clamp(-180.0, 180.0)
} else {
0.0
};
*self =
GeoLocation::try_new(prev.lat(), lon, prev.altitude()).expect("clamped lon is in range");
}
3 => {
if tag.wire_type() != WireType::Fixed32 {
return Err(DecodeError::WireTypeMismatch {
field_number: 3,
expected: WireType::Fixed32 as u8,
actual: tag.wire_type() as u8,
});
}
let v = decode_float(buf)?;
self.set_altitude(v);
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = GeoLocation::try_new(0.0, 0.0, None).expect("0,0 is valid");
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl DefaultInstance for Language {
fn default_instance() -> &'static Self {
static VALUE: buffa::__private::OnceBox<Language> = buffa::__private::OnceBox::new();
VALUE.get_or_init(|| buffa::alloc::boxed::Box::new(Language::default()))
}
}
#[cfg(any(feature = "std", feature = "alloc"))]
impl Message for Language {
fn compute_size(&self, _cache: &mut SizeCache) -> u32 {
let tag = self.to_bcp47();
if tag.is_empty() {
0
} else {
1 + string_encoded_len(&tag) as u32
}
}
fn write_to(&self, _cache: &mut SizeCache, buf: &mut impl EncodeSink) {
let tag = self.to_bcp47();
if !tag.is_empty() {
Tag::new(1, WireType::LengthDelimited).encode(buf);
encode_string(&tag, buf);
}
}
fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
ctx: DecodeContext<'_>,
) -> Result<(), DecodeError> {
match tag.field_number() {
1 => {
if tag.wire_type() != WireType::LengthDelimited {
return Err(DecodeError::WireTypeMismatch {
field_number: 1,
expected: LEN,
actual: tag.wire_type() as u8,
});
}
let s = decode_string(buf)?;
*self = Language::from_bcp47(&s).unwrap_or_default();
}
_ => skip_field_depth(tag, buf, ctx.depth())?,
}
Ok(())
}
fn clear(&mut self) {
*self = Language::default();
}
}
#[cfg(test)]
mod tests;