Exemplo n.º 1
0
        public Message Add(MessageIdData messageId, uint redeliveryCount, MessageMetadata metadata, ReadOnlySequence <byte> data)
        {
            lock (_lock)
            {
                if (_trackBatches)
                {
                    _batches.AddLast(new Batch(messageId, metadata.NumMessagesInBatch));
                }

                long index = 0;

                for (var i = 0; i < metadata.NumMessagesInBatch; ++i)
                {
                    var singleMetadataSize = data.ReadUInt32(index, true);
                    index += 4;
                    var singleMetadata = Serializer.Deserialize <SingleMessageMetadata>(data.Slice(index, singleMetadataSize));
                    index += singleMetadataSize;
                    var singleMessageId = new MessageId(messageId.LedgerId, messageId.EntryId, messageId.Partition, i);
                    var message         = new Message(singleMessageId, redeliveryCount, metadata, singleMetadata, data.Slice(index, singleMetadata.PayloadSize));
                    _messages.Enqueue(message);
                    index += (uint)singleMetadata.PayloadSize;
                }

                return(_messages.Dequeue());
            }
        }
Exemplo n.º 2
0
 private static bool HasValidCheckSum(ReadOnlySequence <byte> input)
 => input.ReadUInt32(Constants.MagicNumber.Length, true) == Crc32C.Calculate(input.Slice(Constants.MetadataSizeOffset));