diff --git a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java index 300d6d92..88f890f5 100644 --- a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java @@ -418,9 +418,9 @@ public abstract class ByteBufUtils { public static List readPacketList(ByteBuf byteBuf, IProtocolRegistration protocolRegistration) { var length = readInt(byteBuf); - var list = new FixedSizeList(length); + var list = new FixedSizeList(length); for (var i = 0; i < length; i++) { - list.set(i, protocolRegistration.read(byteBuf)); + list.set(i, (IPacket) protocolRegistration.read(byteBuf)); } return list; } @@ -430,12 +430,7 @@ public abstract class ByteBufUtils { } public static Set readPacketSet(ByteBuf byteBuf, IProtocolRegistration protocolRegistration) { - var length = readInt(byteBuf); - var set = (Set) CollectionUtils.newFixedSet(length); - for (var i = 0; i < length; i++) { - set.add((IPacket) protocolRegistration.read(byteBuf)); - } - return set; + return new FixedHashSet((FixedSizeList) readPacketList(byteBuf, protocolRegistration)); } public static void writeIntIntMap(ByteBuf byteBuf, Map map) { @@ -765,12 +760,7 @@ public abstract class ByteBufUtils { } public static Set readBooleanSet(ByteBuf byteBuf) { - var length = readInt(byteBuf); - var set = (Set) CollectionUtils.newFixedSet(length); - for (var i = 0; i < length; i++) { - set.add(readBooleanBox(byteBuf)); - } - return set; + return new FixedHashSetBoolean((FixedSizeListBoolean) readBooleanList(byteBuf)); } //---------------------------------byte-------------------------------------- @@ -843,12 +833,7 @@ public abstract class ByteBufUtils { } public static Set readByteSet(ByteBuf byteBuf) { - var length = readInt(byteBuf); - var set = (Set) CollectionUtils.newFixedSet(length); - for (var i = 0; i < length; i++) { - set.add(readByteBox(byteBuf)); - } - return set; + return new FixedHashSetByte((FixedSizeListByte) readByteList(byteBuf)); } //---------------------------------short-------------------------------------- @@ -929,12 +914,7 @@ public abstract class ByteBufUtils { } public static Set readShortSet(ByteBuf byteBuf) { - var length = readInt(byteBuf); - var set = (Set) CollectionUtils.newFixedSet(length); - for (var i = 0; i < length; i++) { - set.add(readShortBox(byteBuf)); - } - return set; + return new FixedHashSetShort((FixedSizeListShort) readShortList(byteBuf)); } @@ -1008,12 +988,7 @@ public abstract class ByteBufUtils { } public static Set readIntSet(ByteBuf byteBuf) { - var length = readInt(byteBuf); - var set = (Set) CollectionUtils.newFixedSet(length); - for (var i = 0; i < length; i++) { - set.add(readIntBox(byteBuf)); - } - return set; + return new FixedHashSetInt((FixedSizeListInt) readIntList(byteBuf)); } @@ -1087,12 +1062,7 @@ public abstract class ByteBufUtils { } public static Set readLongSet(ByteBuf byteBuf) { - var length = readInt(byteBuf); - var set = (Set) CollectionUtils.newFixedSet(length); - for (var i = 0; i < length; i++) { - set.add(readLongBox(byteBuf)); - } - return set; + return new FixedHashSetLong((FixedSizeListLong) readLongList(byteBuf)); } //---------------------------------float-------------------------------------- @@ -1173,12 +1143,7 @@ public abstract class ByteBufUtils { } public static Set readFloatSet(ByteBuf byteBuf) { - var length = readInt(byteBuf); - var set = (Set) CollectionUtils.newFixedSet(length); - for (var i = 0; i < length; i++) { - set.add(readFloatBox(byteBuf)); - } - return set; + return new FixedHashSetFloat((FixedSizeListFloat) readFloatList(byteBuf)); } //---------------------------------double-------------------------------------- @@ -1259,12 +1224,7 @@ public abstract class ByteBufUtils { } public static Set readDoubleSet(ByteBuf byteBuf) { - var length = readInt(byteBuf); - var set = (Set) CollectionUtils.newFixedSet(length); - for (var i = 0; i < length; i++) { - set.add(readDoubleBox(byteBuf)); - } - return set; + return new FixedHashSetDouble((FixedSizeListDouble) readDoubleList(byteBuf)); } //---------------------------------string--------------------------------------