public QueueMessage GetMessage(long position) { var buffer = GetMessageBuffer(position); if (buffer != null) { var nextOffset = 0; var messageLength = ByteUtil.DecodeInt(buffer, nextOffset, out nextOffset); if (messageLength > 0) { var message = new QueueMessage(); var messageBytes = new byte[messageLength]; Buffer.BlockCopy(buffer, nextOffset, messageBytes, 0, messageLength); message.ReadFrom(messageBytes); return(message); } } return(null); }
private IEnumerable <QueueMessage> DecodeMessages(PullRequest pullRequest, byte[] buffer) { var messages = new List <QueueMessage>(); if (buffer == null || buffer.Length <= 4) { return(messages); } try { var nextOffset = 0; var messageLength = MessageUtils.DecodeInt(buffer, nextOffset, out nextOffset); while (messageLength > 0) { var message = new QueueMessage(); var messageBytes = new byte[messageLength]; Buffer.BlockCopy(buffer, nextOffset, messageBytes, 0, messageLength); nextOffset += messageLength; message.ReadFrom(messageBytes); if (!message.IsValid()) { _logger.ErrorFormat("Invalid message, pullRequest: {0}", pullRequest); continue; } messages.Add(message); if (nextOffset >= buffer.Length) { break; } messageLength = MessageUtils.DecodeInt(buffer, nextOffset, out nextOffset); } } catch (Exception ex) { _logger.Error(string.Format("Decode pull return message has exception, pullRequest: {0}", pullRequest), ex); } return(messages); }