public static RawMessage ToRawMessage(this short sendingNodeId, Stream buffer) { buffer.Flip(); var message = new RawMessage(buffer.Length); message.Put(buffer, false); buffer.SetLength(0); // clear var header = new RawMessageHeader(sendingNodeId, (short)0, (int)message.Length); message.Header(header); return(message); }
public void TestPut() { var buffer = new MemoryStream(1000); var node1 = Node.With(Id.Of(1), Name.Of("node1"), Host.Of("localhost"), 37371, 37372); var join = new Join(node1); MessageConverters.MessageToBytes(join, buffer); var message = new RawMessage(1000); message.Put(buffer); buffer.Position = 0; var textOfRawMessage = message.AsTextMessage(); var textOfConvertedBuffer = Converters.BytesToText(buffer.ToArray(), 0, (int)buffer.Length); Assert.Equal(textOfConvertedBuffer, textOfRawMessage); }