コード例 #1
0
ファイル: BufferTests.cs プロジェクト: jorik041/CrossChat
        public void ParsingTest()
        {
            var sw = new Stopwatch();
            sw.Start();
            var commandParser = new CommandParser();
            var buffer = new CommandBuffer(commandParser);

            var resultCommands = new List<Command>();
            buffer.CommandAssembled += resultCommands.Add;
            
            int maxBytes = 1024 * 4;

            var allBytes = new List<byte>();

            for (int i = 1; i < maxBytes; i++)
            {
                allBytes.AddRange(commandParser.ToBytes(CommandNames.Data, GetBytes(i)));
            }

            var chunks = allBytes.Chunk(256).ToList();
            for (int i = 0; i < chunks.Count; i++)
            {
                buffer.AppendBytes(chunks[i].ToArray());
            }

            Assert.AreEqual(maxBytes - 1, resultCommands.Count);
            Assert.AreEqual(1, resultCommands[0].Data.Length);
            Assert.AreEqual(3, resultCommands[2].Data.Length);
            Assert.AreEqual(maxBytes - 1, resultCommands[maxBytes - 2].Data.Length);

            sw.Stop();
            var elapsed = sw.ElapsedMilliseconds;
        }
コード例 #2
0
 public SocketStreamTransportResource(CommandBuffer commandBuffer, CommandParser commandParser)
 {
     _commandBuffer = commandBuffer;
     _commandParser = commandParser;
     _commandBuffer.CommandAssembled += _commandBuffer_OnCommandAssembled;
 }