Пример #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
 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
            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(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
 public override void Serialize(MyStream stream, object target)
 {
     SerializeControl.Instance.Serialize_Internal(stream, Field.GetValue(target));
 }
Пример #13
0
 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
 public abstract void Serialize(MyStream stream, object target);
Пример #18
0
 internal object GetDeserializeValue(MyStream stream)
 {
     return(_des.GetDeserializeValue(stream));
 }
Пример #19
0
 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
 static ThdLinker()
 {
     _sendMarshalStream = new MyStream();
 }