public static MetadataResponse FromBytes(IRequestContext context, ArraySegment <byte> bytes)
        {
            using (var reader = new KafkaReader(bytes)) {
                var brokers = new Server[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 Server(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 Topic[reader.ReadInt32()];
                for (var t = 0; t < topics.Length; t++)
                {
                    var  topicError = (ErrorCode)reader.ReadInt16();
                    var  topicName  = reader.ReadString();
                    bool?isInternal = null;
                    if (context.ApiVersion >= 1)
                    {
                        isInternal = reader.ReadBoolean();
                    }

                    var partitions = new Partition[reader.ReadInt32()];
                    for (var p = 0; p < partitions.Length; p++)
                    {
                        var partitionError = (ErrorCode)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 Partition(partitionId, leaderId, partitionError, replicas, isrs);
                    }
                    topics[t] = new Topic(topicName, topicError, partitions, isInternal);
                }

                return(new MetadataResponse(brokers, topics, controllerId, clusterId));
            }
        }