/// <summary> /// 反序列化 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <param name="data">数据</param> /// <param name="value">目标对象</param> /// <returns>是否成功</returns> internal bool DeSerializeTcpServer <valueType>(ref SubArray <byte> data, ref valueType value) { if (data.Length >= sizeof(int) * 3 && (data.Length & 3) == 0) { fixed(byte *dataFixed = (Buffer = data.GetFixedBuffer())) { start = dataFixed + (bufferIndex = data.Start); int length = data.Length - sizeof(int); End = start + length; if (((uint)(*(int *)End ^ length) | ((*(uint *)start & SerializeConfig.HeaderMapAndValue) ^ SerializeConfig.HeaderMapValue)) == 0) { //MemberMap = null; getGlobalVersion(); if (isReferenceMember == TypeDeSerializer <valueType> .IsReferenceMember) { if (points != null) { points.Clear(); } } else { if (isReferenceMember) { isReferenceMember = false; } else { isReferenceMember = true; if (points == null) { points = ReusableDictionary.CreateInt <object>(); } else { points.Clear(); } } } isReferenceArray = true; State = DeSerializeState.Success; TypeDeSerializer <valueType> .DeSerializeTcpServer(this, ref value); return(State == DeSerializeState.Success && Read == End); } } } return(false); }
/// <summary> /// 序列化 /// </summary> /// <typeparam name="valueType">目标数据类型</typeparam> /// <param name="value">数据对象</param> /// <param name="stream"></param> internal void SerializeTcpServer <valueType>(ref valueType value, UnmanagedStream stream) { //CurrentMemberMap = MemberMap = null; //Warning = SerializeWarning.None; if (isReferenceMember == AutoCSer.BinarySerialize.TypeSerializer <valueType> .IsReferenceMember) { if (points != null) { points.Clear(); } } else if (isReferenceMember) { isReferenceMember = false; } else { isReferenceMember = true; if (points == null) { points = ReusableDictionary <ObjectReference> .Create <int>(); } else { points.Clear(); } } //streamStartIndex = Stream.OffsetLength; streamStartIndex = stream.Data.CurrentIndex; isReferenceArray = true; Config.UnsafeWriteHeader(stream); Stream.From(stream); try { //Warning = SerializeWarning.None; AutoCSer.BinarySerialize.TypeSerializer <valueType> .SerializeTcpServer(this, ref value); } finally { stream.From(Stream); } //Stream.Write(Stream.OffsetLength - streamStartIndex); stream.Write(stream.Data.CurrentIndex - streamStartIndex); }
/// <summary> /// 对象转换JSON字符串 /// </summary> /// <typeparam name="valueType">目标数据类型</typeparam> /// <param name="value">数据对象</param> private void serialize <valueType>(ref valueType value) { #if AutoCSer if (Config.GetLoopObject == null || Config.SetLoopObject == null) { if (Config.GetLoopObject != null) { Warning = SerializeWarning.LessSetLoop; } else if (Config.SetLoopObject != null) { Warning = SerializeWarning.LessGetLoop; } else { Warning = SerializeWarning.None; } if (checkLoopDepth != Config.CheckLoopDepth || isLoopObject) { if (Config.CheckLoopDepth <= 0) { checkLoopDepth = 0; if (forefather == null) { forefather = new object[sizeof(int)]; } } else { checkLoopDepth = Config.CheckLoopDepth; } } isLoopObject = false; } else { if (!isLoopObject) { isLoopObject = true; if (objectIndexs == null) { objectIndexs = ReusableDictionary <ObjectReference> .Create <int>(); } } Warning = SerializeWarning.None; checkLoopDepth = Config.CheckLoopDepth <= 0 ? SerializeConfig.DefaultCheckLoopDepth : Config.CheckLoopDepth; } #else Warning = SerializeWarning.None; if (checkLoopDepth != Config.CheckLoopDepth) { if (Config.CheckLoopDepth <= 0) { checkLoopDepth = 0; if (forefather == null) { forefather = new object[sizeof(int)]; } } else { checkLoopDepth = Config.CheckLoopDepth; } } #endif TypeSerializer <valueType> .Serialize(this, ref value); }
/// <summary> /// 先进先出优先队列 /// </summary> /// <param name="dictionaryCapacity">字典初始化容器尺寸</param> /// <param name="isClear">是否需要清除数据</param> public FifoPriorityQueue(int dictionaryCapacity = 0, bool isClear = true) { dictionary = ReusableDictionary <keyType> .Create <Node>(dictionaryCapacity, isClear); }