-
Notifications
You must be signed in to change notification settings - Fork 18
/
describe_acls_request.go
121 lines (96 loc) · 2.56 KB
/
describe_acls_request.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
package healer
import (
"bytes"
"encoding/binary"
)
type DescribeAclsRequest struct {
RequestHeader
DescribeAclsRequestBody
}
type DescribeAclsRequestBody struct {
ResourceType AclsResourceType
ResourceName *string
PatternType AclsPatternType
Principal *string
Host *string
Operation AclsOperation
PermissionType AclsPermissionType
TaggedFields TaggedFields
}
func (r *DescribeAclsRequest) Encode(version uint16) (rst []byte) {
buf := new(bytes.Buffer)
// length
binary.Write(buf, binary.BigEndian, uint32(0))
defer func() {
length := len(rst) - 4
binary.BigEndian.PutUint32(rst, uint32(length))
}()
header := make([]byte, r.RequestHeader.length())
l := r.RequestHeader.EncodeTo(header)
buf.Write(header[:l])
binary.Write(buf, binary.BigEndian, r.ResourceType)
if version < 2 {
writeNullableString(buf, r.ResourceName)
} else {
writeCompactNullableString(buf, r.ResourceName)
}
if version >= 1 {
binary.Write(buf, binary.BigEndian, r.PatternType)
}
if version < 2 {
writeNullableString(buf, r.Principal)
writeNullableString(buf, r.Host)
} else {
writeCompactNullableString(buf, r.Principal)
writeCompactNullableString(buf, r.Host)
}
binary.Write(buf, binary.BigEndian, r.Operation)
binary.Write(buf, binary.BigEndian, r.PermissionType)
buf.Write(r.DescribeAclsRequestBody.TaggedFields.Encode())
return buf.Bytes()
}
// just for test
func DecodeDescribeAclsRequest(payload []byte, version uint16) (r DescribeAclsRequest, err error) {
offset := 0
// request payload length
binary.BigEndian.Uint32(payload)
offset += 4
header, o := DecodeRequestHeader(payload[offset:])
r.RequestHeader = header
offset += o
r.ResourceType = AclsResourceType(payload[offset])
offset++
if version < 2 {
resourceName, o := nullableString(payload[offset:])
offset += o
r.ResourceName = resourceName
} else {
resourceName, o := compactNullableString(payload[offset:])
offset += o
r.ResourceName = resourceName
}
if version >= 1 {
r.PatternType = AclsPatternType(payload[offset])
offset++
}
if version < 2 {
principal, o := nullableString(payload[offset:])
offset += o
r.Principal = principal
host, o := nullableString(payload[offset:])
offset += o
r.Host = host
} else {
principal, o := compactNullableString(payload[offset:])
offset += o
r.Principal = principal
host, o := compactNullableString(payload[offset:])
offset += o
r.Host = host
}
r.Operation = AclsOperation(payload[offset])
offset++
r.PermissionType = AclsPermissionType(payload[offset])
offset++
return r, nil
}