示例#1
0
        public static SequenceContext CreateFromPacket(IDataPacket data, int fragmentSize)
        {
            SequenceInitPacket initPacket;
            var ms = new MemoryStream();

            data.SerializeTo(ms);
            NetworkWriter.PrependStreamSize(ms);
            var completeBuff = ms.ToArray();

            Guid seqGuid;
            var  sequence = new SequenceHandler().CreateSequence(data, completeBuff, fragmentSize, out initPacket,
                                                                 out seqGuid);
            var initPacketStream = new MemoryStream();

            initPacket.SerializeTo(initPacketStream);

#if DEBUG
            //  var sequenceStreams = new MemoryStream[sequence.Length];
            //  var sequenceBuffs = new List<byte[]>();
            //for (var i = 0; i < sequence.Count; i++)
            //{
            //    var seq = sequence[i];
            //    sequenceStreams[i] = new MemoryStream();
            //    seq.SerializeTo(sequenceStreams[i]);
            //    sequenceBuffs.Add(sequenceStreams[i].ToArray());
            //}
#endif
            var seqCtx = new SequenceContext(initPacket, sequence, initPacketStream.ToArray(), null)
            {
                SequenceGuid = seqGuid
            };
            return(seqCtx);
        }