NewDecoder returns a new decoder based on the given input format. Metric names are validated based on the provided Format -- if the format requires escaping, raditional Prometheues validity checking is used. Otherwise, names are checked for UTF-8 validity. Supported formats include delimited protobu
(r io.Reader, format Format)
| 81 | // Prometheus text format and is not intended for high-performance applications. |
| 82 | // See: https://github.com/prometheus/common/issues/812 |
| 83 | func NewDecoder(r io.Reader, format Format) Decoder { |
| 84 | scheme := model.LegacyValidation |
| 85 | if format.ToEscapingScheme() == model.NoEscaping { |
| 86 | scheme = model.UTF8Validation |
| 87 | } |
| 88 | switch format.FormatType() { |
| 89 | case TypeProtoDelim: |
| 90 | return &protoDecoder{r: bufio.NewReader(r), s: scheme} |
| 91 | case TypeProtoText, TypeProtoCompact: |
| 92 | return &errDecoder{err: fmt.Errorf("format %s not supported for decoding", format)} |
| 93 | } |
| 94 | return &textDecoder{r: r, s: scheme} |
| 95 | } |
| 96 | |
| 97 | // protoDecoder implements the Decoder interface for protocol buffers. |
| 98 | type protoDecoder struct { |
searching dependent graphs…