forked from samuel/go-zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 129
/
create_mode.go
49 lines (45 loc) · 1.48 KB
/
create_mode.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
package zk
import "fmt"
// TODO: (v2) enum type for CreateMode API.
const (
FlagPersistent = 0
FlagEphemeral = 1
FlagSequence = 2
FlagEphemeralSequential = 3
FlagContainer = 4
FlagTTL = 5
FlagPersistentSequentialWithTTL = 6
)
type createMode struct {
flag int32
isEphemeral bool
isSequential bool
isContainer bool
isTTL bool
}
// parsing a flag integer into the CreateMode needed to call the correct
// Create RPC to Zookeeper.
//
// NOTE: This parse method is designed to be able to copy and paste the same
// CreateMode ENUM constructors from Java:
// https://github.com/apache/zookeeper/blob/master/zookeeper-server/src/main/java/org/apache/zookeeper/CreateMode.java
func parseCreateMode(flag int32) (createMode, error) {
switch flag {
case FlagPersistent:
return createMode{0, false, false, false, false}, nil
case FlagEphemeral:
return createMode{1, true, false, false, false}, nil
case FlagSequence:
return createMode{2, false, true, false, false}, nil
case FlagEphemeralSequential:
return createMode{3, true, true, false, false}, nil
case FlagContainer:
return createMode{4, false, false, true, false}, nil
case FlagTTL:
return createMode{5, false, false, false, true}, nil
case FlagPersistentSequentialWithTTL:
return createMode{6, false, true, false, true}, nil
default:
return createMode{}, fmt.Errorf("invalid flag value: [%v]", flag)
}
}