Ejemplo n.º 1
0
 public void PushObject(object obj, string keyName = null)
 {
     if (mIsTxtMode)
     {
         mContext = StringSerialize.Serialize(obj);
     }
     else
     {
         if (string.IsNullOrEmpty(keyName))
         {
             keyName = obj.GetType().Name;
         }
         BytesPack pack = null;
         if (mIsBinary)
         {
             pack = BytesSerialize.Serialize(obj);
         }
         else
         {
             string temps = StringSerialize.Serialize(obj);
             pack = new BytesPack();
             pack.CreateReadBytes(System.Text.Encoding.UTF8.GetBytes(temps));
         }
         mDataPacks[keyName] = pack;
     }
 }
Ejemplo n.º 2
0
        private object _GetObject(object obj, System.Type type, string keyName)
        {
            if (mIsTxtMode)
            {
                if (obj == null)
                {
                    return(StringSerialize.Deserialize(mContext, type));
                }
                else
                {
                    StringSerialize.Deserialize(mContext, obj);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(keyName))
                {
                    keyName = type.Name;
                }

                BytesPack pack = null;
                if (mDataPacks.TryGetValue(keyName, out pack))
                {
                    if (mIsBinary)
                    {
                        if (obj == null)
                        {
                            return(BytesSerialize.Deserialize(pack, type));
                        }
                        else
                        {
                            BytesSerialize.Deserialize(pack, obj);
                        }
                    }
                    else
                    {
                        string str = System.Text.Encoding.UTF8.GetString(pack.GetStream());
                        if (obj == null)
                        {
                            return(StringSerialize.Deserialize(str, type));
                        }
                        else
                        {
                            StringSerialize.Deserialize(str, obj);
                        }
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 返回数据包里的消息
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public T SerializeMessage <T>()
 {
     byte[] data = Stream.ReadBytes((int)(Stream.Length - Stream.Position));
     return(BytesSerialize.FromBytes <T>(data));
 }
Ejemplo n.º 4
0
        //拷贝复制
        public static T CopyData <T>(T obj)
        {
            var pack = BytesSerialize.Serialize(obj);

            return((T)BytesSerialize.Deserialize <T>(pack));
        }