From 615d87b4d5b6d80f2ad51f2c0e071bd84384864b Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Mon, 2 Dec 2024 15:13:36 +0100 Subject: [PATCH] Improve performance, fix buffer decoding --- .../java/it/cavallium/vertx/rpcservice/DataCodec.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/cavallium/vertx/rpcservice/DataCodec.java b/src/main/java/it/cavallium/vertx/rpcservice/DataCodec.java index 529fc18..ccb44e7 100644 --- a/src/main/java/it/cavallium/vertx/rpcservice/DataCodec.java +++ b/src/main/java/it/cavallium/vertx/rpcservice/DataCodec.java @@ -1,6 +1,7 @@ package it.cavallium.vertx.rpcservice; import io.vertx.core.buffer.Buffer; +import io.vertx.core.buffer.impl.BufferImpl; import io.vertx.core.eventbus.MessageCodec; import io.vertx.core.json.Json; @@ -16,9 +17,10 @@ public record DataCodec(MessageCodec codec) { @Override public Object decodeFromWire(int pos, Buffer buffer) { - Buffer buf = Buffer.buffer(); - this.pos2 = buffer.readFromBuffer(pos, buf); - return Json.decodeValue(buf); + int len = buffer.getInt(pos); + Buffer bufferData = buffer.getBuffer(pos + 4, pos + 4 + len); + this.pos2 = pos + 4 + len; + return Json.decodeValue(bufferData); } public int getPos2() {