-
Notifications
You must be signed in to change notification settings - Fork 5
/
namespace.go
46 lines (41 loc) · 972 Bytes
/
namespace.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
package choices
import (
"github.com/Nordstrom/choices/util"
"github.com/foolusion/elwinprotos/storage"
)
type Namespace struct {
Name string
NumSegments int
Segments *segments
}
func (n *Namespace) ToNamespace(ns *storage.Namespace) *storage.Namespace {
if ns == nil {
ns = new(storage.Namespace)
}
ns.Name = n.Name
ns.NumSegments = int64(n.NumSegments)
if ns.Segments == nil {
ns.Segments = new(storage.Segments)
}
ns.Segments.B = n.Segments.b
ns.Segments.Len = int64(n.Segments.len)
return ns
}
const defaultNumSegments = 128
func newNamespace(name string, numSegments int) *Namespace {
if name == "" {
name = util.BasicNameGenerator.GenerateName("ns-")
}
if numSegments <= 0 {
numSegments = defaultNumSegments
}
numBytes := numSegments / 8
if numSegments%8 != 0 {
numBytes++
}
return &Namespace{
Name: name,
NumSegments: numSegments,
Segments: &segments{b: make([]byte, numBytes), len: numSegments},
}
}