-
Notifications
You must be signed in to change notification settings - Fork 18
/
create_topics_response.go
64 lines (50 loc) · 1.36 KB
/
create_topics_response.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
package healer
import (
"encoding/binary"
"fmt"
)
// CreateTopicsResponse is response of create_topics request
type CreateTopicsResponse struct {
CorrelationID uint32
TopicErrors []TopicError
}
// TopicError is sub struct in CreateTopicsResponse
type TopicError struct {
Topic string
ErrorCode int16
}
func (r CreateTopicsResponse) Error() error {
for _, e := range r.TopicErrors {
if e.ErrorCode != 0 {
return KafkaError(e.ErrorCode)
}
}
return nil
}
// NewCreateTopicsResponse decode binary bytes to CreateTopicsResponse struct
func NewCreateTopicsResponse(payload []byte) (r CreateTopicsResponse, err error) {
var (
offset int
)
responseLength := int(binary.BigEndian.Uint32(payload))
if responseLength+4 != len(payload) {
return r, fmt.Errorf("create_topics response length did not match: %d!=%d", responseLength+4, len(payload))
}
offset += 4
r.CorrelationID = binary.BigEndian.Uint32(payload[offset:])
offset += 4
count := int32(binary.BigEndian.Uint32(payload[offset:]))
offset += 4
r.TopicErrors = make([]TopicError, count)
for i := range r.TopicErrors {
e := TopicError{}
l := int(int16(binary.BigEndian.Uint16(payload[offset:])))
offset += 2
e.Topic = string(payload[offset : offset+l])
offset += l
e.ErrorCode = int16(binary.BigEndian.Uint16(payload[offset:]))
offset += 2
r.TopicErrors[i] = e
}
return r, err
}