Esempio n. 1
0
        private byte[] EncodeOffsetRequest(OffsetRequest request)
        {
            if (request.Offsets == null)
            {
                request.Offsets = new List <Offset>();
            }
            using (var message = EncodeHeader(request))
            {
                var topicGroups = request.Offsets.GroupBy(x => x.Topic).ToList();
                message.Pack(ReplicaId)
                .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(partition.Key)
                            .Pack(offset.Time)
                            .Pack(offset.MaxOffsets);
                        }
                    }
                }

                return(message.Payload());
            }
        }
Esempio n. 2
0
        private byte[] EncodeOffsetRequest(OffsetRequest request)
        {
            var message = new WriteByteStream();

            if (request.Offsets == null)
            {
                request.Offsets = new List <Offset>();
            }

            message.Pack(EncodeHeader(request));

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

            message.Pack(ReplicaId.ToBytes(), 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(partition.Key.ToBytes(), offset.Time.ToBytes(), offset.MaxOffsets.ToBytes());
                    }
                }
            }

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

            return(message.Payload());
        }