use super::{AuthorisationKind, CmdError, DataAuthKind, QueryResponse};
use crate::{Blob, BlobAddress, Error, XorName};
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Hash, Eq, PartialEq, PartialOrd, Clone, Serialize, Deserialize)]
pub enum BlobRead {
Get(BlobAddress),
}
#[allow(clippy::large_enum_variant)]
#[derive(Hash, Eq, PartialEq, PartialOrd, Clone, Serialize, Deserialize)]
pub enum BlobWrite {
New(Blob),
DeletePrivate(BlobAddress),
}
impl BlobRead {
pub fn error(&self, error: Error) -> QueryResponse {
QueryResponse::GetBlob(Err(error))
}
pub fn authorisation_kind(&self) -> AuthorisationKind {
use BlobRead::*;
match self {
Get(BlobAddress::Public(_)) => AuthorisationKind::Data(DataAuthKind::PublicRead),
Get(BlobAddress::Private(_)) => AuthorisationKind::Data(DataAuthKind::PrivateRead),
}
}
pub fn dst_address(&self) -> XorName {
use BlobRead::*;
match self {
Get(ref address) => *address.name(),
}
}
}
impl BlobWrite {
pub fn error(&self, error: Error) -> CmdError {
CmdError::Data(error)
}
pub fn authorisation_kind(&self) -> AuthorisationKind {
AuthorisationKind::Data(DataAuthKind::Write)
}
pub fn dst_address(&self) -> XorName {
use BlobWrite::*;
match self {
New(ref data) => *data.name(),
DeletePrivate(ref address) => *address.name(),
}
}
}
impl fmt::Debug for BlobRead {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
use BlobRead::*;
match self {
Get(req) => write!(formatter, "{:?}", req),
}
}
}
impl fmt::Debug for BlobWrite {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
use BlobWrite::*;
match self {
New(req) => write!(formatter, "{:?}", req),
DeletePrivate(req) => write!(formatter, "{:?}", req),
}
}
}