Skip to content

Commit

Permalink
Serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
iamlinhui committed May 27, 2022
1 parent de4fd00 commit 1b5d4b1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,7 +15,7 @@

public class MessageDecoder extends MessageToMessageDecoder<ByteBuf> {

private final Serialize serialize = new Jackson();
private static final Serializer SERIALIZER = new Jackson();

@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,15 +13,15 @@

public class MessageEncoder extends MessageToByteEncoder<Message> {

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 {
MessageType type = message.getType();
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Meta> SCHEMA_CACHE = RuntimeSchema.getSchema(Meta.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.promptness.rpt.base.protocol.Meta;

public interface Serialize {
public interface Serializer {

byte[] serialize(Meta meta) throws Exception;

Expand Down

0 comments on commit 1b5d4b1

Please sign in to comment.