private static MetadataResult ValidateTopic(MetadataResponse.Topic topic) { var errorCode = topic.topic_error_code; if (errorCode.IsSuccess()) { return(new MetadataResult(isValid: true)); } if (errorCode.IsRetryable()) { return(new MetadataResult(errorCode, null, $"topic {topic.topic} returned error code of {errorCode}: Retrying")); } return(new MetadataResult(errorCode, false, $"topic {topic.topic} returned an error of {errorCode}")); }
private static IResponse MetadataResponse(IRequestContext context, byte[] payload, bool hasSize) { using (var reader = new BigEndianBinaryReader(payload, hasSize ? 8 : 4)) { var brokers = new Broker[reader.ReadInt32()]; for (var b = 0; b < brokers.Length; b++) { var brokerId = reader.ReadInt32(); var host = reader.ReadString(); var port = reader.ReadInt32(); string rack = null; if (context.ApiVersion >= 1) { rack = reader.ReadString(); } brokers[b] = new Broker(brokerId, host, port, rack); } string clusterId = null; if (context.ApiVersion >= 2) { clusterId = reader.ReadString(); } int?controllerId = null; if (context.ApiVersion >= 1) { controllerId = reader.ReadInt32(); } var topics = new MetadataResponse.Topic[reader.ReadInt32()]; for (var t = 0; t < topics.Length; t++) { var topicError = (ErrorResponseCode)reader.ReadInt16(); var topicName = reader.ReadString(); bool?isInternal = null; if (context.ApiVersion >= 1) { isInternal = reader.ReadBoolean(); } var partitions = new MetadataResponse.Partition[reader.ReadInt32()]; for (var p = 0; p < partitions.Length; p++) { var partitionError = (ErrorResponseCode)reader.ReadInt16(); var partitionId = reader.ReadInt32(); var leaderId = reader.ReadInt32(); var replicaCount = reader.ReadInt32(); var replicas = replicaCount.Repeat(reader.ReadInt32).ToArray(); var isrCount = reader.ReadInt32(); var isrs = isrCount.Repeat(reader.ReadInt32).ToArray(); partitions[p] = new MetadataResponse.Partition(partitionId, leaderId, partitionError, replicas, isrs); } topics[t] = new MetadataResponse.Topic(topicName, topicError, partitions, isInternal); } return(new MetadataResponse(brokers, topics, controllerId, clusterId)); } }