MCPcopy Create free account
hub / github.com/prometheus/common / NewDecoder

Function NewDecoder

expfmt/decode.go:83–95  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

81// Prometheus text format and is not intended for high-performance applications.
82// See: https://github.com/prometheus/common/issues/812
83func 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.
98type protoDecoder struct {

Callers 3

TestDottedEncodeFunction · 0.85

Calls 2

ToEscapingSchemeMethod · 0.80
FormatTypeMethod · 0.80

Tested by 3

TestDottedEncodeFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…