All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.pulsar.schema.JsonObjectSchema Maven / Gradle / Ivy

There is a newer version: 3.15.0
Show newest version
package io.quarkus.pulsar.schema;

import org.apache.pulsar.client.impl.schema.AbstractSchema;
import org.apache.pulsar.client.impl.schema.SchemaInfoImpl;
import org.apache.pulsar.common.schema.SchemaInfo;
import org.apache.pulsar.common.schema.SchemaType;

import io.netty.buffer.ByteBuf;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonObject;

public class JsonObjectSchema extends AbstractSchema {

    public static final JsonObjectSchema INSTANCE = new JsonObjectSchema();

    private static final SchemaInfo SCHEMA_INFO = SchemaInfoImpl.builder()
            .name("JsonObject")
            .type(SchemaType.NONE)
            .schema(new byte[0]).build();

    @Override
    public JsonObject decode(ByteBuf byteBuf) {
        if (byteBuf == null)
            return null;
        Buffer buffer = Buffer.buffer(byteBuf);
        return buffer.toJsonObject();
    }

    @Override
    public byte[] encode(JsonObject message) {
        if (message == null)
            return null;

        return message.encode().getBytes();
    }

    @Override
    public SchemaInfo getSchemaInfo() {
        return SCHEMA_INFO;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy