public void Deserialize(MyStream stream, object target) { for (int i = 0; i < _desArray.Length; i++) { _desArray[i].Deserialize(stream, target); } }
internal void Serialize_Internal(MyStream stream, object target) { Type targetType = target.GetType(); ISerializable ser = serializeMap[targetType]; ser.Serialize(stream, target); }
public void Serialize(MyStream stream, object target) { for (int i = 0; i < _serArray.Length; i++) { _serArray[i].Serialize(stream, target); } }
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); }
AsyncLinker(int sendBufferSize, int receiveBufferSize, NetExceptionProcess excProcess) { this._receiveStream = new MyStream(); this._sendStream = new MyStream(); this._sendBufferSize = sendBufferSize; this._receiveBufferSize = receiveBufferSize; this._excProcess = excProcess; }
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); }
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)); } }
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; }
/// <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); } } }
/// <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); }
/// <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)); } }
public override void Serialize(MyStream stream, object target) { SerializeControl.Instance.Serialize_Internal(stream, Field.GetValue(target)); }
public void Serialize(MyStream stream, object target) { _ser.Serialize(stream, target); }
internal override object GetDeserializeValue(MyStream stream) { return(stream.ReadString()); }
internal void Deserialize(MyStream stream, object target) { object value = GetDeserializeValue(stream); Field.SetValue(target, value); }
internal abstract object GetDeserializeValue(MyStream stream);
public abstract void Serialize(MyStream stream, object target);
internal object GetDeserializeValue(MyStream stream) { return(_des.GetDeserializeValue(stream)); }
public override void Serialize(MyStream stream, object target) { stream.Write((byte)GetSerializeValue(target)); }
internal override object GetDeserializeValue(MyStream stream) { return(SerializeControl.Instance._Deserialize(stream, fieldType)); }
public void Deserialize(MyStream stream, object target) { _des.Deserialize(stream, target); }
static ThdLinker() { _sendMarshalStream = new MyStream(); }