/// <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); }
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)); } }
public override void Serialize(MyStream stream, object target) { stream.Write((byte)GetSerializeValue(target)); }