2021-03-12 04:49:51 +00:00
|
|
|
use crate::types::traits::*;
|
2021-01-12 12:21:01 +00:00
|
|
|
pub use std::ffi::OsStr;
|
|
|
|
pub use std::net::Ipv4Addr;
|
|
|
|
pub use std::path::Path;
|
2021-01-11 16:49:54 +00:00
|
|
|
pub enum NodeIdentifier {
|
|
|
|
Name(String),
|
|
|
|
Identity(String),
|
|
|
|
Addr(Ipv4Addr),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum TrustLevel {
|
|
|
|
Low,
|
|
|
|
Normal,
|
|
|
|
High,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum VisibilityLevel {
|
|
|
|
No,
|
|
|
|
NameOnly,
|
|
|
|
Yes,
|
|
|
|
}
|
|
|
|
pub enum VerbosityPut {
|
|
|
|
SimpleProgress,
|
|
|
|
ExpectedHashes,
|
|
|
|
PutFetchable,
|
|
|
|
StartedCompressionANDFinishedCompression,
|
|
|
|
}
|
2021-01-12 16:20:49 +00:00
|
|
|
|
|
|
|
impl FcpRequest for VerbosityPut {
|
2021-01-12 20:03:38 +00:00
|
|
|
fn convert(&self) -> String {
|
2021-01-12 16:20:49 +00:00
|
|
|
match self {
|
|
|
|
VerbosityPut::SimpleProgress => 0.to_string(),
|
|
|
|
VerbosityPut::ExpectedHashes => 3.to_string(),
|
|
|
|
VerbosityPut::PutFetchable => 8.to_string(),
|
|
|
|
VerbosityPut::StartedCompressionANDFinishedCompression => 9.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-01-12 20:03:38 +00:00
|
|
|
fn is_berbosity_put_converting() {
|
|
|
|
assert_eq!(fcp_types_unwrap::<VerbosityPut>(None), "".to_string());
|
2021-01-12 16:20:49 +00:00
|
|
|
assert_eq!(
|
2021-01-12 20:03:38 +00:00
|
|
|
fcp_types_unwrap::<VerbosityPut>(Some(&VerbosityPut::SimpleProgress)),
|
2021-01-12 16:20:49 +00:00
|
|
|
"0".to_string()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
2021-01-12 20:03:38 +00:00
|
|
|
fcp_types_unwrap::<VerbosityPut>(Some(&VerbosityPut::ExpectedHashes)),
|
2021-01-12 16:20:49 +00:00
|
|
|
"3".to_string()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
2021-01-12 20:03:38 +00:00
|
|
|
fcp_types_unwrap::<VerbosityPut>(Some(&VerbosityPut::PutFetchable)),
|
2021-01-12 16:20:49 +00:00
|
|
|
"8".to_string()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
2021-01-12 20:03:38 +00:00
|
|
|
fcp_types_unwrap::<VerbosityPut>(Some(
|
2021-01-12 16:20:49 +00:00
|
|
|
&VerbosityPut::StartedCompressionANDFinishedCompression
|
|
|
|
)),
|
|
|
|
"9".to_string()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-11 16:49:54 +00:00
|
|
|
pub enum VerbosityGet {
|
|
|
|
SimpleProgress,
|
|
|
|
SendingToNetwork,
|
|
|
|
CompatibilityMode,
|
|
|
|
ExpectedHashes,
|
|
|
|
ExpectedMIME,
|
|
|
|
ExpectedDataLength,
|
|
|
|
}
|
|
|
|
|
2021-02-15 18:11:46 +00:00
|
|
|
impl FcpRequest for VerbosityGet {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-11 16:49:54 +00:00
|
|
|
pub enum Retry {
|
|
|
|
None,
|
|
|
|
Forever,
|
|
|
|
Num(i32),
|
|
|
|
}
|
2021-01-12 21:28:00 +00:00
|
|
|
impl FcpRequest for Retry {
|
|
|
|
fn convert(&self) -> String {
|
2021-02-11 05:44:08 +00:00
|
|
|
match self {
|
2021-01-12 21:28:00 +00:00
|
|
|
Retry::None => "0".to_string(),
|
|
|
|
Retry::Forever => "-1".to_string(),
|
|
|
|
Retry::Num(num) => num.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-11 16:49:54 +00:00
|
|
|
|
|
|
|
pub enum Persistence {
|
|
|
|
Connection,
|
|
|
|
Reboot,
|
|
|
|
Forever,
|
|
|
|
}
|
|
|
|
|
2021-01-12 16:20:49 +00:00
|
|
|
impl FcpRequest for Persistence {
|
2021-01-12 20:03:38 +00:00
|
|
|
fn convert(&self) -> String {
|
2021-01-12 16:20:49 +00:00
|
|
|
match *self {
|
|
|
|
Persistence::Connection => "connection".to_string(),
|
|
|
|
Persistence::Reboot => "reboot".to_string(),
|
|
|
|
Persistence::Forever => "forever".to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-01-12 20:03:38 +00:00
|
|
|
fn is_persistence_converting() {
|
2021-01-12 16:20:49 +00:00
|
|
|
assert_eq!(
|
2021-01-12 20:03:38 +00:00
|
|
|
fcp_types_unwrap(Some(&Persistence::Connection)),
|
2021-01-12 16:20:49 +00:00
|
|
|
"connection".to_string()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
2021-01-12 20:03:38 +00:00
|
|
|
fcp_types_unwrap(Some(&Persistence::Reboot)),
|
2021-01-12 16:20:49 +00:00
|
|
|
"reboot".to_string()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
2021-01-12 20:03:38 +00:00
|
|
|
fcp_types_unwrap(Some(&Persistence::Forever)),
|
2021-01-12 16:20:49 +00:00
|
|
|
"forever".to_string()
|
|
|
|
);
|
2021-01-12 20:03:38 +00:00
|
|
|
assert_eq!(fcp_types_unwrap::<Persistence>(None), "".to_string());
|
2021-01-12 16:20:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 16:49:54 +00:00
|
|
|
pub enum UploadForm {
|
|
|
|
Direct,
|
|
|
|
Disk,
|
|
|
|
Redirect,
|
|
|
|
}
|
2021-01-12 20:03:38 +00:00
|
|
|
impl FcpRequest for UploadForm {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
match *self {
|
|
|
|
UploadForm::Direct => "direct".to_string(),
|
|
|
|
UploadForm::Disk => "disk".to_string(),
|
|
|
|
UploadForm::Redirect => "redirect".to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn is_upload_from_converting() {
|
|
|
|
assert_eq!(
|
|
|
|
fcp_types_unwrap(Some(&UploadForm::Direct)),
|
|
|
|
"direct".to_string()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
fcp_types_unwrap(Some(&UploadForm::Disk)),
|
|
|
|
"disk".to_string()
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
fcp_types_unwrap(Some(&UploadForm::Redirect)),
|
|
|
|
"redirect".to_string()
|
|
|
|
);
|
|
|
|
assert_eq!(fcp_types_unwrap::<Persistence>(None), "".to_string());
|
|
|
|
}
|
2021-01-11 16:49:54 +00:00
|
|
|
pub enum NumOrNone {
|
|
|
|
None,
|
|
|
|
Num(u32),
|
|
|
|
}
|
2021-02-15 18:11:46 +00:00
|
|
|
impl FcpRequest for NumOrNone {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FcpRequest for Vec<String> {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl FcpRequest for Box<Path> {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
}
|
2021-01-11 16:49:54 +00:00
|
|
|
|
|
|
|
pub enum Priority {
|
|
|
|
A, // 0
|
|
|
|
B, // 1
|
|
|
|
C, // 2
|
|
|
|
D, // 3
|
|
|
|
E, // 4
|
|
|
|
F, // 5
|
|
|
|
G, // 6
|
|
|
|
}
|
2021-01-12 15:43:00 +00:00
|
|
|
|
2021-01-12 20:03:38 +00:00
|
|
|
impl FcpRequest for Priority {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
match *self {
|
|
|
|
Priority::A => "0".to_string(),
|
|
|
|
Priority::B => "1".to_string(),
|
|
|
|
Priority::C => "2".to_string(),
|
|
|
|
Priority::D => "3".to_string(),
|
|
|
|
Priority::E => "4".to_string(),
|
|
|
|
Priority::F => "5".to_string(),
|
|
|
|
Priority::G => "6".to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[test]
|
|
|
|
fn is_priority_converting() {
|
|
|
|
assert_eq!(fcp_types_unwrap(Some(&Priority::A)), "0".to_string());
|
|
|
|
assert_eq!(fcp_types_unwrap(Some(&Priority::B)), "1".to_string());
|
|
|
|
assert_eq!(fcp_types_unwrap(Some(&Priority::C)), "2".to_string());
|
|
|
|
assert_eq!(fcp_types_unwrap(Some(&Priority::D)), "3".to_string());
|
|
|
|
assert_eq!(fcp_types_unwrap(Some(&Priority::E)), "4".to_string());
|
|
|
|
assert_eq!(fcp_types_unwrap(Some(&Priority::F)), "5".to_string());
|
|
|
|
assert_eq!(fcp_types_unwrap(Some(&Priority::G)), "6".to_string());
|
|
|
|
assert_eq!(fcp_types_unwrap::<Priority>(None), "".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FcpRequest for u32 {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
self.to_string()
|
|
|
|
}
|
|
|
|
}
|
2021-01-12 21:28:00 +00:00
|
|
|
impl FcpRequest for i64 {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
self.to_string()
|
|
|
|
}
|
|
|
|
}
|
2021-02-15 18:11:46 +00:00
|
|
|
impl FcpRequest for u64 {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
self.to_string()
|
|
|
|
}
|
|
|
|
}
|
2021-01-12 20:03:38 +00:00
|
|
|
impl FcpRequest for String {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
self.to_string()
|
|
|
|
}
|
|
|
|
}
|
2021-02-11 05:44:08 +00:00
|
|
|
impl FcpRequest for &String {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
self.to_string()
|
|
|
|
}
|
|
|
|
}
|
2021-01-12 20:03:38 +00:00
|
|
|
|
|
|
|
impl FcpRequest for bool {
|
|
|
|
fn convert(&self) -> String {
|
|
|
|
if *self {
|
|
|
|
"true".to_string()
|
|
|
|
} else {
|
|
|
|
"false".to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|