1 module kafkad.protocol.common;
2 
3 /*
4  * Kafka requests are always initiated by clients
5  * thus we only need serializers for requests and deserializers for responses
6  * 
7  * Kafka 0.8.x network protocol is described here: 
8 * https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol
9  */
10 
11 public import core.memory;
12 public import std.algorithm : min;
13 public import std.bitmanip;
14 public import std.exception;
15 public import std.traits;
16 public import vibe.core.stream;
17 public import kafkad.client;
18 import kafkad.exception;
19 
20 enum ApiKey : short {
21     ProduceRequest = 0,
22     FetchRequest = 1,
23     OffsetRequest = 2,
24     MetadataRequest = 3,
25     //Non-user facing control APIs = 4-7
26     OffsetCommitRequest = 8,
27     OffsetFetchRequest = 9,
28     ConsumerMetadataRequest = 10
29 }
30 
31 enum ApiError : short {
32     /* An unexpected server error */
33     Unknown = -1,
34     /* No error - it worked! */
35     NoError = 0,
36     /* The requested offset is outside the range of offsets maintained by the server for the given topic/partition */
37     OffsetOutOfRange = 1,
38     /* This indicates that a message contents does not match its CRC */
39     InvalidMessage = 2,
40     /* This request is for a topic or partition that does not exist on this broker */
41     UnknownTopicOrPartition = 3,
42     /* The message has a negative size */
43     InvalidMessageSize = 4,
44     /* This error is thrown if we are in the middle of a leadership election and there is currently no leader for
45      * this partition and hence it is unavailable for writes */
46     LeaderNotAvailable = 5,
47     /* This error is thrown if the client attempts to send messages to a replica that is not the leader for some
48      * partition. It indicates that the clients metadata is out of date */
49     NotLeaderForPartition = 6,
50     /* This error is thrown if the request exceeds the user-specified time limit in the request */
51     RequestTimedOut = 7,
52     /* This is not a client facing error and is used mostly by tools when a broker is not alive */
53     BrokerNotAvailable = 8,
54     /* If replica is expected on a broker, but is not (this can be safely ignored) */
55     ReplicaNotAvailable = 9,
56     /* The server has a configurable maximum message size to avoid unbounded memory allocation. This error is
57      * thrown if the client attempt to produce a message larger than this maximum */
58     MessageSizeTooLarge = 10,
59     /* Internal error code for broker-to-broker communication */
60     StaleControllerEpochCode = 11,
61     /* If you specify a string larger than configured maximum for offset metadata */
62     OffsetMetadataTooLargeCode = 12,
63     /* The broker returns this error code for an offset fetch request if it is still loading offsets (after a
64      * leader change for that offsets topic partition) */
65     OffsetsLoadInProgressCode = 14,
66     /* The broker returns this error code for consumer metadata requests or offset commit requests if the offsets
67      * topic has not yet been created */
68     ConsumerCoordinatorNotAvailableCode = 15,
69     /* The broker returns this error code if it receives an offset fetch or commit request for a consumer group
70      * that it is not a coordinator for */
71     NotCoordinatorForConsumerCode = 16
72 }