-
Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathfetch_request.rb
63 lines (54 loc) · 1.59 KB
/
fetch_request.rb
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
module Kafka
module Protocol
# A request to fetch messages from a given partition.
#
# ## API Specification
#
# FetchRequest => ReplicaId MaxWaitTime MinBytes [TopicName [Partition FetchOffset MaxBytes]]
# ReplicaId => int32
# MaxWaitTime => int32
# MinBytes => int32
# TopicName => string
# Partition => int32
# FetchOffset => int64
# MaxBytes => int32
#
class FetchRequest
# @param max_wait_time [Integer]
# @param min_bytes [Integer]
# @param topics [Hash]
def initialize(max_wait_time:, min_bytes:, max_bytes:, topics:)
@replica_id = REPLICA_ID
@max_wait_time = max_wait_time
@min_bytes = min_bytes
@max_bytes = max_bytes
@topics = topics
end
def api_key
FETCH_API
end
def api_version
3
end
def response_class
Protocol::FetchResponse
end
def encode(encoder)
encoder.write_int32(@replica_id)
encoder.write_int32(@max_wait_time)
encoder.write_int32(@min_bytes)
encoder.write_int32(@max_bytes)
encoder.write_array(@topics) do |topic, partitions|
encoder.write_string(topic)
encoder.write_array(partitions) do |partition, config|
fetch_offset = config.fetch(:fetch_offset)
max_bytes = config.fetch(:max_bytes)
encoder.write_int32(partition)
encoder.write_int64(fetch_offset)
encoder.write_int32(max_bytes)
end
end
end
end
end
end