forked from coreos/torus
/
blockset.go
50 lines (43 loc) · 1.12 KB
/
blockset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package torus
import (
"github.com/RoaringBitmap/roaring"
"github.com/coreos/torus/models"
"golang.org/x/net/context"
)
// Blockset is the interface representing the standardized methods to interact
// with a set of blocks.
type Blockset interface {
Length() int
Kind() uint32
GetBlock(ctx context.Context, i int) ([]byte, error)
PutBlock(ctx context.Context, inode INodeRef, i int, b []byte) error
GetLiveINodes() *roaring.Bitmap
GetAllBlockRefs() []BlockRef
Marshal() ([]byte, error)
Unmarshal(data []byte) error
GetSubBlockset() Blockset
Truncate(lastIndex int, blocksize uint64) error
Trim(from, to int) error
String() string
}
type BlockLayerKind int
type BlockLayer struct {
Kind BlockLayerKind
Options string
}
type BlockLayerSpec []BlockLayer
func MarshalBlocksetToProto(bs Blockset) ([]*models.BlockLayer, error) {
var out []*models.BlockLayer
var layer Blockset
for layer = bs; layer != nil; layer = layer.GetSubBlockset() {
m, err := layer.Marshal()
if err != nil {
return nil, err
}
out = append(out, &models.BlockLayer{
Type: layer.Kind(),
Content: m,
})
}
return out, nil
}