From 1b5d4b16033f85a6a281fc834f49c0807cd1aad8 Mon Sep 17 00:00:00 2001 From: lynn Date: Sat, 28 May 2022 04:20:18 +0800 Subject: [PATCH] Serializer --- .../java/cn/promptness/rpt/base/coder/MessageDecoder.java | 6 +++--- .../java/cn/promptness/rpt/base/coder/MessageEncoder.java | 6 +++--- .../main/java/cn/promptness/rpt/base/serialize/Jackson.java | 2 +- .../java/cn/promptness/rpt/base/serialize/Protostuff.java | 2 +- .../rpt/base/serialize/{Serialize.java => Serializer.java} | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) rename rpt-base/src/main/java/cn/promptness/rpt/base/serialize/{Serialize.java => Serializer.java} (86%) diff --git a/rpt-base/src/main/java/cn/promptness/rpt/base/coder/MessageDecoder.java b/rpt-base/src/main/java/cn/promptness/rpt/base/coder/MessageDecoder.java index 343e1a8..fbb8f10 100644 --- a/rpt-base/src/main/java/cn/promptness/rpt/base/coder/MessageDecoder.java +++ b/rpt-base/src/main/java/cn/promptness/rpt/base/coder/MessageDecoder.java @@ -4,7 +4,7 @@ import cn.promptness.rpt.base.protocol.MessageType; import cn.promptness.rpt.base.protocol.Meta; import cn.promptness.rpt.base.serialize.Jackson; -import cn.promptness.rpt.base.serialize.Serialize; +import cn.promptness.rpt.base.serialize.Serializer; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.channel.ChannelHandlerContext; @@ -15,7 +15,7 @@ public class MessageDecoder extends MessageToMessageDecoder { - private final Serialize serialize = new Jackson(); + private static final Serializer SERIALIZER = new Jackson(); @Override protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List list) throws Exception { @@ -27,7 +27,7 @@ protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteB if (protobufLength > 0) { byte[] metaByte = new byte[protobufLength]; byteBuf.readBytes(metaByte); - Meta meta = serialize.deserialize(metaByte); + Meta meta = SERIALIZER.deserialize(metaByte); proxyMessage.setMeta(meta); } if (byteBuf.isReadable()) { diff --git a/rpt-base/src/main/java/cn/promptness/rpt/base/coder/MessageEncoder.java b/rpt-base/src/main/java/cn/promptness/rpt/base/coder/MessageEncoder.java index 709ef51..cf6ca57 100644 --- a/rpt-base/src/main/java/cn/promptness/rpt/base/coder/MessageEncoder.java +++ b/rpt-base/src/main/java/cn/promptness/rpt/base/coder/MessageEncoder.java @@ -4,7 +4,7 @@ import cn.promptness.rpt.base.protocol.MessageType; import cn.promptness.rpt.base.protocol.Meta; import cn.promptness.rpt.base.serialize.Jackson; -import cn.promptness.rpt.base.serialize.Serialize; +import cn.promptness.rpt.base.serialize.Serializer; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; @@ -13,7 +13,7 @@ public class MessageEncoder extends MessageToByteEncoder { - private final Serialize serialize = new Jackson(); + private static final Serializer SERIALIZER = new Jackson(); @Override protected void encode(ChannelHandlerContext channelHandlerContext, Message message, ByteBuf out) throws Exception { @@ -21,7 +21,7 @@ protected void encode(ChannelHandlerContext channelHandlerContext, Message messa out.writeInt(type.getCode()); Meta meta = message.getMeta(); - byte[] protobuf = meta == null ? EmptyArrays.EMPTY_BYTES : serialize.serialize(meta); + byte[] protobuf = meta == null ? EmptyArrays.EMPTY_BYTES : SERIALIZER.serialize(meta); out.writeInt(protobuf.length); out.writeBytes(protobuf); diff --git a/rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Jackson.java b/rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Jackson.java index e7d8df6..dd2c78f 100644 --- a/rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Jackson.java +++ b/rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Jackson.java @@ -5,7 +5,7 @@ import java.io.IOException; -public class Jackson implements Serialize { +public class Jackson implements Serializer { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); diff --git a/rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Protostuff.java b/rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Protostuff.java index 33f36a4..999bbf2 100644 --- a/rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Protostuff.java +++ b/rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Protostuff.java @@ -6,7 +6,7 @@ import io.protostuff.Schema; import io.protostuff.runtime.RuntimeSchema; -public class Protostuff implements Serialize { +public class Protostuff implements Serializer { private static final LinkedBuffer BUFFER = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE); private static final Schema SCHEMA_CACHE = RuntimeSchema.getSchema(Meta.class); diff --git a/rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Serialize.java b/rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Serializer.java similarity index 86% rename from rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Serialize.java rename to rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Serializer.java index c8586f6..2d71cf2 100644 --- a/rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Serialize.java +++ b/rpt-base/src/main/java/cn/promptness/rpt/base/serialize/Serializer.java @@ -2,7 +2,7 @@ import cn.promptness.rpt.base.protocol.Meta; -public interface Serialize { +public interface Serializer { byte[] serialize(Meta meta) throws Exception;