protected byte[] EncodeOffsetFetchRequest(OffsetFetchRequest request)
        {
            var message = new WriteByteStream();

            if (request.Topics == null)
            {
                request.Topics = new List <OffsetFetch>();
            }

            message.Pack(EncodeHeader(request));

            var topicGroups = request.Topics.GroupBy(x => x.Topic).ToList();

            message.Pack(ConsumerGroup.ToInt16SizedBytes(), topicGroups.Count.ToBytes());

            foreach (var topicGroup in topicGroups)
            {
                var partitions = topicGroup.GroupBy(x => x.PartitionId).ToList();
                message.Pack(topicGroup.Key.ToInt16SizedBytes(), partitions.Count.ToBytes());

                foreach (var partition in partitions)
                {
                    foreach (var offset in partition)
                    {
                        message.Pack(offset.PartitionId.ToBytes());
                    }
                }
            }

            message.Prepend(message.Length().ToBytes());

            return(message.Payload());
        }
        protected byte[] EncodeOffsetFetchRequest(OffsetFetchRequest request)
        {
            if (request.Topics == null)
            {
                request.Topics = new List <OffsetFetch>();
            }

            using (var message = EncodeHeader(request))
            {
                var topicGroups = request.Topics.GroupBy(x => x.Topic).ToList();

                message.Pack(ConsumerGroup, StringPrefixEncoding.Int16)
                .Pack(topicGroups.Count);

                foreach (var topicGroup in topicGroups)
                {
                    var partitions = topicGroup.GroupBy(x => x.PartitionId).ToList();
                    message.Pack(topicGroup.Key, StringPrefixEncoding.Int16)
                    .Pack(partitions.Count);

                    foreach (var partition in partitions)
                    {
                        foreach (var offset in partition)
                        {
                            message.Pack(offset.PartitionId);
                        }
                    }
                }

                return(message.Payload());
            }
        }