コード例 #1
0
        public void should_read_char_array_at_end_of_file([ValueSource(nameof(GetEncodings))] Encoding encoding,
                                                          [ValueSource(nameof(GetBufferSegmentSizes))] int bufferSegmentSize)
        {
            CreateContext(encoding, bufferSegmentSize);

            var chars = "Hello World!".ToCharArray();

            _writer.Write(chars, 0, chars.Length);

            var charsSubstring = chars.Take(5).ToArray();
            var buffer         = new char[5];

            _reader.SetBuffer(_segmentProvider.GetUnderlyingBufferPointer(), encoding.GetByteCount(charsSubstring));

            Assert.AreEqual(5, _reader.Read(buffer, 0, buffer.Length));
            Assert.AreEqual(charsSubstring, buffer);
        }
コード例 #2
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());
                }
            }
        }