MCPcopy Index your code
hub / github.com/prometheus/prometheus / Decode

Function Decode

util/compression/compression.go:93–122  ·  view source on GitHub ↗

Decode returns the decoded form of src for the given compression type. The buf allows passing various buffer implementations that make decoding more efficient. See NewSyncDecodeBuffer and NewConcurrentDecodeBuffer for further details. For non-zstd compression types, it is valid to pass nil buf. De

(t Type, src []byte, buf DecodeBuffer)

Source from the content-addressed store, hash-verified

91// Decode is concurrency-safe, however note the concurrency limits for the
92// buffer of your choice.
93func Decode(t Type, src []byte, buf DecodeBuffer) (ret []byte, err error) {
94 if len(src) == 0 || t == "" || t == None {
95 return src, nil
96 }
97 if t == Snappy {
98 var b []byte
99 if buf != nil {
100 b = buf.get()
101 defer func() {
102 buf.set(ret)
103 }()
104 }
105 // The snappy library uses `len` to calculate if we need a new buffer.
106 // In order to allocate as few buffers as possible make the length
107 // equal to the capacity.
108 b = b[:cap(b)]
109 return snappy.Decode(b, src)
110 }
111 if t == Zstd {
112 if buf == nil {
113 return nil, errors.New("zstd requested but DecodeBuffer was not provided")
114 }
115 b := buf.get()
116 defer func() {
117 buf.set(ret)
118 }()
119 return buf.zstdDecBuf().DecodeAll(src, b[:0])
120 }
121 return nil, fmt.Errorf("unsupported compression type: %s", t)
122}

Callers 5

buildRecordMethod · 0.92
nextNewMethod · 0.92
StoreMethod · 0.92
TestEncodeDecodeFunction · 0.70
BenchmarkDecodeFunction · 0.70

Calls 4

DecodeMethod · 0.80
getMethod · 0.65
setMethod · 0.65
zstdDecBufMethod · 0.65

Tested by 3

StoreMethod · 0.74
TestEncodeDecodeFunction · 0.56
BenchmarkDecodeFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…