public async Task SendMessageAsync(Message message) { try { await semaphore.DoAsync(async() => { using (var stream = new NetworkStream(this.socket)) { var stopwatch = Stopwatch.StartNew(); using (var byteStream = new MemoryStream()) { NodeEncoder.EncodeMessage(byteStream, message); var messageBytes = byteStream.ToArray(); await stream.WriteAsync(messageBytes, 0, messageBytes.Length); } stopwatch.Stop(); if (this.logger.IsTraceEnabled) { this.logger.Trace("Sent {0} in {1} ms\nPayload: {2}".Format2(message.Command, stopwatch.ElapsedMilliseconds, message.Payload.ToHexDataString())); } } }); } catch (Exception e) { Fail(e); } }
public void TestWireEncodeMessage() { var actual = NodeEncoder.EncodeMessage(MESSAGE_1); CollectionAssert.AreEqual(MESSAGE_1_BYTES.ToList(), actual.ToList()); }