forked from travisjeffery/jocko
/
produce_response.go
87 lines (80 loc) · 1.67 KB
/
produce_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package protocol
type ProducePartitionResponse struct {
Partition int32
ErrorCode int16
BaseOffset int64
Timestamp int64
}
type ProduceResponse struct {
Topic string
PartitionResponses []*ProducePartitionResponse
}
type ProduceResponses struct {
Responses []*ProduceResponse
ThrottleTimeMs int32
}
func (r *ProduceResponses) Encode(e PacketEncoder) error {
e.PutArrayLength(len(r.Responses))
for _, r := range r.Responses {
e.PutString(r.Topic)
e.PutArrayLength(len(r.PartitionResponses))
for _, p := range r.PartitionResponses {
e.PutInt32(p.Partition)
e.PutInt16(p.ErrorCode)
e.PutInt64(p.BaseOffset)
e.PutInt64(p.Timestamp)
}
}
e.PutInt32(r.ThrottleTimeMs)
return nil
}
func (r *ProduceResponses) Decode(d PacketDecoder) error {
var err error
l, err := d.ArrayLength()
if err != nil {
return err
}
r.Responses = make([]*ProduceResponse, l)
for i := range r.Responses {
resp := new(ProduceResponse)
r.Responses[i] = resp
resp.Topic, err = d.String()
if err != nil {
return err
}
pl, err := d.ArrayLength()
if err != nil {
return err
}
ps := make([]*ProducePartitionResponse, pl)
for j := range ps {
p := new(ProducePartitionResponse)
ps[j] = p
p.Partition, err = d.Int32()
if err != nil {
return err
}
p.ErrorCode, err = d.Int16()
if err != nil {
return err
}
p.BaseOffset, err = d.Int64()
if err != nil {
return err
}
p.Timestamp, err = d.Int64()
if err != nil {
return err
}
}
resp.PartitionResponses = ps
}
r.ThrottleTimeMs, err = d.Int32()
if err != nil {
return err
}
return nil
}
func (r *ProduceResponses) Version() int16 {
return 2
}