codama_nodes/shared/
bytes_encoding.rs

1use codama_errors::{CodamaError, CodamaResult};
2use serde::{Deserialize, Serialize};
3pub use BytesEncoding::*;
4
5#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
6#[serde(rename_all = "camelCase")]
7pub enum BytesEncoding {
8    Base16,
9    Base58,
10    Base64,
11    Utf8,
12}
13
14impl TryFrom<String> for BytesEncoding {
15    type Error = CodamaError;
16
17    fn try_from(value: String) -> CodamaResult<Self> {
18        value.as_str().try_into()
19    }
20}
21
22impl TryFrom<&str> for BytesEncoding {
23    type Error = CodamaError;
24
25    fn try_from(value: &str) -> CodamaResult<Self> {
26        match value {
27            "base16" => Ok(Base16),
28            "base58" => Ok(Base58),
29            "base64" => Ok(Base64),
30            "utf8" => Ok(Utf8),
31            _ => Err(CodamaError::InvalidBytesEncoding(value.to_string())),
32        }
33    }
34}