forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.go
99 lines (81 loc) · 2.48 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
package kafka
type fetchRequestV2 struct {
ReplicaID int32
MaxWaitTime int32
MinBytes int32
Topics []fetchRequestTopicV2
}
func (r fetchRequestV2) size() int32 {
return 4 + 4 + 4 + sizeofArray(len(r.Topics), func(i int) int32 { return r.Topics[i].size() })
}
func (r fetchRequestV2) writeTo(wb *writeBuffer) {
wb.writeInt32(r.ReplicaID)
wb.writeInt32(r.MaxWaitTime)
wb.writeInt32(r.MinBytes)
wb.writeArray(len(r.Topics), func(i int) { r.Topics[i].writeTo(wb) })
}
type fetchRequestTopicV2 struct {
TopicName string
Partitions []fetchRequestPartitionV2
}
func (t fetchRequestTopicV2) size() int32 {
return sizeofString(t.TopicName) +
sizeofArray(len(t.Partitions), func(i int) int32 { return t.Partitions[i].size() })
}
func (t fetchRequestTopicV2) writeTo(wb *writeBuffer) {
wb.writeString(t.TopicName)
wb.writeArray(len(t.Partitions), func(i int) { t.Partitions[i].writeTo(wb) })
}
type fetchRequestPartitionV2 struct {
Partition int32
FetchOffset int64
MaxBytes int32
}
func (p fetchRequestPartitionV2) size() int32 {
return 4 + 8 + 4
}
func (p fetchRequestPartitionV2) writeTo(wb *writeBuffer) {
wb.writeInt32(p.Partition)
wb.writeInt64(p.FetchOffset)
wb.writeInt32(p.MaxBytes)
}
type fetchResponseV2 struct {
ThrottleTime int32
Topics []fetchResponseTopicV2
}
func (r fetchResponseV2) size() int32 {
return 4 + sizeofArray(len(r.Topics), func(i int) int32 { return r.Topics[i].size() })
}
func (r fetchResponseV2) writeTo(wb *writeBuffer) {
wb.writeInt32(r.ThrottleTime)
wb.writeArray(len(r.Topics), func(i int) { r.Topics[i].writeTo(wb) })
}
type fetchResponseTopicV2 struct {
TopicName string
Partitions []fetchResponsePartitionV2
}
func (t fetchResponseTopicV2) size() int32 {
return sizeofString(t.TopicName) +
sizeofArray(len(t.Partitions), func(i int) int32 { return t.Partitions[i].size() })
}
func (t fetchResponseTopicV2) writeTo(wb *writeBuffer) {
wb.writeString(t.TopicName)
wb.writeArray(len(t.Partitions), func(i int) { t.Partitions[i].writeTo(wb) })
}
type fetchResponsePartitionV2 struct {
Partition int32
ErrorCode int16
HighwaterMarkOffset int64
MessageSetSize int32
MessageSet messageSet
}
func (p fetchResponsePartitionV2) size() int32 {
return 4 + 2 + 8 + 4 + p.MessageSet.size()
}
func (p fetchResponsePartitionV2) writeTo(wb *writeBuffer) {
wb.writeInt32(p.Partition)
wb.writeInt16(p.ErrorCode)
wb.writeInt64(p.HighwaterMarkOffset)
wb.writeInt32(p.MessageSetSize)
p.MessageSet.writeTo(wb)
}