Skip to content

Commit

Permalink
Add protocol dto classes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Kindrat committed Nov 15, 2015
1 parent cb961d9 commit 6ec8056
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 24 deletions.
30 changes: 11 additions & 19 deletions src/main/java/com/github/nginate/kafka/protocol/ApiKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,17 @@
@Getter
@AllArgsConstructor
public enum ApiKeys {
PRODUCE(0, "produce"),
FETCH(1, "fetch"),
LIST_OFFSETS(2, "list_offsets"),
METADATA(3, "metadata"),
LEADER_AND_ISR(4, "leader_and_isr"),
STOP_REPLICA(5, "stop_replica"),
OFFSET_COMMIT(8, "offset_commit"),
OFFSET_FETCH(9, "offset_fetch"),
CONSUMER_METADATA(10, "consumer_metadata"),
JOIN_GROUP(11, "join_group"),
HEARTBEAT(12, "heartbeat");
PRODUCE(0),
FETCH(1),
LIST_OFFSETS(2),
METADATA(3),
LEADER_AND_ISR(4),
STOP_REPLICA(5),
OFFSET_COMMIT(8),
OFFSET_FETCH(9),
CONSUMER_METADATA(10),
JOIN_GROUP(11),
HEARTBEAT(12);

/**
* the perminant and immutable id of an API--this can't change ever
*/
private final int id;
/**
* an english description of the api--this is for debugging and can change
*/
private final String name;

}
5 changes: 0 additions & 5 deletions src/main/java/com/github/nginate/kafka/protocol/Type.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.nginate.kafka.protocol.messages;

import com.github.nginate.kafka.protocol.types.Type;
import lombok.Data;

import static com.github.nginate.kafka.protocol.types.TypeName.INT8;

@Data
public abstract class Message {
@Type(INT8)
private int size;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.nginate.kafka.protocol.messages;

import com.github.nginate.kafka.protocol.types.Type;
import lombok.Data;
import lombok.EqualsAndHashCode;

import static com.github.nginate.kafka.protocol.types.TypeName.INT16;
import static com.github.nginate.kafka.protocol.types.TypeName.INT32;
import static com.github.nginate.kafka.protocol.types.TypeName.STRING;

@Data
@EqualsAndHashCode(callSuper = true)
public abstract class Request extends Message{
@Type(INT16)
private int apiKey;
@Type(INT16)
private int apiVersion;
@Type(INT32)
private int correlationId;
@Type(STRING)
private String clientId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.nginate.kafka.protocol.messages;

import com.github.nginate.kafka.protocol.types.Type;
import com.github.nginate.kafka.protocol.types.TypeName;
import lombok.Data;
import lombok.EqualsAndHashCode;

import static com.github.nginate.kafka.protocol.types.TypeName.*;

@Data
@EqualsAndHashCode(callSuper = true)
public abstract class Response extends Message {
@Type(INT32)
private int correlationId;
}
11 changes: 11 additions & 0 deletions src/main/java/com/github/nginate/kafka/protocol/types/Type.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.nginate.kafka.protocol.types;

import java.lang.annotation.*;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Type {
TypeName value();
boolean repeatable() default false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.nginate.kafka.protocol.types;

public enum TypeName {
/**
* Signed integer (1 byte) with the given precision (in bits) stored in big endian order.
*/
INT8,
/**
* Signed integer (2 bytes) with the given precision (in bits) stored in big endian order.
*/
INT16,
/**
* Signed integer (4 bytes) with the given precision (in bits) stored in big endian order.
*/
INT32,
/**
* Signed integer (8 bytes) with the given precision (in bits) stored in big endian order.
*/
INT64,
/**
* Consist of a signed int16 giving a length N followed by N bytes of content. A length of -1 indicates null.
*/
STRING,
/**
* Consist of a signed int32 giving a length N followed by N bytes of content. A length of -1 indicates null.
*/
BYTES
}

0 comments on commit 6ec8056

Please sign in to comment.