/// <summary>
/// 参数解码
/// </summary>
/// <param name="data">要解码的字节数组</param>
/// <param name="length">从0位置开始解码的长度</param>
/// <returns>解码结果</returns>
public static Dictionary<string, string> ParamDecoding(byte[] data, int length)
{
string outs = Encoding.UTF8.GetString(data, 0, (int)length);
Dictionary<string, string> pram = new Dictionary<string, string>();
string[] list = outs.Split("|".ToArray(), StringSplitOptions.RemoveEmptyEntries);
foreach (string item in list)
{
string[] x = item.Split("=".ToArray(), StringSplitOptions.RemoveEmptyEntries);
pram.Add(WidthDecoding(x[0]), WidthDecoding(x[1]));
}
return pram;
}
/// <summary>
/// 参数编码
/// </summary>
/// <param name="param">要编码的参数集合</param>
/// <returns>编码的结果字节</returns>
public static byte[] ParamEcoding(Dictionary<string, string> param)
{
StringBuilder bf = new StringBuilder();
foreach (string item in param.Keys)
{
bf.Append(WidthEcoding(item));
//bf.Append(item);
bf.Append("=");
bf.Append(WidthEcoding(param[item]));
bf.Append("|");
//bf.Append(list[item]);
}
byte[] outs = Encoding.UTF8.GetBytes(bf.ToString());
return outs;
}
/// <summary>
/// 款字节解码
/// </summary>
/// <param name="p_Value">要解码的宽字符编码(如:\u0efx\u094f)</param>
/// <returns></returns>
public static string WidthDecoding(string p_Value)
{
//string _ReturnText = "";
StringBuilder _ReturnText = new StringBuilder();
string[] _ValueList = p_Value.Split(new char[] { '\\', 'u' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i != _ValueList.Length; i++)
{
char _ValueChar = Convert.ToChar(Convert.ToUInt16(_ValueList, 16));
_ReturnText.Append(_ValueChar.ToString());
}
return _ReturnText.ToString();
}
/// <summary>
/// 宽字符编码
/// </summary>
/// <param name="s">要编码的字符串</param>
/// <returns>结果(如:\u0efx\u094f)</returns>
public static string WidthEcoding(string s)
{
StringBuilder outs = new StringBuilder();
foreach (char item in s)
{
outs.Append(string.Format("}", (int)item));
}
return outs.ToString();
}