package io.vertx.kafka.client.serialization;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import org.apache.kafka.common.serialization.Serde;
import org.apache.kafka.common.serialization.Serdes;
public class VertxSerdes extends Serdes {
static public Serde<Buffer> Buffer() {
return new BufferSerde();
}
static public Serde<JsonArray> JsonArray() {
return new JsonArraySerde();
}
static public Serde<JsonObject> JsonObject() {
return new JsonObjectSerde();
}
static public final class BufferSerde extends WrapperSerde<Buffer> {
public BufferSerde() {
super(new BufferSerializer(), new BufferDeserializer());
}
}
static public final class JsonArraySerde extends WrapperSerde<JsonArray> {
public JsonArraySerde() {
super(new JsonArraySerializer(), new JsonArrayDeserializer());
}
}
static public final class JsonObjectSerde extends WrapperSerde<JsonObject> {
public JsonObjectSerde() {
super(new JsonObjectSerializer(), new JsonObjectDeserializer());
}
}
static public <T> Serde<T> serdeFrom(Class<T> type) {
if (Buffer.class.isAssignableFrom(type)) {
return (Serde<T>) Buffer();
}
if (JsonArray.class.isAssignableFrom(type)) {
return (Serde<T>) JsonArray();
}
if (JsonObject.class.isAssignableFrom(type)) {
return (Serde<T>) JsonObject();
}
return Serdes.serdeFrom(type);
}
}