use super::*;
use crate::component::ComponentId;
#[repr(u8)]
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Serialize, Deserialize, Hash)]
pub enum AppDataUpdateOperationType {
Update = 1,
Remove = 2,
}
#[repr(u8)]
#[derive(
Debug,
PartialEq,
Eq,
Clone,
Serialize,
Deserialize,
TlsDeserialize,
TlsDeserializeBytes,
TlsSerialize,
TlsSize,
)]
pub enum AppDataUpdateOperation {
#[tls_codec(discriminant = 1)]
Update(VLBytes) = 1,
#[tls_codec(discriminant = 2)]
Remove = 2,
}
impl AppDataUpdateOperation {
pub fn operation_type(&self) -> AppDataUpdateOperationType {
match self {
AppDataUpdateOperation::Update(_) => AppDataUpdateOperationType::Update,
AppDataUpdateOperation::Remove => AppDataUpdateOperationType::Remove,
}
}
}
#[derive(
Debug,
PartialEq,
Clone,
Serialize,
Deserialize,
TlsSize,
TlsSerialize,
TlsDeserialize,
TlsDeserializeBytes,
)]
pub struct AppDataUpdateProposal {
component_id: ComponentId,
operation: AppDataUpdateOperation,
}
impl AppDataUpdateProposal {
pub fn update(component_id: ComponentId, data: impl Into<VLBytes>) -> Self {
Self::new(component_id, AppDataUpdateOperation::Update(data.into()))
}
pub fn remove(component_id: ComponentId) -> Self {
Self::new(component_id, AppDataUpdateOperation::Remove)
}
pub(crate) fn new(component_id: ComponentId, operation: AppDataUpdateOperation) -> Self {
Self {
component_id,
operation,
}
}
pub fn component_id(&self) -> ComponentId {
self.component_id
}
pub fn operation(&self) -> &AppDataUpdateOperation {
&self.operation
}
}