-
Notifications
You must be signed in to change notification settings - Fork 18
/
findcoordinator_request.go
58 lines (43 loc) · 1.43 KB
/
findcoordinator_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
package healer
import (
"encoding/binary"
)
/*
FindCoordinator Request (Version: 0) => group_id
group_id => STRING
FIELD DESCRIPTION
group_id The unique group id.
FindCoordinator Request (Version: 1) => coordinator_key coordinator_type
coordinator_key => STRING
coordinator_type => INT8
FIELD DESCRIPTION
coordinator_key Id to use for finding the coordinator (for groups, this is the groupId, for transactional producers, this is the transactional id)
coordinator_type The type of coordinator to find (0 = group, 1 = transaction)
*/
type FindCoordinatorRequest struct {
*RequestHeader
GroupID string
}
func NewFindCoordinatorRequest(clientID, groupID string) *FindCoordinatorRequest {
requestHeader := &RequestHeader{
APIKey: API_FindCoordinator,
APIVersion: 0,
ClientID: &clientID,
}
return &FindCoordinatorRequest{
RequestHeader: requestHeader,
GroupID: groupID,
}
}
func (findCoordinatorR *FindCoordinatorRequest) Encode(version uint16) []byte {
requestLength := findCoordinatorR.RequestHeader.length() + 2 + len(findCoordinatorR.GroupID)
payload := make([]byte, requestLength+4)
offset := 0
binary.BigEndian.PutUint32(payload[offset:], uint32(requestLength))
offset += 4
offset += findCoordinatorR.RequestHeader.EncodeTo(payload[offset:])
binary.BigEndian.PutUint16(payload[offset:], uint16(len(findCoordinatorR.GroupID)))
offset += 2
copy(payload[offset:], findCoordinatorR.GroupID)
return payload
}