package io.vertx.core.eventbus.impl.codecs;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.eventbus.MessageCodec;
import io.vertx.core.json.JsonObject;
public class JsonObjectMessageCodec implements MessageCodec<JsonObject, JsonObject> {
@Override
public void encodeToWire(Buffer buffer, JsonObject jsonObject) {
Buffer encoded = jsonObject.toBuffer();
buffer.appendInt(encoded.length());
buffer.appendBuffer(encoded);
}
@Override
public JsonObject decodeFromWire(int pos, Buffer buffer) {
int length = buffer.getInt(pos);
pos += 4;
return new JsonObject(buffer.slice(pos, pos + length));
}
@Override
public JsonObject transform(JsonObject jsonObject) {
return jsonObject.copy();
}
@Override
public String name() {
return "jsonobject";
}
@Override
public byte systemCodecID() {
return 13;
}
}