#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use crate::proto::mavlink_messages_v1 as proto;
use super::errors::ProtoImportError;
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Deprecated {
since: DeprecatedSince,
replaced_by: String,
}
impl Deprecated {
pub fn new(since: DeprecatedSince, replaced_by: String) -> Self {
Self { since, replaced_by }
}
pub fn to_proto(&self) -> proto::Deprecated {
proto::Deprecated {
since: Some(self.since.to_proto()),
replaced_by: self.replaced_by.clone(),
}
}
pub fn from_proto(proto: &proto::Deprecated) -> Result<Self, ProtoImportError> {
Ok(Self {
since: DeprecatedSince::from_proto(
proto
.since
.as_ref()
.ok_or(ProtoImportError::DeprecatedSinceIsNone)?,
),
replaced_by: proto.replaced_by.clone(),
})
}
pub fn since(&self) -> &DeprecatedSince {
&self.since
}
pub fn replaced_by(&self) -> &String {
&self.replaced_by
}
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DeprecatedSince {
year: i32,
month: u8,
}
impl DeprecatedSince {
pub fn new(year: i32, month: u8) -> Self {
Self { year, month }
}
pub fn to_proto(&self) -> proto::DeprecatedSince {
proto::DeprecatedSince {
year: self.year,
month: self.month as u32,
}
}
pub fn from_proto(proto: &proto::DeprecatedSince) -> Self {
Self {
year: proto.year,
month: proto.month as u8,
}
}
pub fn year(&self) -> i32 {
self.year
}
pub fn month(&self) -> u8 {
self.month
}
}