MCPcopy Index your code
hub / github.com/cloudflare/ebpf_exporter / decodeLabels

Method decodeLabels

decoder/decoder.go:148–185  ·  view source on GitHub ↗

decodeLabels is the inner function of DecodeLabels without any caching

(in []byte, labels []config.Label)

Source from the content-addressed store, hash-verified

146
147// decodeLabels is the inner function of DecodeLabels without any caching
148func (s *Set) decodeLabels(in []byte, labels []config.Label) ([]string, error) {
149 values := make([]string, len(labels))
150
151 off := uint(0)
152
153 totalSize := uint(0)
154 for _, label := range labels {
155 size := label.Size
156 if size == 0 {
157 return nil, fmt.Errorf("error decoding label %q: size is zero or not set", label.Name)
158 }
159
160 totalSize += size + label.Padding
161 }
162
163 if totalSize != uint(len(in)) {
164 return nil, fmt.Errorf("error decoding labels: total size of key %#v is %d bytes, but we have labels to decode %d", in, len(in), totalSize)
165 }
166
167 for i, label := range labels {
168 if len(label.Decoders) == 0 {
169 return nil, fmt.Errorf("error decoding label %q: no decoders set", label.Name)
170 }
171
172 size := label.Size
173
174 decoded, err := s.decode(in[off:off+size], label)
175 if err != nil {
176 return nil, err
177 }
178
179 off += size + label.Padding
180
181 values[i] = string(decoded)
182 }
183
184 return values, nil
185}

Callers 3

BenchmarkCacheFunction · 0.95

Calls 1

decodeMethod · 0.95

Tested by 1

BenchmarkCacheFunction · 0.76