public static PartitionMetadata ReadFrom(ByteBuffer buffer, Dictionary <int, Broker> brokers) { var errorCode = ApiUtils.ReadShortInRange( buffer, "error code", Tuple.Create <short, short>(-1, short.MaxValue)); var partitionId = ApiUtils.ReadIntInRange(buffer, "partition id", Tuple.Create(0, int.MaxValue)); // partition id var leaderId = buffer.GetInt(); var leader = brokers[leaderId]; // list of all replicas var numReplicas = ApiUtils.ReadIntInRange(buffer, "number of all replicas", Tuple.Create(0, int.MaxValue)); var replicaIds = Enumerable.Range(0, numReplicas).Select(_ => buffer.GetInt()).ToList(); var replicas = replicaIds.Select(x => brokers[x]).ToList(); // list of in-sync replicasd var numIsr = ApiUtils.ReadIntInRange(buffer, "number of in-sync replicas", Tuple.Create(0, int.MaxValue)); var isrIds = Enumerable.Range(0, numIsr).Select(_ => buffer.GetInt()).ToList(); var isr = isrIds.Select(x => brokers[x]).ToList(); return(new PartitionMetadata(partitionId, leader, replicas, isr, errorCode)); }
public override void WriteTo(ByteBuffer buffer) { var groupedStatus = this.statusGroupedByTopic.Value; buffer.PutInt(this.CorrelationId); buffer.PutInt(groupedStatus.Count); // topic count foreach (var topicStatus in groupedStatus) { var topic = topicStatus.Key; var errorsAndOffsets = topicStatus.Value; ApiUtils.WriteShortString(buffer, topic); buffer.PutInt(errorsAndOffsets.Count); // partition count foreach (var kvp in errorsAndOffsets) { buffer.PutInt(kvp.Key.Partiton); buffer.PutShort(kvp.Value.Error); buffer.PutLong(kvp.Value.Offset); } } }
public static ProducerResponse ReadFrom(ByteBuffer buffer) { var correlationId = buffer.GetInt(); var topicCount = buffer.GetInt(); var statusPairs = Enumerable.Range(0, topicCount).SelectMany( _ => { var topic = ApiUtils.ReadShortString(buffer); var partitionCount = buffer.GetInt(); return(Enumerable.Range(0, partitionCount).Select( __ => { var partition = buffer.GetInt(); var error = buffer.GetShort(); var offset = buffer.GetLong(); return new KeyValuePair <TopicAndPartition, ProducerResponseStatus>( new TopicAndPartition(topic, partition), new ProducerResponseStatus(error, offset)); })); }); return(new ProducerResponse(statusPairs.ToDictionary(x => x.Key, x => x.Value), correlationId)); }
public override void WriteTo(ByteBuffer buffer) { buffer.PutInt(CorrelationId); buffer.PutInt(offsetsGroupedByTopic.Value.Count); // topic count foreach (var kvp in offsetsGroupedByTopic.Value) { var topic = kvp.Key; var errorAndOffsetsMap = kvp.Value; ApiUtils.WriteShortString(buffer, topic); buffer.PutInt(errorAndOffsetsMap.Count); foreach (var topicPartitionAndErrorOffset in errorAndOffsetsMap) { buffer.PutInt(topicPartitionAndErrorOffset.Key.Partiton); buffer.PutShort(topicPartitionAndErrorOffset.Value.Error); buffer.PutInt(topicPartitionAndErrorOffset.Value.Offsets.Count); foreach (var offset in topicPartitionAndErrorOffset.Value.Offsets) { buffer.PutLong(offset); } } } }
public static OffsetResponse ReadFrom(ByteBuffer buffer) { var correlationId = buffer.GetInt(); var numTopics = buffer.GetInt(); var pairs = Enumerable.Range(1, numTopics).SelectMany(_ => { var topic = ApiUtils.ReadShortString(buffer); var numPartitions = buffer.GetInt(); return(Enumerable.Range(1, numPartitions).Select(__ => { var partiton = buffer.GetInt(); var error = buffer.GetShort(); var numOffsets = buffer.GetInt(); var offsets = Enumerable.Range(1, numOffsets).Select(o => buffer.GetLong()).ToList(); return new KeyValuePair <TopicAndPartition, PartitionOffsetsResponse>( new TopicAndPartition(topic, partiton), new PartitionOffsetsResponse(error, offsets)); })); }); return(new OffsetResponse(correlationId, pairs.ToDictionary(kvp => kvp.Key, kvp => kvp.Value))); }
public override void WriteTo(ByteBuffer buffer) { buffer.PutShort(this.VersionId); buffer.PutInt(this.CorrelationId); ApiUtils.WriteShortString(buffer, this.ClientId); buffer.PutInt(this.ReplicaId); buffer.PutInt(this.MaxWait); buffer.PutInt(this.MinBytes); buffer.PutInt(this.requestInfoGroupedByTopic.Value.Count); // topic count foreach (var kvp in this.requestInfoGroupedByTopic.Value) { var topic = kvp.Key; var partitionFetchInfos = kvp.Value; ApiUtils.WriteShortString(buffer, topic); buffer.PutInt(partitionFetchInfos.Count); // partition count foreach (var pfi in partitionFetchInfos) { buffer.PutInt(pfi.Key.Partiton); buffer.PutLong(pfi.Value.Offset); buffer.PutInt(pfi.Value.FetchSize); } } }
public override void WriteTo(ByteBuffer buffer) { buffer.PutShort(this.VersionId); buffer.PutInt(this.CorrelationId); ApiUtils.WriteShortString(buffer, this.ClientId); buffer.PutInt(this.ReplicaId); buffer.PutInt(this.requestInfoGroupedByTopic.Value.Count); foreach (var topicAndPartitionInfos in this.requestInfoGroupedByTopic.Value) { var topic = topicAndPartitionInfos.Key; var partitionInfos = topicAndPartitionInfos.Value; ApiUtils.WriteShortString(buffer, topic); buffer.PutInt(partitionInfos.Count); // partition count foreach (var pi in partitionInfos) { var partition = pi.Key.Partiton; var partitionInfo = pi.Value; buffer.PutInt(partition); buffer.PutLong(partitionInfo.Time); buffer.PutInt(partitionInfo.MaxNumOffsets); } } }
public static int GetHeaderSize(string topic) { return(ApiUtils.ShortStringLength(topic) + 4 /* partition count */); }