mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-17 08:25:48 +00:00
perf[protocol]: 简化序列化和反序列化方法
This commit is contained in:
@@ -35,15 +35,11 @@ public class BooleanSerializer implements ISerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(ByteBuf buffer, Object object, IFieldRegistration fieldRegistration) {
|
||||
if (object == null) {
|
||||
ByteBufUtils.writeBoolean(buffer, Boolean.FALSE);
|
||||
return;
|
||||
}
|
||||
ByteBufUtils.writeBoolean(buffer, (Boolean) object);
|
||||
ByteBufUtils.writeBooleanBox(buffer, (Boolean) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readObject(ByteBuf buffer, IFieldRegistration fieldRegistration) {
|
||||
return ByteBufUtils.readBoolean(buffer);
|
||||
return ByteBufUtils.readBooleanBox(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,16 +36,12 @@ public class ByteSerializer implements ISerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(ByteBuf buffer, Object object, IFieldRegistration fieldRegistration) {
|
||||
if (object == null) {
|
||||
ByteBufUtils.writeByte(buffer, (byte) 0);
|
||||
return;
|
||||
}
|
||||
ByteBufUtils.writeByte(buffer, (Byte) object);
|
||||
ByteBufUtils.writeByteBox(buffer, (Byte) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readObject(ByteBuf buffer, IFieldRegistration fieldRegistration) {
|
||||
return ByteBufUtils.readByte(buffer);
|
||||
return ByteBufUtils.readByteBox(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,15 +36,11 @@ public class CharSerializer implements ISerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(ByteBuf buffer, Object object, IFieldRegistration fieldRegistration) {
|
||||
if (object == null) {
|
||||
ByteBufUtils.writeChar(buffer, Character.MIN_VALUE);
|
||||
return;
|
||||
}
|
||||
ByteBufUtils.writeChar(buffer, (Character) object);
|
||||
ByteBufUtils.writeCharBox(buffer, (Character) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readObject(ByteBuf buffer, IFieldRegistration fieldRegistration) {
|
||||
return ByteBufUtils.readChar(buffer);
|
||||
return ByteBufUtils.readCharBox(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,15 +35,11 @@ public class DoubleSerializer implements ISerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(ByteBuf buffer, Object object, IFieldRegistration fieldRegistration) {
|
||||
if (object == null) {
|
||||
ByteBufUtils.writeDouble(buffer, 0);
|
||||
return;
|
||||
}
|
||||
ByteBufUtils.writeDouble(buffer, (Double) object);
|
||||
ByteBufUtils.writeDoubleBox(buffer, (Double) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readObject(ByteBuf buffer, IFieldRegistration fieldRegistration) {
|
||||
return ByteBufUtils.readDouble(buffer);
|
||||
return ByteBufUtils.readDoubleBox(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,15 +36,11 @@ public class FloatSerializer implements ISerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(ByteBuf buffer, Object object, IFieldRegistration fieldRegistration) {
|
||||
if (object == null) {
|
||||
ByteBufUtils.writeFloat(buffer, 0F);
|
||||
return;
|
||||
}
|
||||
ByteBufUtils.writeFloat(buffer, (Float) object);
|
||||
ByteBufUtils.writeFloatBox(buffer, (Float) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readObject(ByteBuf buffer, IFieldRegistration fieldRegistration) {
|
||||
return ByteBufUtils.readFloat(buffer);
|
||||
return ByteBufUtils.readFloatBox(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,15 +36,11 @@ public class IntSerializer implements ISerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(ByteBuf buffer, Object object, IFieldRegistration fieldRegistration) {
|
||||
if (object == null) {
|
||||
ByteBufUtils.writeInt(buffer, 0);
|
||||
return;
|
||||
}
|
||||
ByteBufUtils.writeInt(buffer, (Integer) object);
|
||||
ByteBufUtils.writeIntBox(buffer, (Integer) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readObject(ByteBuf buffer, IFieldRegistration fieldRegistration) {
|
||||
return ByteBufUtils.readInt(buffer);
|
||||
return ByteBufUtils.readIntBox(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,15 +35,11 @@ public class LongSerializer implements ISerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(ByteBuf buffer, Object object, IFieldRegistration fieldRegistration) {
|
||||
if (object == null) {
|
||||
ByteBufUtils.writeLong(buffer, 0L);
|
||||
return;
|
||||
}
|
||||
ByteBufUtils.writeLong(buffer, (Long) object);
|
||||
ByteBufUtils.writeLongBox(buffer, (Long) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readObject(ByteBuf buffer, IFieldRegistration fieldRegistration) {
|
||||
return ByteBufUtils.readLong(buffer);
|
||||
return ByteBufUtils.readLongBox(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,15 +36,11 @@ public class ShortSerializer implements ISerializer {
|
||||
|
||||
@Override
|
||||
public void writeObject(ByteBuf buffer, Object object, IFieldRegistration fieldRegistration) {
|
||||
if (object == null) {
|
||||
ByteBufUtils.writeShort(buffer, (short) 0);
|
||||
return;
|
||||
}
|
||||
ByteBufUtils.writeShort(buffer, (Short) object);
|
||||
ByteBufUtils.writeShortBox(buffer, (Short) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readObject(ByteBuf buffer, IFieldRegistration fieldRegistration) {
|
||||
return ByteBufUtils.readShort(buffer);
|
||||
return ByteBufUtils.readShortBox(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user