public static OffsetsResponse FromBytes(IRequestContext context, ArraySegment <byte> bytes) { using (var reader = new KafkaReader(bytes)) { var topics = new List <Topic>(); var topicCount = reader.ReadInt32(); for (var t = 0; t < topicCount; t++) { var topicName = reader.ReadString(); var partitionCount = reader.ReadInt32(); for (var p = 0; p < partitionCount; p++) { var partitionId = reader.ReadInt32(); var errorCode = (ErrorCode)reader.ReadInt16(); if (context.ApiVersion == 0) { var offsetsCount = reader.ReadInt32(); for (var o = 0; o < offsetsCount; o++) { var offset = reader.ReadInt64(); topics.Add(new Topic(topicName, partitionId, errorCode, offset)); } } else { var timestamp = reader.ReadInt64(); var offset = reader.ReadInt64(); topics.Add(new Topic(topicName, partitionId, errorCode, offset, DateTimeOffset.FromUnixTimeMilliseconds(timestamp))); } } } return(new OffsetsResponse(topics)); } }
public static FetchResponse FromBytes(IRequestContext context, ArraySegment <byte> bytes) { using (var reader = new KafkaReader(bytes)) { TimeSpan?throttleTime = null; if (context.ApiVersion >= 1) { throttleTime = TimeSpan.FromMilliseconds(reader.ReadInt32()); } var topics = new List <FetchResponse.Topic>(); var topicCount = reader.ReadInt32(); for (var t = 0; t < topicCount; t++) { var topicName = reader.ReadString(); var partitionCount = reader.ReadInt32(); for (var p = 0; p < partitionCount; p++) { var partitionId = reader.ReadInt32(); var errorCode = (ErrorCode)reader.ReadInt16(); var highWaterMarkOffset = reader.ReadInt64(); var messages = reader.ReadMessages(); topics.Add(new Topic(topicName, partitionId, highWaterMarkOffset, errorCode, messages)); } } return(new FetchResponse(topics, throttleTime)); } }
public static ProduceResponse FromBytes(IRequestContext context, ArraySegment <byte> bytes) { using (var reader = new KafkaReader(bytes)) { TimeSpan?throttleTime = null; var topics = new List <Topic>(); var topicCount = reader.ReadInt32(); for (var i = 0; i < topicCount; i++) { var topicName = reader.ReadString(); var partitionCount = reader.ReadInt32(); for (var j = 0; j < partitionCount; j++) { var partitionId = reader.ReadInt32(); var errorCode = (ErrorCode)reader.ReadInt16(); var offset = reader.ReadInt64(); DateTimeOffset?timestamp = null; if (context.ApiVersion >= 2) { var milliseconds = reader.ReadInt64(); if (milliseconds >= 0) { timestamp = DateTimeOffset.FromUnixTimeMilliseconds(milliseconds); } } topics.Add(new Topic(topicName, partitionId, errorCode, offset, timestamp)); } } if (context.ApiVersion >= 1) { throttleTime = TimeSpan.FromMilliseconds(reader.ReadInt32()); } return(new ProduceResponse(topics, throttleTime)); } }
public static OffsetFetchResponse FromBytes(IRequestContext context, ArraySegment <byte> bytes) { using (var reader = new KafkaReader(bytes)) { var topics = new List <Topic>(); var topicCount = reader.ReadInt32(); for (var t = 0; t < topicCount; t++) { var topicName = reader.ReadString(); var partitionCount = reader.ReadInt32(); for (var p = 0; p < partitionCount; p++) { var partitionId = reader.ReadInt32(); var offset = reader.ReadInt64(); var metadata = reader.ReadString(); var errorCode = (ErrorCode)reader.ReadInt16(); topics.Add(new Topic(topicName, partitionId, errorCode, offset, metadata)); } } return(new OffsetFetchResponse(topics)); } }