

use std::{ time };
use urlencoding::{ decode, encode };      // url解码编码
use bytesize;
use crate::prelude::*;


#[gen_特征_derive(MOD特征_tool)]
impl 信令路由{
    fn fn_字节to可读<T:Into<u64>>(字节:T)->String{                   TOOL工具::字节转可读(字节.into())  }
    fn fn_encodeURI(字符串:impl AsRef<str>)->String{                 TOOL工具::encodeURI(字符串)  }
    fn fn_decodeURI(字符串:impl AsRef<str>)->anyhow_Result<String>{  TOOL工具::decodeURI(字符串)  }
    fn 字节to可读<T:Into<u64>>(&self, 字节:T)->String{                TOOL工具::字节转可读(字节.into())  }
    fn encodeURI(&self,字符串:impl AsRef<str>)->String{                 TOOL工具::encodeURI(字符串)  }
    fn decodeURI(&self,字符串:impl AsRef<str>)->anyhow_Result<String>{  TOOL工具::decodeURI(字符串)  }
}


#[derive(Clone, Serialize, Deserialize)]//可选特征
enum 信令表{
    test{ 文本:String },
    test_回复{ 文本:String  },

}
impl信令特征!(信令表, 执行函数);

async fn 执行函数(信令路由:信令路由,id:信令ID,单个信令:信令表)->anyhow_Result<信令表>{ 
    match 单个信令{
        信令表::test{ 文本 }=>{ 
            anyhow_Ok信令!(信令表::test_回复 { 文本:文本 })
        }
        _ =>{ return Err(anyhow_err!("信令不存在")); }
    }
}



pub struct TOOL工具;
impl TOOL工具 {
    pub fn 字节转可读<T:Into<u64>>(size: T)->String{   bytesize::ByteSize::b(size.into()).to_string()  }
    pub fn decodeURI(字符串:impl AsRef<str>)->anyhow_Result<String>{  decode(字符串.as_ref()).map(|str|str.into_owned()).map_err(|err|anyhow_err!("{err}"))   }
    pub fn encodeURI(字符串:impl AsRef<str>)->String{  encode(字符串.as_ref()).into_owned()   }   // url解码编码
}

