mirror of
https://github.com/prometheus/prometheus
synced 2024-12-29 18:22:16 +00:00
Add FromData function (again)! (#600)
Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>
This commit is contained in:
parent
4da65c46c9
commit
2ae028114c
@ -1,5 +1,6 @@
|
||||
## master / unreleased
|
||||
- [BUGFIX] Calling `Close` more than once on a querier returns an error instead of a panic.
|
||||
- [ENHANCEMENT] Add (again) FromData function to easily create a chunk from bytes.
|
||||
|
||||
|
||||
## 0.7.1
|
||||
|
@ -14,6 +14,7 @@
|
||||
package chunkenc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@ -70,16 +71,18 @@ func (nopIterator) At() (int64, float64) { return 0, 0 }
|
||||
func (nopIterator) Next() bool { return false }
|
||||
func (nopIterator) Err() error { return nil }
|
||||
|
||||
// Pool is used to create and reuse chunk references to avoid allocations.
|
||||
type Pool interface {
|
||||
Put(Chunk) error
|
||||
Get(e Encoding, b []byte) (Chunk, error)
|
||||
}
|
||||
|
||||
// Pool is a memory pool of chunk objects.
|
||||
// pool is a memory pool of chunk objects.
|
||||
type pool struct {
|
||||
xor sync.Pool
|
||||
}
|
||||
|
||||
// NewPool returns a new pool.
|
||||
func NewPool() Pool {
|
||||
return &pool{
|
||||
xor: sync.Pool{
|
||||
@ -119,3 +122,14 @@ func (p *pool) Put(c Chunk) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FromData returns a chunk from a byte slice of chunk data.
|
||||
// This is there so that users of the library can easily create chunks from
|
||||
// bytes.
|
||||
func FromData(e Encoding, d []byte) (Chunk, error) {
|
||||
switch e {
|
||||
case EncXOR:
|
||||
return &XORChunk{b: bstream{count: 0, stream: d}}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("unknown chunk encoding: %d", e)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user