use crate::codec as cyfs_base;
use crate::*;
use std::collections::HashMap;
use std::net::IpAddr;
pub const CYFS_NAME_MAX_LENGTH: usize = 40;
#[derive(Clone, Copy, Eq, PartialEq, Debug, RawEncode, RawDecode)]
#[repr(u8)]
pub enum NameState {
Normal = 0,
Lock = 1,
Auction = 2, ArrearsAuction = 3, ArrearsAuctionWait = 4, ActiveAuction = 5, }
impl From<i32> for NameState {
fn from(i: i32) -> Self {
match i {
0 => NameState::Normal,
1 => NameState::Lock,
2 => NameState::Auction,
3 => NameState::ArrearsAuction,
4 => NameState::ArrearsAuctionWait,
5 => NameState::ActiveAuction,
_ => {
unimplemented!()
}
}
}
}
#[derive(Clone, Debug, RawEncode, RawDecode)]
pub enum NameLink {
ObjectLink(ObjectId),
OtherNameLink(String),
IPLink(IpAddr),
}
impl std::fmt::Display for NameLink {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
NameLink::ObjectLink(id) => {
write!(f, "link to obj {}", id)
}
NameLink::OtherNameLink(name) => {
write!(f, "link to name {}", name)
}
NameLink::IPLink(ip) => {
write!(f, "link to ip {}", ip)
}
}
}
}
#[derive(Clone, Debug, RawEncode, RawDecode)]
pub struct NameRecord {
pub link: NameLink,
pub user_data: String,
}
#[derive(Clone, Debug, RawEncode, RawDecode)]
pub struct NameInfo {
pub sub_records: HashMap<String, NameRecord>,
pub record: NameRecord,
pub owner: Option<ObjectId>,
}