示例#1
0
        private static bool TryGetPacktedDataType(string data, out NetdataType type)
        {
            type = NetdataType.UnknownData;
            string[] splited = data.Split(HeaderSplitSymble.ToCharArray());
            int      id      = splited.Length == 2 ? int.Parse(splited[0]) : -1;

            type = id != -1 ? (NetdataType)id : type;
            return(id != -1);
        }
示例#2
0
        /// <summary>
        /// 解包数据
        /// </summary>
        /// <param name="type"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static NetdataType DepacketData(string data, out string dest)
        {
            dest = data;
            NetdataType type = NetdataType.UnknownData;

            if (TryGetPacktedDataType(data, out type))
            {
                dest = data.Split(HeaderSplitSymble.ToCharArray())[1];
            }
            return(type);
        }
示例#3
0
        /// <summary>
        /// 打包数据
        /// </summary>
        /// <param name="type"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static string PacketData(NetdataType type, string data)
        {
            string packed = type.ToString() + HeaderSplitSymble + data;

            return(packed);
        }