Decode implements the Decoder interface.
(v *dto.MetricFamily)
| 142 | |
| 143 | // Decode implements the Decoder interface. |
| 144 | func (d *protoDecoder) Decode(v *dto.MetricFamily) error { |
| 145 | opts := protodelim.UnmarshalOptions{ |
| 146 | MaxSize: -1, |
| 147 | } |
| 148 | if err := opts.UnmarshalFrom(d.r, v); err != nil { |
| 149 | return err |
| 150 | } |
| 151 | if !d.s.IsValidMetricName(v.GetName()) { |
| 152 | return fmt.Errorf("invalid metric name %q", v.GetName()) |
| 153 | } |
| 154 | for _, m := range v.GetMetric() { |
| 155 | if m == nil { |
| 156 | continue |
| 157 | } |
| 158 | for _, l := range m.GetLabel() { |
| 159 | if l == nil { |
| 160 | continue |
| 161 | } |
| 162 | if !model.LabelValue(l.GetValue()).IsValid() { |
| 163 | return fmt.Errorf("invalid label value %q", l.GetValue()) |
| 164 | } |
| 165 | if !d.s.IsValidLabelName(l.GetName()) { |
| 166 | return fmt.Errorf("invalid label name %q", l.GetName()) |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | return nil |
| 171 | } |
| 172 | |
| 173 | // errDecoder is an error-state decoder that always returns the same error. |
| 174 | type errDecoder struct { |
nothing calls this directly
no test coverage detected