1use crate::codec as cyfs_base;
2use crate::*;
3
4use std::collections::HashMap;
5use std::net::IpAddr;
6
7pub const CYFS_NAME_MAX_LENGTH: usize = 40;
9
10#[derive(Clone, Copy, Eq, PartialEq, Debug, RawEncode, RawDecode)]
13#[repr(u8)]
14pub enum NameState {
15 Normal = 0,
16 Lock = 1,
17 Auction = 2, ArrearsAuction = 3, ArrearsAuctionWait = 4, ActiveAuction = 5, }
22
23impl From<i32> for NameState {
24 fn from(i: i32) -> Self {
25 match i {
26 0 => NameState::Normal,
27 1 => NameState::Lock,
28 2 => NameState::Auction,
29 3 => NameState::ArrearsAuction,
30 4 => NameState::ArrearsAuctionWait,
31 5 => NameState::ActiveAuction,
32 _ => {
33 unimplemented!()
34 }
35 }
36 }
37}
38
39#[derive(Clone, Debug, RawEncode, RawDecode)]
40pub enum NameLink {
41 ObjectLink(ObjectId),
42 OtherNameLink(String),
43 IPLink(IpAddr),
44}
45
46impl std::fmt::Display for NameLink {
47 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48 match self {
49 NameLink::ObjectLink(id) => {
50 write!(f, "link to obj {}", id)
51 }
52 NameLink::OtherNameLink(name) => {
53 write!(f, "link to name {}", name)
54 }
55 NameLink::IPLink(ip) => {
56 write!(f, "link to ip {}", ip)
57 }
58 }
59 }
60}
61
62#[derive(Clone, Debug, RawEncode, RawDecode)]
63pub struct NameRecord {
64 pub link: NameLink,
65 pub user_data: String,
66}
67
68#[derive(Clone, Debug, RawEncode, RawDecode)]
71pub struct NameInfo {
72 pub sub_records: HashMap<String, NameRecord>,
74 pub record: NameRecord,
76 pub owner: Option<ObjectId>,
77}
78