ebpf_exporter
25 строк · 565.0 Байт
1package decoder
2
3import (
4"github.com/cloudflare/ebpf_exporter/v2/config"
5)
6
7// String is a decoder that decodes strings coming from the kernel
8type String struct{}
9
10// Decode transforms byte slice from the kernel into string
11func (s *String) Decode(in []byte, _ config.Decoder) ([]byte, error) {
12return in[0:clen(in)], nil
13}
14
15// clen returns position of the fist null byte in a byte slice or byte slice
16// length if there is no null byte in the slice
17func clen(n []byte) int {
18for i := 0; i < len(n); i++ {
19if n[i] == 0 {
20return i
21}
22}
23
24return len(n)
25}
26