private IEnumerable <ProduceResponse> DecodeProduceResponse(byte[] data) { var stream = new ReadByteStream(data); var correlationId = stream.ReadInt(); var topicCount = stream.ReadInt(); for (int i = 0; i < topicCount; i++) { var topic = stream.ReadInt16String(); var partitionCount = stream.ReadInt(); for (int j = 0; j < partitionCount; j++) { var response = new ProduceResponse() { Topic = topic, PartitionId = stream.ReadInt(), Error = stream.ReadInt16(), Offset = stream.ReadLong() }; yield return(response); } } }
private IEnumerable <OffsetResponse> DecodeOffsetResponse(byte[] data) { var stream = new ReadByteStream(data); var correlationId = stream.ReadInt(); var topicCount = stream.ReadInt(); for (int i = 0; i < topicCount; i++) { var topic = stream.ReadInt16String(); var partitionCount = stream.ReadInt(); for (int j = 0; j < partitionCount; j++) { var response = new OffsetResponse() { Topic = topic, PartitionId = stream.ReadInt(), Error = stream.ReadInt16(), Offsets = new List <long>() }; var offsetCount = stream.ReadInt(); for (int k = 0; k < offsetCount; k++) { response.Offsets.Add(stream.ReadLong()); } yield return(response); } } }
public static Partition FromStream(ReadByteStream stream) { var partition = new Partition { ErrorCode = stream.ReadInt16(), PartitionId = stream.ReadInt(), LeaderId = stream.ReadInt(), Replicas = new List <int>(), Isrs = new List <int>() }; var numReplicas = stream.ReadInt(); for (int i = 0; i < numReplicas; i++) { partition.Replicas.Add(stream.ReadInt()); } var numIsr = stream.ReadInt(); for (int i = 0; i < numIsr; i++) { partition.Isrs.Add(stream.ReadInt()); } return(partition); }
private IEnumerable <FetchResponse> DecodeFetchResponse(byte[] data) { var stream = new ReadByteStream(data); var correlationId = stream.ReadInt(); var topicCount = stream.ReadInt(); for (int i = 0; i < topicCount; i++) { var topic = stream.ReadInt16String(); var partitionCount = stream.ReadInt(); for (int j = 0; j < partitionCount; j++) { var partitionId = stream.ReadInt(); var response = new FetchResponse { Topic = topic, PartitionId = partitionId, Error = stream.ReadInt16(), HighWaterMark = stream.ReadLong() }; //note: dont use initializer here as it breaks stream position. response.Messages = Message.DecodeMessageSet(stream.ReadIntPrefixedBytes()) .Select(x => { x.Meta.PartitionId = partitionId; return(x); }); yield return(response); } } }
private IEnumerable <ConsumerMetadataResponse> DecodeConsumerMetadataResponse(byte[] data) { var stream = new ReadByteStream(data); var correlationId = stream.ReadInt(); var response = new ConsumerMetadataResponse { Error = stream.ReadInt16(), CoordinatorId = stream.ReadInt(), CoordinatorHost = stream.ReadInt16String(), CoordinatorPort = stream.ReadInt() }; yield return(response); }
public static Topic FromStream(ReadByteStream stream) { var topic = new Topic { ErrorCode = stream.ReadInt16(), Name = stream.ReadInt16String(), Partitions = new List <Partition>() }; var numPartitions = stream.ReadInt(); for (int i = 0; i < numPartitions; i++) { topic.Partitions.Add(Partition.FromStream(stream)); } return(topic); }