/// <summary> /// Write a size prefixed string where the size is stored as a 2 byte short /// </summary> /// <param name="buffer">The buffer to write to</param> /// <param name="string">The string to write</param> public static void WriteShortString(ByteBuffer buffer, string @string) { if (@string == null) { buffer.PutShort(-1); } else { var encodedString = Encoding.UTF8.GetBytes(@string); if (encodedString.Length > short.MaxValue) { throw new KafkaException(string.Format("String exceeds the maximum size of {0}", short.MaxValue)); } buffer.PutShort((short)encodedString.Length); buffer.Write(encodedString, 0, encodedString.Length); } }
public override void WriteTo(ByteBuffer buffer) { buffer.PutShort(this.VersionId); buffer.PutInt(this.CorrelationId); ApiUtils.WriteShortString(buffer, this.ClientId); buffer.PutInt(this.Topics.Count); foreach (var topic in this.Topics) { ApiUtils.WriteShortString(buffer, topic); } }
public void WriteTo(ByteBuffer buffer) { /* error code */ buffer.PutShort(this.ErrorCode); /* topic */ ApiUtils.WriteShortString(buffer, this.Topic); /* number of partitions */ buffer.PutInt(this.PartitionsMetadata.Count()); foreach (var m in this.PartitionsMetadata) { m.WriteTo(buffer); } }
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 void WriteTo(ByteBuffer buffer) { buffer.PutShort(this.ErrorCode); buffer.PutInt(this.PartitionId); // leader var leaderId = (this.Leader != null) ? this.Leader.Id : TopicMetadata.NoLeaderNodeId; buffer.PutInt(leaderId); /* number of replicas */ buffer.PutInt(this.Replicas.Count()); foreach (var replica in this.Replicas) { buffer.PutInt(replica.Id); } /* number of in-sync replicas */ buffer.PutInt(this.Isr.Count()); foreach (var r in this.Isr) { buffer.PutInt(r.Id); } }
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.PutShort(this.RequiredAcks); buffer.PutInt(this.AckTimeoutMs); // save the topic structure buffer.PutInt(this.dataGroupedByTopic.Value.Count); // the number of topics foreach (var kvp in this.dataGroupedByTopic.Value) { var topic = kvp.Key; var topicAndPartitonData = kvp.Value; ApiUtils.WriteShortString(buffer, topic); // write the topic buffer.PutInt(topicAndPartitonData.Count); foreach (var partitionAndData in topicAndPartitonData) { var partition = partitionAndData.Key.Partiton; var partitionMessageData = partitionAndData.Value; var bytes = partitionMessageData.Buffer; buffer.PutInt(partition); buffer.PutInt((int)bytes.Length); buffer.Put(bytes); bytes.Position = 0; } } }
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 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); } } } }