/// <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); }