Esempio n. 1
0
 public int Write(RawMessage message, MemoryStream buffer)
 {
     buffer.Clear();
     message.CopyBytesTo(buffer);
     buffer.Flip();
     return(Write(buffer));
 }
 public MemoryStream BytesFrom(RawMessage message, MemoryStream buffer)
 {
     buffer.Clear();
     message.CopyBytesTo(buffer);
     buffer.Flip();
     return(buffer);
 }
        private void PrepareRawMessage(int position, long bytesToAppend)
        {
            var inboundHeader  = new RawMessageHeader(_node1.Id.Value, (short)0, (short)_buffer.Length);
            var inboundMessage = new RawMessage(_buffer.Length);

            if (position == 0)
            {
                inboundMessage.Header(inboundHeader);
            }
            inboundMessage.Append(_buffer.ToArray(), position, bytesToAppend);
            inboundMessage.CopyBytesTo(_builder.WorkBuffer());
        }
Esempio n. 4
0
        public static MemoryStream BytesFrom(string text)
        {
            var message = new RawMessage(Converters.TextToBytes(text));
            var header  = RawMessageHeader.From(1, 0, message.Length);

            message.Header(header);

            var buffer = new MemoryStream(4000);

            message.CopyBytesTo(buffer);
            buffer.Flip();

            return(buffer);
        }
        public void TestCopyBytesTo()
        {
            var buffer = new MemoryStream(1000);
            var node1  = NextNodeWith(1);
            var join   = new Join(node1);

            MessageConverters.MessageToBytes(join, buffer);
            buffer.Flip();
            var messageSize  = buffer.Length;
            var messageBytes = new byte[messageSize];

            Array.Copy(buffer.ToArray(), 0, messageBytes, 0, messageSize);
            var message = new RawMessage(messageBytes);

            message.Header(RawMessageHeader.From(node1.Id.Value, 0, message.Length));

            buffer.Clear();
            message.CopyBytesTo(buffer); // copyBytesTo
            var text = buffer.ToArray().BytesToText(RawMessageHeader.Bytes, (int)message.Length);

            Assert.True(OperationalMessage.MessageFrom(text).IsJoin);
        }
Esempio n. 6
0
        public void TestCopyBytesTo()
        {
            var buffer = new MemoryStream(1000);
            var text   = "JOIN\nid=1 nm=node1 op=localhost:35745 app=localhost:35746";
            var node1  = Node.With(Id.Of(1), Name.Of("node1"), Host.Of("localhost"), 35745, 35746);
            var bytes  = Converters.TextToBytes(text);

            buffer.Write(bytes, 0, bytes.Length);
            buffer.Flip();
            var messageSize  = buffer.Length;
            var messageBytes = new byte[messageSize];

            Array.Copy(buffer.ToArray(), 0, messageBytes, 0, messageSize);
            var message = new RawMessage(messageBytes);

            message.Header(RawMessageHeader.From(node1.Id.Value, 0, message.Length));
            Assert.Equal(text, message.AsTextMessage());

            buffer.Clear();
            message.CopyBytesTo(buffer); // copyBytesTo
            var convertedText = buffer.ToArray().BytesToText(RawMessageHeader.Bytes, (int)message.Length);

            Assert.Equal(text, convertedText);
        }
Esempio n. 7
0
 public IConsumerByteBuffer BytesFrom(RawMessage message, IConsumerByteBuffer buffer)
 {
     message.CopyBytesTo(buffer.Clear().AsStream());
     return(buffer.Flip());
 }