mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08: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
|
## master / unreleased
|
||||||
- [BUGFIX] Calling `Close` more than once on a querier returns an error instead of a panic.
|
- [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
|
## 0.7.1
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
package chunkenc
|
package chunkenc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -70,16 +71,18 @@ func (nopIterator) At() (int64, float64) { return 0, 0 }
|
||||||
func (nopIterator) Next() bool { return false }
|
func (nopIterator) Next() bool { return false }
|
||||||
func (nopIterator) Err() error { return nil }
|
func (nopIterator) Err() error { return nil }
|
||||||
|
|
||||||
|
// Pool is used to create and reuse chunk references to avoid allocations.
|
||||||
type Pool interface {
|
type Pool interface {
|
||||||
Put(Chunk) error
|
Put(Chunk) error
|
||||||
Get(e Encoding, b []byte) (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 {
|
type pool struct {
|
||||||
xor sync.Pool
|
xor sync.Pool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewPool returns a new pool.
|
||||||
func NewPool() Pool {
|
func NewPool() Pool {
|
||||||
return &pool{
|
return &pool{
|
||||||
xor: sync.Pool{
|
xor: sync.Pool{
|
||||||
|
@ -119,3 +122,14 @@ func (p *pool) Put(c Chunk) error {
|
||||||
}
|
}
|
||||||
return nil
|
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 a new issue