Ejemplo n.º 1
0
        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="source"></param>
        /// <param name="type"></param>
        /// <param name="data"></param>
        public OutputTunnelPacket(TunnelPipeline source, byte[] header, TunnelPacketType type, PacketData data) : base(source)
        {
            Type        = type;
            this.header = header;
            this.Length = data?.Size ?? 0;
            this.data   = data;

            HeaderSerializer.Serialize((int)type, data?.Size ?? 0, header);
        }
Ejemplo n.º 2
0
        void ContinueConstruct <TState>(IOCallback <TState> callback, TState state)
        {
            for (; headerSize < HeaderSize && sourceOffset < sourceSize; headerSize++)
            {
                header[headerSize] = source[sourceOffset++];
            }

            if (headerSize < HeaderSize)            // 信息头未解析完成
            {
                ReadMoreData <TState>(new object[] { callback, state });
                return;
            }

            HeaderSerializer.Deserialize(header, this);
            // 检查报文有效性
            if (Magic != MagicValue || Version != VersionValue)
            {
                trans.Interrupte();
                return;
            }

            length = Length;
            callback(Source, this, state);
        }