use serde::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, schemars::JsonSchema)]
#[cfg_attr(feature = "server", derive(utoipa::ToSchema))]
#[serde(rename_all = "snake_case")]
pub enum WireProtocol {
SinglePutV1,
MultipartV1,
AzureBlockBlobV1,
LocalFsV1,
}
impl fmt::Display for WireProtocol {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::SinglePutV1 => "single_put_v1",
Self::MultipartV1 => "multipart_v1",
Self::AzureBlockBlobV1 => "azure_block_blob_v1",
Self::LocalFsV1 => "local_fs_v1",
})
}
}
impl FromStr for WireProtocol {
type Err = WireProtocolParseError;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"single_put_v1" => Ok(Self::SinglePutV1),
"multipart_v1" => Ok(Self::MultipartV1),
"azure_block_blob_v1" => Ok(Self::AzureBlockBlobV1),
"local_fs_v1" => Ok(Self::LocalFsV1),
other => Err(WireProtocolParseError(other.to_owned())),
}
}
}
#[derive(Debug, thiserror::Error)]
#[error("unknown wire protocol: {0}")]
pub struct WireProtocolParseError(String);