forked from couchbase/gocbcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collections.go
140 lines (119 loc) · 3.47 KB
/
collections.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package gocbcore
import (
"encoding/json"
"strconv"
"time"
)
const (
unknownCid = uint32(0xFFFFFFFF)
pendingCid = uint32(0xFFFFFFFE)
)
// ManifestCollection is the representation of a collection within a manifest.
type ManifestCollection struct {
UID uint32
Name string
MaxTTL uint32
}
// UnmarshalJSON is a custom implementation of json unmarshaling.
func (item *ManifestCollection) UnmarshalJSON(data []byte) error {
decData := struct {
UID string `json:"uid"`
Name string `json:"name"`
MaxTTL uint32 `json:"maxTTL"`
}{}
if err := json.Unmarshal(data, &decData); err != nil {
return err
}
decUID, err := strconv.ParseUint(decData.UID, 16, 32)
if err != nil {
return err
}
item.UID = uint32(decUID)
item.Name = decData.Name
item.MaxTTL = decData.MaxTTL
return nil
}
// ManifestScope is the representation of a scope within a manifest.
type ManifestScope struct {
UID uint32
Name string
Collections []ManifestCollection
}
// UnmarshalJSON is a custom implementation of json unmarshaling.
func (item *ManifestScope) UnmarshalJSON(data []byte) error {
decData := struct {
UID string `json:"uid"`
Name string `json:"name"`
Collections []ManifestCollection `json:"collections"`
}{}
if err := json.Unmarshal(data, &decData); err != nil {
return err
}
decUID, err := strconv.ParseUint(decData.UID, 16, 32)
if err != nil {
return err
}
item.UID = uint32(decUID)
item.Name = decData.Name
item.Collections = decData.Collections
return nil
}
// Manifest is the representation of a collections manifest.
type Manifest struct {
UID uint64
Scopes []ManifestScope
}
// UnmarshalJSON is a custom implementation of json unmarshaling.
func (item *Manifest) UnmarshalJSON(data []byte) error {
decData := struct {
UID string `json:"uid"`
Scopes []ManifestScope `json:"scopes"`
}{}
if err := json.Unmarshal(data, &decData); err != nil {
return err
}
decUID, err := strconv.ParseUint(decData.UID, 16, 64)
if err != nil {
return err
}
item.UID = decUID
item.Scopes = decData.Scopes
return nil
}
// GetCollectionManifestOptions are the options available to the GetCollectionManifest command.
type GetCollectionManifestOptions struct {
TraceContext RequestSpanContext
RetryStrategy RetryStrategy
Deadline time.Time
}
// GetAllCollectionManifestsOptions are the options available to the GetAllCollectionManifests command.
type GetAllCollectionManifestsOptions struct {
TraceContext RequestSpanContext
RetryStrategy RetryStrategy
Deadline time.Time
}
// GetCollectionIDOptions are the options available to the GetCollectionID command.
type GetCollectionIDOptions struct {
RetryStrategy RetryStrategy
TraceContext RequestSpanContext
Deadline time.Time
}
// GetCollectionIDResult encapsulates the result of a GetCollectionID operation.
type GetCollectionIDResult struct {
ManifestID uint64
CollectionID uint32
}
// GetCollectionManifestResult encapsulates the result of a GetCollectionManifest operation.
type GetCollectionManifestResult struct {
Manifest []byte
}
// SingleServerManifestResult encapsulates the result from a single server when using the GetAllCollectionManifests
// operation.
type SingleServerManifestResult struct {
Manifest []byte
Error error
}
// GetAllCollectionManifestsResult encapsulates the result of a GetAllCollectionManifests operation.
type GetAllCollectionManifestsResult struct {
Manifests map[string]SingleServerManifestResult
}