Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added IntDeserializer to KeyFormat #716

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/kafdrop/controller/MessageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import kafdrop.util.DefaultMessageDeserializer;
import kafdrop.util.DefaultMessageSerializer;
import kafdrop.util.Deserializers;
import kafdrop.util.IntMessageDeserializer;
import kafdrop.util.KeyFormat;
import kafdrop.util.MessageDeserializer;
import kafdrop.util.MessageFormat;
Expand Down Expand Up @@ -435,6 +436,8 @@ private MessageDeserializer getDeserializer(String topicName, MessageFormat form
deserializer = new ProtobufSchemaRegistryMessageDeserializer(topicName, schemaRegistryUrl, schemaRegistryAuth);
} else if (format == MessageFormat.MSGPACK) {
deserializer = new MsgPackMessageDeserializer();
} else if (format == MessageFormat.INT) {
deserializer = new IntMessageDeserializer();
} else {
deserializer = new DefaultMessageDeserializer();
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/kafdrop/util/ByteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ static String readString(ByteBuffer buffer) {
return new String(readBytes(buffer), StandardCharsets.UTF_8);
}

static String readInt(ByteBuffer buffer) {
return String.valueOf(buffer.getInt());
}

private static byte[] readBytes(ByteBuffer buffer) {
return readBytes(buffer, buffer.limit());
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/kafdrop/util/IntMessageDeserializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package kafdrop.util;

import java.nio.ByteBuffer;

public class IntMessageDeserializer implements MessageDeserializer {
@Override
public String deserializeMessage(ByteBuffer buffer) {
return ByteUtils.readInt(buffer);
}


}
2 changes: 1 addition & 1 deletion src/main/java/kafdrop/util/KeyFormat.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package kafdrop.util;

public enum KeyFormat {
DEFAULT, AVRO
DEFAULT, INT, AVRO
}
2 changes: 1 addition & 1 deletion src/main/java/kafdrop/util/MessageFormat.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package kafdrop.util;

public enum MessageFormat {
DEFAULT, AVRO, PROTOBUF, MSGPACK
DEFAULT, INT, AVRO, PROTOBUF, MSGPACK
}