/// <summary>
        /// Initializes a new instance of the <see cref="BufferedMessageSet"/> class with compression.
        /// </summary>
        /// <param name="compressionCodec"></param>
        /// <param name="messages">messages to add</param>
        public BufferedMessageSet(CompressionCodecs compressionCodec, IEnumerable <Message> messages, int partition)
        {
            this.PartitionId = partition;
            IEnumerable <Message> messagesToAdd;

            switch (compressionCodec)
            {
            case CompressionCodecs.NoCompressionCodec:
                messagesToAdd = messages;
                break;

            default:
                var message = CompressionUtils.Compress(messages, compressionCodec, partition);
                messagesToAdd = new List <Message>()
                {
                    message
                };
                break;
            }

            int length = GetMessageSetSize(messagesToAdd);

            this.Messages        = messagesToAdd;
            this.ErrorCode       = (short)ErrorMapping.NoError;
            this.topIterPosition = 0;
        }
        private MessageAndOffset MakeNextOuter()
        {
            if (!this.Messages.Skip(topIterPosition).Any())
            {
                return(AllDone());
            }

            Message newMessage = this.Messages.ElementAt(topIterPosition);

            lastMessageSize = newMessage.Size;
            topIterPosition++;
            switch (newMessage.CompressionCodec)
            {
            case CompressionCodecs.NoCompressionCodec:
                Logger.DebugFormat(
                    "Message is uncompressed. Valid byte count = {0}",
                    currValidBytes);
                innerIter       = null;
                innerDone       = true;
                currValidBytes += 4 + newMessage.Size;
                return(new MessageAndOffset(newMessage, currValidBytes));

            default:
                Logger.DebugFormat("Message is compressed. Valid byte count = {0}", currValidBytes);
                innerIter = CompressionUtils.Decompress(newMessage, this.PartitionId).GetEnumerator();
                innerDone = !innerIter.MoveNext();
                return(MakeNext());
            }
        }
Exemple #3
0
        private MessageAndOffset MakeNextOuter()
        {
            if (topIterPosition >= this.Messages.Count())
            {
                return(AllDone());
            }

            Message newMessage = this.Messages.ToList()[topIterPosition];

            topIterPosition++;
            switch (newMessage.CompressionCodec)
            {
            case CompressionCodecs.NoCompressionCodec:
                if (Logger.IsDebugEnabled)
                {
                    Logger.DebugFormat(
                        CultureInfo.CurrentCulture,
                        "Message is uncompressed. Valid byte count = {0}",
                        currValidBytes);
                }

                innerIter       = null;
                currValidBytes += 4 + newMessage.Size;
                return(new MessageAndOffset(newMessage, currValidBytes));

            default:
                if (Logger.IsDebugEnabled)
                {
                    Logger.DebugFormat(CultureInfo.CurrentCulture, "Message is compressed. Valid byte count = {0}", currValidBytes);
                }

                innerIter = CompressionUtils.Decompress(newMessage).GetEnumerator();
                return(MakeNext());
            }
        }