'Gets the output data from a prometheus endpoint response along with its
Content-type header and parses it into Prometheus classes (see [0])
Parse the binary buffer in input, searching for Prometheus messages
of type MetricFamily [0] delimited by a varint32 [1] when the
content-type is a `application/vnd.google.protobuf`.
[0] https://github.com/prometheus/client_model/blob/086fe7ca28bde6cec2acd5223423c1475a362858/metrics.proto#L76-%20%20L81
[1] https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/AbstractMessageLite#writeDelimitedTo(java.io.OutputStream)'

def parse_metric_family(self, buf, content_type):

    if ('application/vnd.google.protobuf' in content_type):
        n = 0
        while (n < len(buf)):
            (msg_len, new_pos) = _DecodeVarint32(buf, n)
            n = new_pos
            msg_buf = buf[n:(n + msg_len)]
            n += msg_len
            message = metrics_pb2.MetricFamily()
            message.ParseFromString(msg_buf)
            (yield message)
    elif ('text/plain' in content_type):
        messages = {}
        obj_map = {}
        obj_help = {}
        for line in buf.splitlines():
            self._extract_metrics_from_string(line, messages, obj_map, obj_help)
        for _m in obj_map:
            if ((_m in messages) or ((obj_map[_m] == 'histogram') and ('{}_bucket'.format(_m) in messages))):
                (yield self._extract_metric_from_map(_m, messages, obj_map, obj_help))
    else:
        raise self.UnknownFormatError('Unsupported    content-type    provided:    {}'.format(content_type))
