public void TestHeaderFrom() { var buffer = new MemoryStream(1000); var header = RawMessageHeader.From(1, 0, 100); var message = new RawMessage(100); header.CopyBytesTo(buffer); buffer.Flip(); message.HeaderFrom(buffer); buffer.Flip(); var convertedHeader = RawMessageHeader.From(buffer); Assert.Equal(header, convertedHeader); }
public void Sync() { if (!Underflow()) { var content = _workBuffer.ToArray(); if (_mode == ScanMode.ReadHeader) { _rawMessage.HeaderFrom(_workBuffer); } var messageTotalLength = _rawMessage.RequiredMessageLength; var missingRawMessageLength = messageTotalLength - _rawMessage.Length; var contentPosition = _workBuffer.Position; var availableContentLength = _workBuffer.Length - contentPosition; var appendLength = Math.Min(missingRawMessageLength, availableContentLength); _rawMessage.Append(content, contentPosition, appendLength); _workBuffer.Position = contentPosition + appendLength; if (availableContentLength == missingRawMessageLength) { _workBuffer.Clear(); SetMode(ScanMode.ReadHeader); } else if (availableContentLength > missingRawMessageLength) { SetMode(ScanMode.ReadHeader); } else if (availableContentLength < missingRawMessageLength) { _workBuffer.Clear(); SetMode(ScanMode.ReuseHeader); } } }