forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.go
101 lines (82 loc) · 2.49 KB
/
fetch.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
package kafka
import "bufio"
type fetchRequestV1 struct {
ReplicaID int32
MaxWaitTime int32
MinBytes int32
Topics []fetchRequestTopicV1
}
func (r fetchRequestV1) size() int32 {
return 4 + 4 + 4 + sizeofArray(len(r.Topics), func(i int) int32 { return r.Topics[i].size() })
}
func (r fetchRequestV1) writeTo(w *bufio.Writer) {
writeInt32(w, r.ReplicaID)
writeInt32(w, r.MaxWaitTime)
writeInt32(w, r.MinBytes)
writeArray(w, len(r.Topics), func(i int) { r.Topics[i].writeTo(w) })
}
type fetchRequestTopicV1 struct {
TopicName string
Partitions []fetchRequestPartitionV1
}
func (t fetchRequestTopicV1) size() int32 {
return sizeofString(t.TopicName) +
sizeofArray(len(t.Partitions), func(i int) int32 { return t.Partitions[i].size() })
}
func (t fetchRequestTopicV1) writeTo(w *bufio.Writer) {
writeString(w, t.TopicName)
writeArray(w, len(t.Partitions), func(i int) { t.Partitions[i].writeTo(w) })
}
type fetchRequestPartitionV1 struct {
Partition int32
FetchOffset int64
MaxBytes int32
}
func (p fetchRequestPartitionV1) size() int32 {
return 4 + 8 + 4
}
func (p fetchRequestPartitionV1) writeTo(w *bufio.Writer) {
writeInt32(w, p.Partition)
writeInt64(w, p.FetchOffset)
writeInt32(w, p.MaxBytes)
}
type fetchResponseV1 struct {
ThrottleTime int32
Topics []fetchResponseTopicV1
}
func (r fetchResponseV1) size() int32 {
return 4 + sizeofArray(len(r.Topics), func(i int) int32 { return r.Topics[i].size() })
}
func (r fetchResponseV1) writeTo(w *bufio.Writer) {
writeInt32(w, r.ThrottleTime)
writeArray(w, len(r.Topics), func(i int) { r.Topics[i].writeTo(w) })
}
type fetchResponseTopicV1 struct {
TopicName string
Partitions []fetchResponsePartitionV1
}
func (t fetchResponseTopicV1) size() int32 {
return sizeofString(t.TopicName) +
sizeofArray(len(t.Partitions), func(i int) int32 { return t.Partitions[i].size() })
}
func (t fetchResponseTopicV1) writeTo(w *bufio.Writer) {
writeString(w, t.TopicName)
writeArray(w, len(t.Partitions), func(i int) { t.Partitions[i].writeTo(w) })
}
type fetchResponsePartitionV1 struct {
Partition int32
ErrorCode int16
HighwaterMarkOffset int64
MessageSetSize int32
MessageSet messageSet
}
func (p fetchResponsePartitionV1) size() int32 {
return 4 + 2 + 8 + 4 + p.MessageSet.size()
}
func (p fetchResponsePartitionV1) writeTo(w *bufio.Writer) {
writeInt32(w, p.Partition)
writeInt16(w, p.ErrorCode)
writeInt64(w, p.HighwaterMarkOffset)
writeInt32(w, p.MessageSetSize)
p.MessageSet.writeTo(w)
}