示例#1
0
        /// <summary>
        ///     Take a raw message buffer and extract the endpoint name and serialized proto buffer.
        /// </summary>
        /// <param name="messageData"></param>
        public Message(byte[] messageData)
        {
            unsafe
            {
                var segmentReader = new UnsafeBinaryReader(Encoding.UTF8);
                fixed(byte *mData = messageData)
                {
                    var segment = new BufferSegment(mData);

                    segmentReader.SetBuffer(segment.Data, messageData.Length);
                    var length = segmentReader.ReadVariableLengthQuantity();

                    fixed(byte *headerData = segmentReader.ReadBytes(length))
                    {
                        Header = GetHeader(headerData, length);
                    }

                    Payload = segmentReader.ReadBytes(segmentReader.AvailableData());
                }
            }
        }
示例#2
0
        public void should_read_bytes([ValueSource(nameof(GetBufferSegmentSizes))] int bufferSegmentSize)
        {
            CreateContext(Encoding.UTF8, bufferSegmentSize);

            var bytes = new byte[bufferSegmentSize];

            new Random().NextBytes(bytes);
            _writer.Write(bytes, 0, bytes.Length);
            _writer.Write(_marker);

            var read = _reader.ReadBytes(bytes.Length);

            Assert.AreEqual(bytes, read);
            Assert.AreEqual(_marker, _reader.ReadUInt32());
        }