Пример #1
0
        private byte[] EncodeOffsetCommitRequest(OffsetCommitRequest request)
        {
            var message = new WriteByteStream();

            if (request.OffsetCommits == null)
            {
                request.OffsetCommits = new List <OffsetCommit>();
            }

            message.Pack(EncodeHeader(request));
            message.Pack(request.ConsumerGroup.ToInt16SizedBytes());

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

            message.Pack(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 commit in partition)
                    {
                        message.Pack(partition.Key.ToBytes(), commit.Offset.ToBytes(), commit.TimeStamp.ToBytes(), commit.Metadata.ToInt16SizedBytes());
                    }
                }
            }

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

            return(message.Payload());
        }
Пример #2
0
        private byte[] EncodeOffsetCommitRequest(OffsetCommitRequest request)
        {
            if (request.OffsetCommits == null)
            {
                request.OffsetCommits = new List <OffsetCommit>();
            }

            using (var message = EncodeHeader(request).Pack(request.ConsumerGroup, StringPrefixEncoding.Int16))
            {
                var topicGroups = request.OffsetCommits.GroupBy(x => x.Topic).ToList();
                message.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 commit in partition)
                        {
                            message.Pack(partition.Key)
                            .Pack(commit.Offset)
                            .Pack(commit.TimeStamp)
                            .Pack(commit.Metadata, StringPrefixEncoding.Int16);
                        }
                    }
                }

                return(message.Payload());
            }
        }