forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listoffset.go
105 lines (85 loc) · 2.58 KB
/
listoffset.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
package kafka
import "bufio"
type listOffsetRequestV1 struct {
ReplicaID int32
Topics []listOffsetRequestTopicV1
}
func (r listOffsetRequestV1) size() int32 {
return 4 + sizeofArray(len(r.Topics), func(i int) int32 { return r.Topics[i].size() })
}
func (r listOffsetRequestV1) writeTo(wb *writeBuffer) {
wb.writeInt32(r.ReplicaID)
wb.writeArray(len(r.Topics), func(i int) { r.Topics[i].writeTo(wb) })
}
type listOffsetRequestTopicV1 struct {
TopicName string
Partitions []listOffsetRequestPartitionV1
}
func (t listOffsetRequestTopicV1) size() int32 {
return sizeofString(t.TopicName) +
sizeofArray(len(t.Partitions), func(i int) int32 { return t.Partitions[i].size() })
}
func (t listOffsetRequestTopicV1) writeTo(wb *writeBuffer) {
wb.writeString(t.TopicName)
wb.writeArray(len(t.Partitions), func(i int) { t.Partitions[i].writeTo(wb) })
}
type listOffsetRequestPartitionV1 struct {
Partition int32
Time int64
}
func (p listOffsetRequestPartitionV1) size() int32 {
return 4 + 8
}
func (p listOffsetRequestPartitionV1) writeTo(wb *writeBuffer) {
wb.writeInt32(p.Partition)
wb.writeInt64(p.Time)
}
type listOffsetResponseV1 []listOffsetResponseTopicV1
func (r listOffsetResponseV1) size() int32 {
return sizeofArray(len(r), func(i int) int32 { return r[i].size() })
}
func (r listOffsetResponseV1) writeTo(wb *writeBuffer) {
wb.writeArray(len(r), func(i int) { r[i].writeTo(wb) })
}
type listOffsetResponseTopicV1 struct {
TopicName string
PartitionOffsets []partitionOffsetV1
}
func (t listOffsetResponseTopicV1) size() int32 {
return sizeofString(t.TopicName) +
sizeofArray(len(t.PartitionOffsets), func(i int) int32 { return t.PartitionOffsets[i].size() })
}
func (t listOffsetResponseTopicV1) writeTo(wb *writeBuffer) {
wb.writeString(t.TopicName)
wb.writeArray(len(t.PartitionOffsets), func(i int) { t.PartitionOffsets[i].writeTo(wb) })
}
type partitionOffsetV1 struct {
Partition int32
ErrorCode int16
Timestamp int64
Offset int64
}
func (p partitionOffsetV1) size() int32 {
return 4 + 2 + 8 + 8
}
func (p partitionOffsetV1) writeTo(wb *writeBuffer) {
wb.writeInt32(p.Partition)
wb.writeInt16(p.ErrorCode)
wb.writeInt64(p.Timestamp)
wb.writeInt64(p.Offset)
}
func (p *partitionOffsetV1) readFrom(r *bufio.Reader, sz int) (remain int, err error) {
if remain, err = readInt32(r, sz, &p.Partition); err != nil {
return
}
if remain, err = readInt16(r, remain, &p.ErrorCode); err != nil {
return
}
if remain, err = readInt64(r, remain, &p.Timestamp); err != nil {
return
}
if remain, err = readInt64(r, remain, &p.Offset); err != nil {
return
}
return
}