Decode implements the Decoder interface.
(v *dto.MetricFamily)
| 87 | |
| 88 | // Decode implements the Decoder interface. |
| 89 | func (d *protoDecoder) Decode(v *dto.MetricFamily) error { |
| 90 | opts := protodelim.UnmarshalOptions{ |
| 91 | MaxSize: -1, |
| 92 | } |
| 93 | if err := opts.UnmarshalFrom(bufio.NewReader(d.r), v); err != nil { |
| 94 | return err |
| 95 | } |
| 96 | if !model.IsValidMetricName(model.LabelValue(v.GetName())) { |
| 97 | return fmt.Errorf("invalid metric name %q", v.GetName()) |
| 98 | } |
| 99 | for _, m := range v.GetMetric() { |
| 100 | if m == nil { |
| 101 | continue |
| 102 | } |
| 103 | for _, l := range m.GetLabel() { |
| 104 | if l == nil { |
| 105 | continue |
| 106 | } |
| 107 | if !model.LabelValue(l.GetValue()).IsValid() { |
| 108 | return fmt.Errorf("invalid label value %q", l.GetValue()) |
| 109 | } |
| 110 | if !model.LabelName(l.GetName()).IsValid() { |
| 111 | return fmt.Errorf("invalid label name %q", l.GetName()) |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | return nil |
| 116 | } |
| 117 | |
| 118 | // textDecoder implements the Decoder interface for the text protocol. |
| 119 | type textDecoder struct { |
nothing calls this directly
no test coverage detected