コード例 #1
0
 public void Deserialize(MyStream stream, object target)
 {
     for (int i = 0; i < _desArray.Length; i++)
     {
         _desArray[i].Deserialize(stream, target);
     }
 }
コード例 #2
0
        internal void Serialize_Internal(MyStream stream, object target)
        {
            Type          targetType = target.GetType();
            ISerializable ser        = serializeMap[targetType];

            ser.Serialize(stream, target);
        }
コード例 #3
0
ファイル: Serialize.cs プロジェクト: OneBigShrimp/NetManager
 public void Serialize(MyStream stream, object target)
 {
     for (int i = 0; i < _serArray.Length; i++)
     {
         _serArray[i].Serialize(stream, target);
     }
 }
コード例 #4
0
        internal IProtocol Deserialize_Internal(MyStream stream)
        {
            int oldPos = stream.Position;

            this.CurProtocolId = stream.ReadInt();
            Type targetType     = id2Type[this.CurProtocolId];
            int  protocolLength = stream.ReadInt();
            int  finalPos       = stream.Position + protocolLength;

            if (stream.RemainCount < protocolLength)
            {
                //长度不够,回滚Position
                stream.Position = oldPos;
                return(null);
            }

            IProtocol result = _Deserialize(stream, targetType) as IProtocol;

            if (stream.Position != finalPos)
            {
                throw new LengthException();
                //rs.Position = startPos + protocolLength;
            }
            return(result);
        }
コード例 #5
0
 AsyncLinker(int sendBufferSize, int receiveBufferSize, NetExceptionProcess excProcess)
 {
     this._receiveStream     = new MyStream();
     this._sendStream        = new MyStream();
     this._sendBufferSize    = sendBufferSize;
     this._receiveBufferSize = receiveBufferSize;
     this._excProcess        = excProcess;
 }
コード例 #6
0
            internal override object GetDeserializeValue(MyStream stream)
            {
                byte  arrayLength = stream.ReadByte();
                Array array       = Array.CreateInstance(elementType, arrayLength);

                for (int i = 0; i < arrayLength; i++)
                {
                    array.SetValue(SerializeControl.Instance._Deserialize(stream, elementType), i);
                }
                return(array);
            }
コード例 #7
0
ファイル: Serialize.cs プロジェクト: OneBigShrimp/NetManager
            public override void Serialize(MyStream stream, object target)
            {
                Array array  = Field.GetValue(target) as Array;
                byte  length = (byte)array.Length;

                stream.Write(length);

                for (int i = 0; i < length; i++)
                {
                    SerializeControl.Instance.Serialize_Internal(stream, array.GetValue(i));
                }
            }
コード例 #8
0
ファイル: ThdLinker.cs プロジェクト: OneBigShrimp/NetManager
        ThdLinker(int sendBufferSize, int receiveBufferSize, NetExceptionProcess excProcess)
        {
            this._sendTransitOct = new MyOctets();
            this._sendBuffer     = new MyStream();

            this._receiveTransitStream = new MyStream(1024);
            this._receiveBuffer        = new byte[1024];

            this._sendEvent = new AutoResetEvent(false);

            this._sendBufferSize    = sendBufferSize;
            this._receiveBufferSize = receiveBufferSize;
            if (excProcess == null)
            {
                throw new Exception("parameter 'excProcess' can't be null!!");
            }
            this._excProcess = excProcess;
        }
コード例 #9
0
 /// <summary>
 /// 将一个byte数组反序列化为一组IProtocol对象
 /// </summary>
 /// <returns></returns>
 internal void Deserialize(MyStream stream, Queue <IProtocol> protocols)
 {
     for (int i = 0; i < 100; i++)
     {
         if (!stream.CanAnalyse)
         {//流的内容太短,无法解析类型和长度
             return;
         }
         IProtocol proto = Deserialize_Internal(stream);
         if (proto == null)
         {//协议长度不够,要和下次一起解析
             return;
         }
         else
         {
             protocols.Enqueue(proto);
         }
     }
 }
コード例 #10
0
        /// <summary>
        /// 序列化
        /// </summary>
        /// <param name="target">序列化目标</param>
        internal void Serialize(MyStream stream, IProtocol target)
        {
            Type targetType = target.GetType();

            if (!serializeMap.ContainsKey(targetType))
            {
                throw new NoRegistException(targetType);
            }

            int lengthPos = stream.Oct.Count + 4;

            stream.Write(type2Id[targetType]);
            //空出4个字节留给协议长度
            stream.Write(0);
            Serialize_Internal(stream, target);

            int length = stream.Oct.Count - lengthPos - 4;

            stream.WriteProtocolLength(lengthPos, length);
        }
コード例 #11
0
        /// <summary>
        /// 根据类型反序列化,会通过反射创建对象,并将其返回
        /// </summary>
        /// <returns></returns>
        internal object _Deserialize(MyStream stream, Type type)
        {
            if (!deserializeMap.ContainsKey(type))
            {
                throw new Exception("Type has not been regist : " + type);
            }

            if (typeof(ISerObj).IsAssignableFrom(type))
            {
                object          result = type.Assembly.CreateInstance(type.FullName);
                IDeserializable des    = deserializeMap[type];
                des.Deserialize(stream, result);
                return(result);
            }
            else
            {
                DeserializeCell des = deserializeMap[type] as DeserializeCell;
                return(des.GetDeserializeValue(stream));
            }
        }
コード例 #12
0
ファイル: Serialize.cs プロジェクト: OneBigShrimp/NetManager
 public override void Serialize(MyStream stream, object target)
 {
     SerializeControl.Instance.Serialize_Internal(stream, Field.GetValue(target));
 }
コード例 #13
0
ファイル: Serialize.cs プロジェクト: OneBigShrimp/NetManager
 public void Serialize(MyStream stream, object target)
 {
     _ser.Serialize(stream, target);
 }
コード例 #14
0
 internal override object GetDeserializeValue(MyStream stream)
 {
     return(stream.ReadString());
 }
コード例 #15
0
            internal void Deserialize(MyStream stream, object target)
            {
                object value = GetDeserializeValue(stream);

                Field.SetValue(target, value);
            }
コード例 #16
0
 internal abstract object GetDeserializeValue(MyStream stream);
コード例 #17
0
ファイル: Serialize.cs プロジェクト: OneBigShrimp/NetManager
 public abstract void Serialize(MyStream stream, object target);
コード例 #18
0
 internal object GetDeserializeValue(MyStream stream)
 {
     return(_des.GetDeserializeValue(stream));
 }
コード例 #19
0
ファイル: Serialize.cs プロジェクト: OneBigShrimp/NetManager
 public override void Serialize(MyStream stream, object target)
 {
     stream.Write((byte)GetSerializeValue(target));
 }
コード例 #20
0
 internal override object GetDeserializeValue(MyStream stream)
 {
     return(SerializeControl.Instance._Deserialize(stream, fieldType));
 }
コード例 #21
0
 public void Deserialize(MyStream stream, object target)
 {
     _des.Deserialize(stream, target);
 }
コード例 #22
0
ファイル: ThdLinker.cs プロジェクト: OneBigShrimp/NetManager
 static ThdLinker()
 {
     _sendMarshalStream = new MyStream();
 }