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 8548e64b..117f7515 100644 --- a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java @@ -19,6 +19,8 @@ import com.zfoo.protocol.util.StringUtils; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.util.ReferenceCountUtil; +import io.netty.util.collection.IntObjectHashMap; +import io.netty.util.collection.LongObjectHashMap; import java.util.Collection; import java.util.List; @@ -452,9 +454,9 @@ public abstract class ByteBufUtils { public static Map readIntIntMap(ByteBuf byteBuf) { var length = readInt(byteBuf); - var map = (Map) CollectionUtils.newFixedMap(length); + var map = new IntObjectHashMap(length); for (var i = 0; i < length; i++) { - map.put(readIntBox(byteBuf), readIntBox(byteBuf)); + map.put(readInt(byteBuf), readIntBox(byteBuf)); } return map; } @@ -473,9 +475,9 @@ public abstract class ByteBufUtils { public static Map readIntLongMap(ByteBuf byteBuf) { var length = readInt(byteBuf); - var map = (Map) CollectionUtils.newFixedMap(length); + var map = new IntObjectHashMap(length); for (var i = 0; i < length; i++) { - map.put(readIntBox(byteBuf), readLongBox(byteBuf)); + map.put(readInt(byteBuf), readLongBox(byteBuf)); } return map; } @@ -494,9 +496,9 @@ public abstract class ByteBufUtils { public static Map readIntStringMap(ByteBuf byteBuf) { var length = readInt(byteBuf); - var map = (Map) CollectionUtils.newFixedMap(length); + var map = new IntObjectHashMap(length); for (var i = 0; i < length; i++) { - map.put(readIntBox(byteBuf), readString(byteBuf)); + map.put(readInt(byteBuf), readString(byteBuf)); } return map; } @@ -515,9 +517,9 @@ public abstract class ByteBufUtils { public static Map readIntPacketMap(ByteBuf byteBuf, IProtocolRegistration protocolRegistration) { var length = readInt(byteBuf); - var map = (Map) CollectionUtils.newFixedMap(length); + var map = new IntObjectHashMap(length); for (var i = 0; i < length; i++) { - map.put(readIntBox(byteBuf), (IPacket) protocolRegistration.read(byteBuf)); + map.put(readInt(byteBuf), (IPacket) protocolRegistration.read(byteBuf)); } return map; } @@ -536,9 +538,9 @@ public abstract class ByteBufUtils { public static Map readLongIntMap(ByteBuf byteBuf) { var length = readInt(byteBuf); - var map = (Map) CollectionUtils.newFixedMap(length); + var map = new LongObjectHashMap(length); for (var i = 0; i < length; i++) { - map.put(readLongBox(byteBuf), readIntBox(byteBuf)); + map.put(readLong(byteBuf), readIntBox(byteBuf)); } return map; } @@ -557,9 +559,9 @@ public abstract class ByteBufUtils { public static Map readLongLongMap(ByteBuf byteBuf) { var length = readInt(byteBuf); - var map = (Map) CollectionUtils.newFixedMap(length); + var map = new LongObjectHashMap(length); for (var i = 0; i < length; i++) { - map.put(readLongBox(byteBuf), readLongBox(byteBuf)); + map.put(readLong(byteBuf), readLongBox(byteBuf)); } return map; } @@ -578,9 +580,9 @@ public abstract class ByteBufUtils { public static Map readLongStringMap(ByteBuf byteBuf) { var length = readInt(byteBuf); - var map = (Map) CollectionUtils.newFixedMap(length); + var map = new LongObjectHashMap(length); for (var i = 0; i < length; i++) { - map.put(readLongBox(byteBuf), readString(byteBuf)); + map.put(readLong(byteBuf), readString(byteBuf)); } return map; } @@ -599,9 +601,9 @@ public abstract class ByteBufUtils { public static Map readLongPacketMap(ByteBuf byteBuf, IProtocolRegistration protocolRegistration) { var length = readInt(byteBuf); - var map = (Map) CollectionUtils.newFixedMap(length); + var map = new LongObjectHashMap(length); for (var i = 0; i < length; i++) { - map.put(readLongBox(byteBuf), (IPacket) protocolRegistration.read(byteBuf)); + map.put(readLong(byteBuf), (IPacket) protocolRegistration.read(byteBuf)); } return map; }