diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownListSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownListSerializer.java index 2110a539..407c845b 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownListSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownListSerializer.java @@ -204,7 +204,7 @@ public class CutDownListSerializer implements ICutDownSerializer { builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, objectProtocolField.getProtocolId())).append(LS); break; case CSharp: - builder.append(StringUtils.format("buffer.WritePacketList<>({}, {});", objectStr, objectProtocolField.getProtocolId())).append(LS); + builder.append(StringUtils.format("buffer.WritePacketList({}, {});", objectStr, objectProtocolField.getProtocolId())).append(LS); break; default: flag = false; diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownMapSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownMapSerializer.java index 1512fbbb..f1f130be 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownMapSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownMapSerializer.java @@ -109,7 +109,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { builder.append(StringUtils.format("buffer.writeIntPacketMap({}, {})", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS); return true; case CSharp: - builder.append(StringUtils.format("buffer.WriteIntPacketMap<>({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS); + builder.append(StringUtils.format("buffer.WriteIntPacketMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS); return true; } } @@ -171,7 +171,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { builder.append(StringUtils.format("buffer.writeLongPacketMap({}, {})", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS); return true; case CSharp: - builder.append(StringUtils.format("buffer.WriteLongPacketMap<>({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS); + builder.append(StringUtils.format("buffer.WriteLongPacketMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS); return true; } } @@ -233,7 +233,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { builder.append(StringUtils.format("buffer.writeStringPacketMap({}, {})", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS); return true; case CSharp: - builder.append(StringUtils.format("buffer.WriteStringPacketMap<>({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS); + builder.append(StringUtils.format("buffer.WriteStringPacketMap({}, {});", objectStr, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS); return true; } } @@ -312,7 +312,7 @@ public class CutDownMapSerializer implements ICutDownSerializer { builder.append(StringUtils.format("var {} = buffer.readIntPacketMap({})", map, ((ObjectProtocolField) valueRegistration).getProtocolId())).append(LS); return map; case CSharp: - builder.append(StringUtils.format("var {} = buffer.ReadIntPacket<{}>Map({});", map, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS); + builder.append(StringUtils.format("var {} = buffer.ReadIntPacketMap<{}>({});", map, EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(protocolId), protocolId)).append(LS); return map; } } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownSetSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownSetSerializer.java index a0b70a7c..41f7f175 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownSetSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/CutDownSetSerializer.java @@ -202,7 +202,7 @@ public class CutDownSetSerializer implements ICutDownSerializer { builder.append(StringUtils.format("buffer.writePacketArray({}, {})", objectStr, objectProtocolField.getProtocolId())).append(LS); break; case CSharp: - builder.append(StringUtils.format("buffer.WritePacketSet<>({}, {});", objectStr, objectProtocolField.getProtocolId())).append(LS); + builder.append(StringUtils.format("buffer.WritePacketSet({}, {});", objectStr, objectProtocolField.getProtocolId())).append(LS); break; default: flag = false; diff --git a/protocol/src/main/resources/cs/Buffer/ByteBuffer.cs b/protocol/src/main/resources/cs/Buffer/ByteBuffer.cs index bc64ea62..71609a34 100644 --- a/protocol/src/main/resources/cs/Buffer/ByteBuffer.cs +++ b/protocol/src/main/resources/cs/Buffer/ByteBuffer.cs @@ -60,7 +60,8 @@ namespace CsProtocol.Buffer { if (writeIndex > buffer.Length) { - throw new Exception("writeIndex[" + writeIndex + "] out of bounds exception: readerIndex: " + readOffset + + throw new Exception("writeIndex[" + writeIndex + "] out of bounds exception: readerIndex: " + + readOffset + ", writerIndex: " + writeOffset + "(expected: 0 <= readerIndex <= writerIndex <= capacity:" + buffer.Length); } @@ -564,7 +565,7 @@ namespace CsProtocol.Buffer WriteBool(!flag); return flag; } - + public void WriteBooleanArray(bool[] array) { if ((array == null) || (array.Length == 0)) @@ -581,7 +582,7 @@ namespace CsProtocol.Buffer } } } - + public bool[] ReadBooleanArray() { int size = ReadInt(); @@ -593,6 +594,7 @@ namespace CsProtocol.Buffer array[index] = ReadBool(); } } + return array; } @@ -624,6 +626,7 @@ namespace CsProtocol.Buffer array[index] = ReadByte(); } } + return array; } @@ -643,7 +646,7 @@ namespace CsProtocol.Buffer } } } - + public short[] ReadShortArray() { int size = ReadInt(); @@ -655,9 +658,10 @@ namespace CsProtocol.Buffer array[index] = ReadShort(); } } + return array; } - + public void WriteIntArray(int[] array) { if ((array == null) || (array.Length == 0)) @@ -674,7 +678,7 @@ namespace CsProtocol.Buffer } } } - + public int[] ReadIntArray() { int size = ReadInt(); @@ -686,9 +690,10 @@ namespace CsProtocol.Buffer array[index] = ReadInt(); } } + return array; } - + public void WriteLongArray(long[] array) { if ((array == null) || (array.Length == 0)) @@ -705,7 +710,7 @@ namespace CsProtocol.Buffer } } } - + public long[] ReadLongArray() { int size = ReadInt(); @@ -717,9 +722,10 @@ namespace CsProtocol.Buffer array[index] = ReadLong(); } } + return array; } - + public void WriteFloatArray(float[] array) { if ((array == null) || (array.Length == 0)) @@ -736,7 +742,7 @@ namespace CsProtocol.Buffer } } } - + public float[] ReadFloatArray() { int size = ReadInt(); @@ -748,9 +754,10 @@ namespace CsProtocol.Buffer array[index] = ReadLong(); } } + return array; } - + public void WriteDoubleArray(double[] array) { if ((array == null) || (array.Length == 0)) @@ -767,7 +774,7 @@ namespace CsProtocol.Buffer } } } - + public double[] ReadDoubleArray() { int size = ReadInt(); @@ -779,9 +786,10 @@ namespace CsProtocol.Buffer array[index] = ReadLong(); } } + return array; } - + public void WriteCharArray(char[] array) { if ((array == null) || (array.Length == 0)) @@ -798,7 +806,7 @@ namespace CsProtocol.Buffer } } } - + public char[] ReadCharArray() { int size = ReadInt(); @@ -810,9 +818,10 @@ namespace CsProtocol.Buffer array[index] = ReadChar(); } } + return array; } - + public void WriteStringArray(string[] array) { if ((array == null) || (array.Length == 0)) @@ -829,7 +838,7 @@ namespace CsProtocol.Buffer } } } - + public string[] ReadStringArray() { int size = ReadInt(); @@ -841,9 +850,10 @@ namespace CsProtocol.Buffer array[index] = ReadString(); } } + return array; } - + public void WritePacketArray(T[] array, short protocolId) { if ((array == null) || (array.Length == 0)) @@ -861,7 +871,7 @@ namespace CsProtocol.Buffer } } } - + public T[] ReadPacketArray(short protocolId) { int size = ReadInt(); @@ -874,9 +884,10 @@ namespace CsProtocol.Buffer array[index] = (T) protocolRegistration.Read(this); } } + return array; } - + public void WriteBooleanList(List list) { if ((list == null) || (list.Count == 0)) @@ -893,7 +904,7 @@ namespace CsProtocol.Buffer } } } - + public List ReadBooleanList() { int size = ReadInt(); @@ -905,9 +916,10 @@ namespace CsProtocol.Buffer list.Add(ReadBool()); } } + return list; } - + public void WriteByteList(List list) { if ((list == null) || (list.Count == 0)) @@ -924,7 +936,7 @@ namespace CsProtocol.Buffer } } } - + public List ReadByteList() { int size = ReadInt(); @@ -936,9 +948,10 @@ namespace CsProtocol.Buffer list.Add(ReadByte()); } } + return list; } - + public void WriteShortList(List list) { if ((list == null) || (list.Count == 0)) @@ -955,7 +968,7 @@ namespace CsProtocol.Buffer } } } - + public List ReadShortList() { int size = ReadInt(); @@ -967,9 +980,10 @@ namespace CsProtocol.Buffer list.Add(ReadShort()); } } + return list; } - + public void WriteIntList(List list) { if ((list == null) || (list.Count == 0)) @@ -986,7 +1000,7 @@ namespace CsProtocol.Buffer } } } - + public List ReadIntList() { int size = ReadInt(); @@ -998,6 +1012,7 @@ namespace CsProtocol.Buffer list.Add(ReadInt()); } } + return list; } @@ -1029,6 +1044,7 @@ namespace CsProtocol.Buffer list.Add(ReadLong()); } } + return list; } @@ -1048,7 +1064,7 @@ namespace CsProtocol.Buffer } } } - + public List ReadFloatList() { int size = ReadInt(); @@ -1060,9 +1076,10 @@ namespace CsProtocol.Buffer list.Add(ReadFloat()); } } + return list; } - + public void WriteDoubleList(List list) { if ((list == null) || (list.Count == 0)) @@ -1079,7 +1096,7 @@ namespace CsProtocol.Buffer } } } - + public List ReadDoubleList() { int size = ReadInt(); @@ -1091,9 +1108,10 @@ namespace CsProtocol.Buffer list.Add(ReadDouble()); } } + return list; } - + public void WriteCharList(List list) { if ((list == null) || (list.Count == 0)) @@ -1110,7 +1128,7 @@ namespace CsProtocol.Buffer } } } - + public List ReadCharList() { int size = ReadInt(); @@ -1122,9 +1140,10 @@ namespace CsProtocol.Buffer list.Add(ReadChar()); } } + return list; } - + public void WriteStringList(List list) { if ((list == null) || (list.Count == 0)) @@ -1141,7 +1160,7 @@ namespace CsProtocol.Buffer } } } - + public List ReadStringList() { int size = ReadInt(); @@ -1153,9 +1172,10 @@ namespace CsProtocol.Buffer list.Add(ReadString()); } } + return list; } - + public void WritePacketList(List list, short protocolId) { if ((list == null) || (list.Count == 0)) @@ -1173,7 +1193,7 @@ namespace CsProtocol.Buffer } } } - + public List ReadPacketList(short protocolId) { int size = ReadInt(); @@ -1186,6 +1206,7 @@ namespace CsProtocol.Buffer list.Add((T) protocolRegistration.Read(this)); } } + return list; } @@ -1208,7 +1229,7 @@ namespace CsProtocol.Buffer public HashSet ReadBooleanSet() { int size = ReadInt(); - HashSet set = new HashSet(size); + HashSet set = new HashSet(); if (size > 0) { for (int index = 0; index < size; index++) @@ -1216,6 +1237,7 @@ namespace CsProtocol.Buffer set.Add(ReadBool()); } } + return set; } @@ -1238,7 +1260,7 @@ namespace CsProtocol.Buffer public HashSet ReadShortSet() { int size = ReadInt(); - HashSet set = new HashSet(size); + HashSet set = new HashSet(); if (size > 0) { for (int index = 0; index < size; index++) @@ -1246,6 +1268,7 @@ namespace CsProtocol.Buffer set.Add(ReadShort()); } } + return set; } @@ -1268,7 +1291,7 @@ namespace CsProtocol.Buffer public HashSet ReadIntSet() { int size = ReadInt(); - HashSet set = new HashSet(size); + HashSet set = new HashSet(); if (size > 0) { for (int index = 0; index < size; index++) @@ -1276,6 +1299,7 @@ namespace CsProtocol.Buffer set.Add(ReadInt()); } } + return set; } @@ -1298,7 +1322,7 @@ namespace CsProtocol.Buffer public HashSet ReadLongSet() { int size = ReadInt(); - HashSet set = new HashSet(size); + HashSet set = new HashSet(); if (size > 0) { for (int index = 0; index < size; index++) @@ -1306,6 +1330,7 @@ namespace CsProtocol.Buffer set.Add(ReadLong()); } } + return set; } @@ -1328,7 +1353,7 @@ namespace CsProtocol.Buffer public HashSet ReadFloatSet() { int size = ReadInt(); - HashSet set = new HashSet(size); + HashSet set = new HashSet(); if (size > 0) { for (int index = 0; index < size; index++) @@ -1336,6 +1361,7 @@ namespace CsProtocol.Buffer set.Add(ReadFloat()); } } + return set; } @@ -1358,7 +1384,7 @@ namespace CsProtocol.Buffer public HashSet ReadDoubleSet() { int size = ReadInt(); - HashSet set = new HashSet(size); + HashSet set = new HashSet(); if (size > 0) { for (int index = 0; index < size; index++) @@ -1366,6 +1392,7 @@ namespace CsProtocol.Buffer set.Add(ReadDouble()); } } + return set; } @@ -1388,7 +1415,7 @@ namespace CsProtocol.Buffer public HashSet ReadCharSet() { int size = ReadInt(); - HashSet set = new HashSet(size); + HashSet set = new HashSet(); if (size > 0) { for (int index = 0; index < size; index++) @@ -1396,6 +1423,7 @@ namespace CsProtocol.Buffer set.Add(ReadChar()); } } + return set; } @@ -1418,7 +1446,7 @@ namespace CsProtocol.Buffer public HashSet ReadStringSet() { int size = ReadInt(); - HashSet set = new HashSet(size); + HashSet set = new HashSet(); if (size > 0) { for (int index = 0; index < size; index++) @@ -1426,6 +1454,7 @@ namespace CsProtocol.Buffer set.Add(ReadString()); } } + return set; } @@ -1449,7 +1478,7 @@ namespace CsProtocol.Buffer public HashSet ReadPacketSet(short protocolId) { int size = ReadInt(); - HashSet set = new HashSet(size); + HashSet set = new HashSet(); if (size > 0) { IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); @@ -1458,6 +1487,7 @@ namespace CsProtocol.Buffer set.Add((T) protocolRegistration.Read(this)); } } + return set; } @@ -1491,6 +1521,7 @@ namespace CsProtocol.Buffer map[key] = value; } } + return map; } @@ -1524,6 +1555,7 @@ namespace CsProtocol.Buffer map[key] = value; } } + return map; } @@ -1557,44 +1589,46 @@ namespace CsProtocol.Buffer map[key] = value; } } + return map; } - public void WriteIntPacketMap(Dictionary map, short protocolId) - { - if ((map == null) || (map.Count == 0)) - { - WriteInt(0); - } - else - { - IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); - WriteInt(map.Count); - foreach (var element in map) - { - WriteInt(element.Key); - protocolRegistration.Write(this, (IPacket) element.Value); - } - } - } + public void WriteIntPacketMap(Dictionary map, short protocolId) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + WriteInt(map.Count); + foreach (var element in map) + { + WriteInt(element.Key); + protocolRegistration.Write(this, (IPacket) element.Value); + } + } + } - public Dictionary ReadIntPacketMap(short protocolId) - { - int size = ReadInt(); - Dictionary map = new Dictionary(size); - if (size > 0) - { - IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); - for (int index = 0; index < size; index++) - { - var key = ReadInt(); - var value = (T) protocolRegistration.Read(this); - map[key] = value; - } - } - return map; - } + public Dictionary ReadIntPacketMap(short protocolId) + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + for (int index = 0; index < size; index++) + { + var key = ReadInt(); + var value = (T) protocolRegistration.Read(this); + map[key] = value; + } + } + + return map; + } public void WriteLongIntMap(Dictionary map) { @@ -1626,6 +1660,7 @@ namespace CsProtocol.Buffer map[key] = value; } } + return map; } @@ -1659,6 +1694,7 @@ namespace CsProtocol.Buffer map[key] = value; } } + return map; } @@ -1692,44 +1728,46 @@ namespace CsProtocol.Buffer map[key] = value; } } + return map; } - public void WriteLongPacketMap(Dictionary map, short protocolId) - { - if ((map == null) || (map.Count == 0)) - { - WriteInt(0); - } - else - { - IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); - WriteInt(map.Count); - foreach (var element in map) - { - WriteLong(element.Key); - protocolRegistration.Write(this, (IPacket) element.Value); - } - } - } + public void WriteLongPacketMap(Dictionary map, short protocolId) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + WriteInt(map.Count); + foreach (var element in map) + { + WriteLong(element.Key); + protocolRegistration.Write(this, (IPacket) element.Value); + } + } + } - public Dictionary ReadLongPacketMap(short protocolId) - { - int size = ReadInt(); - Dictionary map = new Dictionary(size); - if (size > 0) - { - IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); - for (int index = 0; index < size; index++) - { - var key = ReadLong(); - var value = (T) protocolRegistration.Read(this); - map[key] = value; - } - } - return map; - } + public Dictionary ReadLongPacketMap(short protocolId) + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + for (int index = 0; index < size; index++) + { + var key = ReadLong(); + var value = (T) protocolRegistration.Read(this); + map[key] = value; + } + } + + return map; + } public void WriteStringIntMap(Dictionary map) { @@ -1761,6 +1799,7 @@ namespace CsProtocol.Buffer map[key] = value; } } + return map; } @@ -1794,6 +1833,7 @@ namespace CsProtocol.Buffer map[key] = value; } } + return map; } @@ -1827,43 +1867,45 @@ namespace CsProtocol.Buffer map[key] = value; } } + return map; } - public void WriteStringPacketMap(Dictionary map, short protocolId) - { - if ((map == null) || (map.Count == 0)) - { - WriteInt(0); - } - else - { - IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); - WriteInt(map.Count); - foreach (var element in map) - { - WriteString(element.Key); - protocolRegistration.Write(this, (IPacket) element.Value); - } - } - } + public void WriteStringPacketMap(Dictionary map, short protocolId) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + WriteInt(map.Count); + foreach (var element in map) + { + WriteString(element.Key); + protocolRegistration.Write(this, (IPacket) element.Value); + } + } + } - public Dictionary ReadStringPacketMap(short protocolId) - { - int size = ReadInt(); - Dictionary map = new Dictionary(size); - if (size > 0) - { - IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); - for (int index = 0; index < size; index++) - { - var key = ReadString(); - var value = (T) protocolRegistration.Read(this); - map[key] = value; - } - } - return map; - } + public Dictionary ReadStringPacketMap(short protocolId) + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + for (int index = 0; index < size; index++) + { + var key = ReadString(); + var value = (T) protocolRegistration.Read(this); + map[key] = value; + } + } + + return map; + } } -} +} \ No newline at end of file diff --git a/protocol/src/test/resources/csTest/CsProtocol/Buffer/BigEndianByteBuffer.cs b/protocol/src/test/resources/csTest/CsProtocol/Buffer/BigEndianByteBuffer.cs index 3c836577..b394c899 100644 --- a/protocol/src/test/resources/csTest/CsProtocol/Buffer/BigEndianByteBuffer.cs +++ b/protocol/src/test/resources/csTest/CsProtocol/Buffer/BigEndianByteBuffer.cs @@ -1,4 +1,4 @@ -namespace CsProtocol.Buffer +namespace CsProtocol.Buffer { public class BigEndianByteBuffer : ByteBuffer { diff --git a/protocol/src/test/resources/csTest/CsProtocol/Buffer/ByteBuffer.cs b/protocol/src/test/resources/csTest/CsProtocol/Buffer/ByteBuffer.cs index 0a1257ac..71609a34 100644 --- a/protocol/src/test/resources/csTest/CsProtocol/Buffer/ByteBuffer.cs +++ b/protocol/src/test/resources/csTest/CsProtocol/Buffer/ByteBuffer.cs @@ -2,6 +2,8 @@ using System; using System.Collections.Generic; using System.Text; +// CSharp字节保存在内存的低地址中是根据操作系统来的,所以有可能是大端模式,也有可能是小端模式 +// 右移操作>>是带符号右移 namespace CsProtocol.Buffer { public abstract class ByteBuffer @@ -58,7 +60,8 @@ namespace CsProtocol.Buffer { if (writeIndex > buffer.Length) { - throw new Exception("writeIndex[" + writeIndex + "] out of bounds exception: readerIndex: " + readOffset + + throw new Exception("writeIndex[" + writeIndex + "] out of bounds exception: readerIndex: " + + readOffset + ", writerIndex: " + writeOffset + "(expected: 0 <= readerIndex <= writerIndex <= capacity:" + buffer.Length); } @@ -555,5 +558,1354 @@ namespace CsProtocol.Buffer return Encoding.UTF8.GetString(value, 0, value.Length); } + + public bool WritePacketFlag(IPacket packet) + { + bool flag = packet == null; + WriteBool(!flag); + return flag; + } + + public void WriteBooleanArray(bool[] array) + { + if ((array == null) || (array.Length == 0)) + { + WriteInt(0); + } + else + { + WriteInt(array.Length); + int length = array.Length; + for (int index = 0; index < length; index++) + { + WriteBool(array[index]); + } + } + } + + public bool[] ReadBooleanArray() + { + int size = ReadInt(); + bool[] array = new bool[size]; + if (size > 0) + { + for (int index = 0; index < size; index++) + { + array[index] = ReadBool(); + } + } + + return array; + } + + public void WriteByteArray(byte[] array) + { + if ((array == null) || (array.Length == 0)) + { + WriteInt(0); + } + else + { + WriteInt(array.Length); + int length = array.Length; + for (int index = 0; index < length; index++) + { + WriteByte(array[index]); + } + } + } + + public byte[] ReadByteArray() + { + int size = ReadInt(); + byte[] array = new byte[size]; + if (size > 0) + { + for (int index = 0; index < size; index++) + { + array[index] = ReadByte(); + } + } + + return array; + } + + public void WriteShortArray(short[] array) + { + if ((array == null) || (array.Length == 0)) + { + WriteInt(0); + } + else + { + WriteInt(array.Length); + int length = array.Length; + for (int index = 0; index < length; index++) + { + WriteShort(array[index]); + } + } + } + + public short[] ReadShortArray() + { + int size = ReadInt(); + short[] array = new short[size]; + if (size > 0) + { + for (int index = 0; index < size; index++) + { + array[index] = ReadShort(); + } + } + + return array; + } + + public void WriteIntArray(int[] array) + { + if ((array == null) || (array.Length == 0)) + { + WriteInt(0); + } + else + { + WriteInt(array.Length); + int length = array.Length; + for (int index = 0; index < length; index++) + { + WriteInt(array[index]); + } + } + } + + public int[] ReadIntArray() + { + int size = ReadInt(); + int[] array = new int[size]; + if (size > 0) + { + for (int index = 0; index < size; index++) + { + array[index] = ReadInt(); + } + } + + return array; + } + + public void WriteLongArray(long[] array) + { + if ((array == null) || (array.Length == 0)) + { + WriteInt(0); + } + else + { + WriteInt(array.Length); + int length = array.Length; + for (int index = 0; index < length; index++) + { + WriteLong(array[index]); + } + } + } + + public long[] ReadLongArray() + { + int size = ReadInt(); + long[] array = new long[size]; + if (size > 0) + { + for (int index = 0; index < size; index++) + { + array[index] = ReadLong(); + } + } + + return array; + } + + public void WriteFloatArray(float[] array) + { + if ((array == null) || (array.Length == 0)) + { + WriteInt(0); + } + else + { + WriteInt(array.Length); + int length = array.Length; + for (int index = 0; index < length; index++) + { + WriteFloat(array[index]); + } + } + } + + public float[] ReadFloatArray() + { + int size = ReadInt(); + float[] array = new float[size]; + if (size > 0) + { + for (int index = 0; index < size; index++) + { + array[index] = ReadLong(); + } + } + + return array; + } + + public void WriteDoubleArray(double[] array) + { + if ((array == null) || (array.Length == 0)) + { + WriteInt(0); + } + else + { + WriteInt(array.Length); + int length = array.Length; + for (int index = 0; index < length; index++) + { + WriteDouble(array[index]); + } + } + } + + public double[] ReadDoubleArray() + { + int size = ReadInt(); + double[] array = new double[size]; + if (size > 0) + { + for (int index = 0; index < size; index++) + { + array[index] = ReadLong(); + } + } + + return array; + } + + public void WriteCharArray(char[] array) + { + if ((array == null) || (array.Length == 0)) + { + WriteInt(0); + } + else + { + WriteInt(array.Length); + int length = array.Length; + for (int index = 0; index < length; index++) + { + WriteChar(array[index]); + } + } + } + + public char[] ReadCharArray() + { + int size = ReadInt(); + char[] array = new char[size]; + if (size > 0) + { + for (int index = 0; index < size; index++) + { + array[index] = ReadChar(); + } + } + + return array; + } + + public void WriteStringArray(string[] array) + { + if ((array == null) || (array.Length == 0)) + { + WriteInt(0); + } + else + { + WriteInt(array.Length); + int length = array.Length; + for (int index = 0; index < length; index++) + { + WriteString(array[index]); + } + } + } + + public string[] ReadStringArray() + { + int size = ReadInt(); + string[] array = new string[size]; + if (size > 0) + { + for (int index = 0; index < size; index++) + { + array[index] = ReadString(); + } + } + + return array; + } + + public void WritePacketArray(T[] array, short protocolId) + { + if ((array == null) || (array.Length == 0)) + { + WriteInt(0); + } + else + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + WriteInt(array.Length); + int length = array.Length; + for (int index = 0; index < length; index++) + { + protocolRegistration.Write(this, (IPacket) array[index]); + } + } + } + + public T[] ReadPacketArray(short protocolId) + { + int size = ReadInt(); + T[] array = new T[size]; + if (size > 0) + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + for (int index = 0; index < size; index++) + { + array[index] = (T) protocolRegistration.Read(this); + } + } + + return array; + } + + public void WriteBooleanList(List list) + { + if ((list == null) || (list.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(list.Count); + int length = list.Count; + for (int index = 0; index < length; index++) + { + WriteBool(list[index]); + } + } + } + + public List ReadBooleanList() + { + int size = ReadInt(); + List list = new List(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + list.Add(ReadBool()); + } + } + + return list; + } + + public void WriteByteList(List list) + { + if ((list == null) || (list.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(list.Count); + int length = list.Count; + for (int index = 0; index < length; index++) + { + WriteByte(list[index]); + } + } + } + + public List ReadByteList() + { + int size = ReadInt(); + List list = new List(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + list.Add(ReadByte()); + } + } + + return list; + } + + public void WriteShortList(List list) + { + if ((list == null) || (list.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(list.Count); + int length = list.Count; + for (int index = 0; index < length; index++) + { + WriteShort(list[index]); + } + } + } + + public List ReadShortList() + { + int size = ReadInt(); + List list = new List(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + list.Add(ReadShort()); + } + } + + return list; + } + + public void WriteIntList(List list) + { + if ((list == null) || (list.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(list.Count); + int length = list.Count; + for (int index = 0; index < length; index++) + { + WriteInt(list[index]); + } + } + } + + public List ReadIntList() + { + int size = ReadInt(); + List list = new List(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + list.Add(ReadInt()); + } + } + + return list; + } + + public void WriteLongList(List list) + { + if ((list == null) || (list.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(list.Count); + int length = list.Count; + for (int index = 0; index < length; index++) + { + WriteLong(list[index]); + } + } + } + + public List ReadLongList() + { + int size = ReadInt(); + List list = new List(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + list.Add(ReadLong()); + } + } + + return list; + } + + public void WriteFloatList(List list) + { + if ((list == null) || (list.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(list.Count); + int length = list.Count; + for (int index = 0; index < length; index++) + { + WriteFloat(list[index]); + } + } + } + + public List ReadFloatList() + { + int size = ReadInt(); + List list = new List(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + list.Add(ReadFloat()); + } + } + + return list; + } + + public void WriteDoubleList(List list) + { + if ((list == null) || (list.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(list.Count); + int length = list.Count; + for (int index = 0; index < length; index++) + { + WriteDouble(list[index]); + } + } + } + + public List ReadDoubleList() + { + int size = ReadInt(); + List list = new List(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + list.Add(ReadDouble()); + } + } + + return list; + } + + public void WriteCharList(List list) + { + if ((list == null) || (list.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(list.Count); + int length = list.Count; + for (int index = 0; index < length; index++) + { + WriteDouble(list[index]); + } + } + } + + public List ReadCharList() + { + int size = ReadInt(); + List list = new List(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + list.Add(ReadChar()); + } + } + + return list; + } + + public void WriteStringList(List list) + { + if ((list == null) || (list.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(list.Count); + int length = list.Count; + for (int index = 0; index < length; index++) + { + WriteString(list[index]); + } + } + } + + public List ReadStringList() + { + int size = ReadInt(); + List list = new List(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + list.Add(ReadString()); + } + } + + return list; + } + + public void WritePacketList(List list, short protocolId) + { + if ((list == null) || (list.Count == 0)) + { + WriteInt(0); + } + else + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + WriteInt(list.Count); + int length = list.Count; + for (int index = 0; index < length; index++) + { + protocolRegistration.Write(this, (IPacket) list[index]); + } + } + } + + public List ReadPacketList(short protocolId) + { + int size = ReadInt(); + List list = new List(size); + if (size > 0) + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + for (int index = 0; index < size; index++) + { + list.Add((T) protocolRegistration.Read(this)); + } + } + + return list; + } + + public void WriteBooleanSet(HashSet set) + { + if ((set == null) || (set.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(set.Count); + foreach (var element in set) + { + WriteBool(element); + } + } + } + + public HashSet ReadBooleanSet() + { + int size = ReadInt(); + HashSet set = new HashSet(); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + set.Add(ReadBool()); + } + } + + return set; + } + + public void WriteShortSet(HashSet set) + { + if ((set == null) || (set.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(set.Count); + foreach (var element in set) + { + WriteShort(element); + } + } + } + + public HashSet ReadShortSet() + { + int size = ReadInt(); + HashSet set = new HashSet(); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + set.Add(ReadShort()); + } + } + + return set; + } + + public void WriteIntSet(HashSet set) + { + if ((set == null) || (set.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(set.Count); + foreach (var element in set) + { + WriteInt(element); + } + } + } + + public HashSet ReadIntSet() + { + int size = ReadInt(); + HashSet set = new HashSet(); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + set.Add(ReadInt()); + } + } + + return set; + } + + public void WriteLongSet(HashSet set) + { + if ((set == null) || (set.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(set.Count); + foreach (var element in set) + { + WriteLong(element); + } + } + } + + public HashSet ReadLongSet() + { + int size = ReadInt(); + HashSet set = new HashSet(); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + set.Add(ReadLong()); + } + } + + return set; + } + + public void WriteFloatSet(HashSet set) + { + if ((set == null) || (set.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(set.Count); + foreach (var element in set) + { + WriteFloat(element); + } + } + } + + public HashSet ReadFloatSet() + { + int size = ReadInt(); + HashSet set = new HashSet(); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + set.Add(ReadFloat()); + } + } + + return set; + } + + public void WriteDoubleSet(HashSet set) + { + if ((set == null) || (set.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(set.Count); + foreach (var element in set) + { + WriteDouble(element); + } + } + } + + public HashSet ReadDoubleSet() + { + int size = ReadInt(); + HashSet set = new HashSet(); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + set.Add(ReadDouble()); + } + } + + return set; + } + + public void WriteCharSet(HashSet set) + { + if ((set == null) || (set.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(set.Count); + foreach (var element in set) + { + WriteChar(element); + } + } + } + + public HashSet ReadCharSet() + { + int size = ReadInt(); + HashSet set = new HashSet(); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + set.Add(ReadChar()); + } + } + + return set; + } + + public void WriteStringSet(HashSet set) + { + if ((set == null) || (set.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(set.Count); + foreach (var element in set) + { + WriteString(element); + } + } + } + + public HashSet ReadStringSet() + { + int size = ReadInt(); + HashSet set = new HashSet(); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + set.Add(ReadString()); + } + } + + return set; + } + + public void WritePacketSet(HashSet set, short protocolId) + { + if ((set == null) || (set.Count == 0)) + { + WriteInt(0); + } + else + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + WriteInt(set.Count); + foreach (var element in set) + { + protocolRegistration.Write(this, (IPacket) element); + } + } + } + + public HashSet ReadPacketSet(short protocolId) + { + int size = ReadInt(); + HashSet set = new HashSet(); + if (size > 0) + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + for (int index = 0; index < size; index++) + { + set.Add((T) protocolRegistration.Read(this)); + } + } + + return set; + } + + public void WriteIntIntMap(Dictionary map) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(map.Count); + foreach (var element in map) + { + WriteInt(element.Key); + WriteInt(element.Value); + } + } + } + + public Dictionary ReadIntIntMap() + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + var key = ReadInt(); + var value = ReadInt(); + map[key] = value; + } + } + + return map; + } + + public void WriteIntLongMap(Dictionary map) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(map.Count); + foreach (var element in map) + { + WriteInt(element.Key); + WriteLong(element.Value); + } + } + } + + public Dictionary ReadIntLongMap() + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + var key = ReadInt(); + var value = ReadLong(); + map[key] = value; + } + } + + return map; + } + + public void WriteIntStringMap(Dictionary map) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(map.Count); + foreach (var element in map) + { + WriteInt(element.Key); + WriteString(element.Value); + } + } + } + + public Dictionary ReadIntStringMap() + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + var key = ReadInt(); + var value = ReadString(); + map[key] = value; + } + } + + return map; + } + + + public void WriteIntPacketMap(Dictionary map, short protocolId) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + WriteInt(map.Count); + foreach (var element in map) + { + WriteInt(element.Key); + protocolRegistration.Write(this, (IPacket) element.Value); + } + } + } + + public Dictionary ReadIntPacketMap(short protocolId) + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + for (int index = 0; index < size; index++) + { + var key = ReadInt(); + var value = (T) protocolRegistration.Read(this); + map[key] = value; + } + } + + return map; + } + + public void WriteLongIntMap(Dictionary map) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(map.Count); + foreach (var element in map) + { + WriteLong(element.Key); + WriteInt(element.Value); + } + } + } + + public Dictionary ReadLongIntMap() + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + var key = ReadLong(); + var value = ReadInt(); + map[key] = value; + } + } + + return map; + } + + public void WriteLongLongMap(Dictionary map) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(map.Count); + foreach (var element in map) + { + WriteLong(element.Key); + WriteLong(element.Value); + } + } + } + + public Dictionary ReadLongLongMap() + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + var key = ReadLong(); + var value = ReadLong(); + map[key] = value; + } + } + + return map; + } + + public void WriteLongStringMap(Dictionary map) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(map.Count); + foreach (var element in map) + { + WriteLong(element.Key); + WriteString(element.Value); + } + } + } + + public Dictionary ReadLongStringMap() + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + var key = ReadLong(); + var value = ReadString(); + map[key] = value; + } + } + + return map; + } + + + public void WriteLongPacketMap(Dictionary map, short protocolId) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + WriteInt(map.Count); + foreach (var element in map) + { + WriteLong(element.Key); + protocolRegistration.Write(this, (IPacket) element.Value); + } + } + } + + public Dictionary ReadLongPacketMap(short protocolId) + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + for (int index = 0; index < size; index++) + { + var key = ReadLong(); + var value = (T) protocolRegistration.Read(this); + map[key] = value; + } + } + + return map; + } + + public void WriteStringIntMap(Dictionary map) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(map.Count); + foreach (var element in map) + { + WriteString(element.Key); + WriteInt(element.Value); + } + } + } + + public Dictionary ReadStringIntMap() + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + var key = ReadString(); + var value = ReadInt(); + map[key] = value; + } + } + + return map; + } + + public void WriteStringLongMap(Dictionary map) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(map.Count); + foreach (var element in map) + { + WriteString(element.Key); + WriteLong(element.Value); + } + } + } + + public Dictionary ReadStringLongMap() + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + var key = ReadString(); + var value = ReadLong(); + map[key] = value; + } + } + + return map; + } + + public void WriteStringStringMap(Dictionary map) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + WriteInt(map.Count); + foreach (var element in map) + { + WriteString(element.Key); + WriteString(element.Value); + } + } + } + + public Dictionary ReadStringStringMap() + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + for (int index = 0; index < size; index++) + { + var key = ReadString(); + var value = ReadString(); + map[key] = value; + } + } + + return map; + } + + + public void WriteStringPacketMap(Dictionary map, short protocolId) + { + if ((map == null) || (map.Count == 0)) + { + WriteInt(0); + } + else + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + WriteInt(map.Count); + foreach (var element in map) + { + WriteString(element.Key); + protocolRegistration.Write(this, (IPacket) element.Value); + } + } + } + + public Dictionary ReadStringPacketMap(short protocolId) + { + int size = ReadInt(); + Dictionary map = new Dictionary(size); + if (size > 0) + { + IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId); + for (int index = 0; index < size; index++) + { + var key = ReadString(); + var value = (T) protocolRegistration.Read(this); + map[key] = value; + } + } + + return map; + } } } \ No newline at end of file diff --git a/protocol/src/test/resources/csTest/CsProtocol/IPacket.cs b/protocol/src/test/resources/csTest/CsProtocol/IPacket.cs index 0d113ea1..c4f5c8c5 100644 --- a/protocol/src/test/resources/csTest/CsProtocol/IPacket.cs +++ b/protocol/src/test/resources/csTest/CsProtocol/IPacket.cs @@ -1,4 +1,4 @@ -namespace CsProtocol.Buffer +namespace CsProtocol.Buffer { public interface IPacket { diff --git a/protocol/src/test/resources/csTest/CsProtocol/IProtocolRegistration.cs b/protocol/src/test/resources/csTest/CsProtocol/IProtocolRegistration.cs index c3ec2439..7c257d33 100644 --- a/protocol/src/test/resources/csTest/CsProtocol/IProtocolRegistration.cs +++ b/protocol/src/test/resources/csTest/CsProtocol/IProtocolRegistration.cs @@ -1,4 +1,4 @@ -namespace CsProtocol.Buffer +namespace CsProtocol.Buffer { public interface IProtocolRegistration { diff --git a/protocol/src/test/resources/csTest/CsProtocol/Packet/ComplexObject.cs b/protocol/src/test/resources/csTest/CsProtocol/Packet/ComplexObject.cs index 9b33a3f3..9caab25e 100644 --- a/protocol/src/test/resources/csTest/CsProtocol/Packet/ComplexObject.cs +++ b/protocol/src/test/resources/csTest/CsProtocol/Packet/ComplexObject.cs @@ -8,8 +8,7 @@ namespace CsProtocol // 包括了各种复杂的结构,数组,List,Set,Map // // @author jaysunxiao - // @version 1.0 - // @since 2017 10.14 11:19 + // @version 3.0 public class ComplexObject : IPacket { // byte类型,最简单的整形 @@ -128,7 +127,7 @@ namespace CsProtocol public short ProtocolId() { - return 1160; + return 100; } } @@ -137,302 +136,53 @@ namespace CsProtocol { public short ProtocolId() { - return 1160; + return 100; } public void Write(ByteBuffer buffer, IPacket packet) { - if (packet == null) + if (buffer.WritePacketFlag(packet)) { - buffer.WriteBool(false); return; } - buffer.WriteBool(true); ComplexObject message = (ComplexObject) packet; buffer.WriteByte(message.a); buffer.WriteByte(message.aa); - if ((message.aaa == null) || (message.aaa.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.aaa.Length); - int length0 = message.aaa.Length; - for (int i1 = 0; i1 < length0; i1++) - { - byte element2 = message.aaa[i1]; - buffer.WriteByte(element2); - } - } - if ((message.aaaa == null) || (message.aaaa.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.aaaa.Length); - int length3 = message.aaaa.Length; - for (int i4 = 0; i4 < length3; i4++) - { - byte element5 = message.aaaa[i4]; - buffer.WriteByte(element5); - } - } + buffer.WriteByteArray(message.aaa); + buffer.WriteByteArray(message.aaaa); buffer.WriteShort(message.b); buffer.WriteShort(message.bb); - if ((message.bbb == null) || (message.bbb.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.bbb.Length); - int length6 = message.bbb.Length; - for (int i7 = 0; i7 < length6; i7++) - { - short element8 = message.bbb[i7]; - buffer.WriteShort(element8); - } - } - if ((message.bbbb == null) || (message.bbbb.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.bbbb.Length); - int length9 = message.bbbb.Length; - for (int i10 = 0; i10 < length9; i10++) - { - short element11 = message.bbbb[i10]; - buffer.WriteShort(element11); - } - } + buffer.WriteShortArray(message.bbb); + buffer.WriteShortArray(message.bbbb); buffer.WriteInt(message.c); buffer.WriteInt(message.cc); - if ((message.ccc == null) || (message.ccc.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.ccc.Length); - int length12 = message.ccc.Length; - for (int i13 = 0; i13 < length12; i13++) - { - int element14 = message.ccc[i13]; - buffer.WriteInt(element14); - } - } - if ((message.cccc == null) || (message.cccc.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.cccc.Length); - int length15 = message.cccc.Length; - for (int i16 = 0; i16 < length15; i16++) - { - int element17 = message.cccc[i16]; - buffer.WriteInt(element17); - } - } + buffer.WriteIntArray(message.ccc); + buffer.WriteIntArray(message.cccc); buffer.WriteLong(message.d); buffer.WriteLong(message.dd); - if ((message.ddd == null) || (message.ddd.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.ddd.Length); - int length18 = message.ddd.Length; - for (int i19 = 0; i19 < length18; i19++) - { - long element20 = message.ddd[i19]; - buffer.WriteLong(element20); - } - } - if ((message.dddd == null) || (message.dddd.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.dddd.Length); - int length21 = message.dddd.Length; - for (int i22 = 0; i22 < length21; i22++) - { - long element23 = message.dddd[i22]; - buffer.WriteLong(element23); - } - } + buffer.WriteLongArray(message.ddd); + buffer.WriteLongArray(message.dddd); buffer.WriteFloat(message.e); buffer.WriteFloat(message.ee); - if ((message.eee == null) || (message.eee.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.eee.Length); - int length24 = message.eee.Length; - for (int i25 = 0; i25 < length24; i25++) - { - float element26 = message.eee[i25]; - buffer.WriteFloat(element26); - } - } - if ((message.eeee == null) || (message.eeee.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.eeee.Length); - int length27 = message.eeee.Length; - for (int i28 = 0; i28 < length27; i28++) - { - float element29 = message.eeee[i28]; - buffer.WriteFloat(element29); - } - } + buffer.WriteFloatArray(message.eee); + buffer.WriteFloatArray(message.eeee); buffer.WriteDouble(message.f); buffer.WriteDouble(message.ff); - if ((message.fff == null) || (message.fff.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.fff.Length); - int length30 = message.fff.Length; - for (int i31 = 0; i31 < length30; i31++) - { - double element32 = message.fff[i31]; - buffer.WriteDouble(element32); - } - } - if ((message.ffff == null) || (message.ffff.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.ffff.Length); - int length33 = message.ffff.Length; - for (int i34 = 0; i34 < length33; i34++) - { - double element35 = message.ffff[i34]; - buffer.WriteDouble(element35); - } - } + buffer.WriteDoubleArray(message.fff); + buffer.WriteDoubleArray(message.ffff); buffer.WriteBool(message.g); buffer.WriteBool(message.gg); - if ((message.ggg == null) || (message.ggg.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.ggg.Length); - int length36 = message.ggg.Length; - for (int i37 = 0; i37 < length36; i37++) - { - bool element38 = message.ggg[i37]; - buffer.WriteBool(element38); - } - } - if ((message.gggg == null) || (message.gggg.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.gggg.Length); - int length39 = message.gggg.Length; - for (int i40 = 0; i40 < length39; i40++) - { - bool element41 = message.gggg[i40]; - buffer.WriteBool(element41); - } - } + buffer.WriteBooleanArray(message.ggg); + buffer.WriteBooleanArray(message.gggg); buffer.WriteChar(message.h); buffer.WriteChar(message.hh); - if ((message.hhh == null) || (message.hhh.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.hhh.Length); - int length42 = message.hhh.Length; - for (int i43 = 0; i43 < length42; i43++) - { - char element44 = message.hhh[i43]; - buffer.WriteChar(element44); - } - } - if ((message.hhhh == null) || (message.hhhh.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.hhhh.Length); - int length45 = message.hhhh.Length; - for (int i46 = 0; i46 < length45; i46++) - { - char element47 = message.hhhh[i46]; - buffer.WriteChar(element47); - } - } + buffer.WriteCharArray(message.hhh); + buffer.WriteCharArray(message.hhhh); buffer.WriteString(message.jj); - if ((message.jjj == null) || (message.jjj.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.jjj.Length); - int length48 = message.jjj.Length; - for (int i49 = 0; i49 < length48; i49++) - { - string element50 = message.jjj[i49]; - buffer.WriteString(element50); - } - } - ProtocolManager.GetProtocol(1116).Write(buffer, message.kk); - if ((message.kkk == null) || (message.kkk.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.kkk.Length); - int length51 = message.kkk.Length; - for (int i52 = 0; i52 < length51; i52++) - { - ObjectA element53 = message.kkk[i52]; - ProtocolManager.GetProtocol(1116).Write(buffer, element53); - } - } - if (message.l == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.l.Count); - int length54 = message.l.Count; - for (int i55 = 0; i55 < length54; i55++) - { - var element56 = message.l[i55]; - buffer.WriteInt(element56); - } - } + buffer.WriteStringArray(message.jjj); + ProtocolManager.GetProtocol(102).Write(buffer, message.kk); + buffer.WritePacketArray(message.kkk, 102); + buffer.WriteIntList(message.l); if (message.ll == null) { buffer.WriteInt(0); @@ -440,35 +190,22 @@ namespace CsProtocol else { buffer.WriteInt(message.ll.Count); - int length57 = message.ll.Count; - for (int i58 = 0; i58 < length57; i58++) + int length0 = message.ll.Count; + for (int i1 = 0; i1 < length0; i1++) { - var element59 = message.ll[i58]; - if (element59 == null) + var element2 = message.ll[i1]; + if (element2 == null) { buffer.WriteInt(0); } else { - buffer.WriteInt(element59.Count); - int length60 = element59.Count; - for (int i61 = 0; i61 < length60; i61++) + buffer.WriteInt(element2.Count); + int length3 = element2.Count; + for (int i4 = 0; i4 < length3; i4++) { - var element62 = element59[i61]; - if (element62 == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(element62.Count); - int length63 = element62.Count; - for (int i64 = 0; i64 < length63; i64++) - { - var element65 = element62[i64]; - buffer.WriteInt(element65); - } - } + var element5 = element2[i4]; + buffer.WriteIntList(element5); } } } @@ -480,40 +217,14 @@ namespace CsProtocol else { buffer.WriteInt(message.lll.Count); - int length66 = message.lll.Count; - for (int i67 = 0; i67 < length66; i67++) + int length6 = message.lll.Count; + for (int i7 = 0; i7 < length6; i7++) { - var element68 = message.lll[i67]; - if (element68 == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(element68.Count); - int length69 = element68.Count; - for (int i70 = 0; i70 < length69; i70++) - { - var element71 = element68[i70]; - ProtocolManager.GetProtocol(1116).Write(buffer, element71); - } - } - } - } - if (message.llll == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.llll.Count); - int length72 = message.llll.Count; - for (int i73 = 0; i73 < length72; i73++) - { - var element74 = message.llll[i73]; - buffer.WriteString(element74); + var element8 = message.lll[i7]; + buffer.WritePacketList(element8, 102); } } + buffer.WriteStringList(message.llll); if (message.lllll == null) { buffer.WriteInt(0); @@ -521,57 +232,15 @@ namespace CsProtocol else { buffer.WriteInt(message.lllll.Count); - int length75 = message.lllll.Count; - for (int i76 = 0; i76 < length75; i76++) + int length9 = message.lllll.Count; + for (int i10 = 0; i10 < length9; i10++) { - var element77 = message.lllll[i76]; - if ((element77 == null) || (element77.Count == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(element77.Count); - foreach (var i78 in element77) - { - var keyElement79 = i78.Key; - var valueElement80 = i78.Value; - buffer.WriteInt(keyElement79); - buffer.WriteString(valueElement80); - } - } - } - } - if ((message.m == null) || (message.m.Count == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.m.Count); - foreach (var i81 in message.m) - { - var keyElement82 = i81.Key; - var valueElement83 = i81.Value; - buffer.WriteInt(keyElement82); - buffer.WriteString(valueElement83); - } - } - if ((message.mm == null) || (message.mm.Count == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.mm.Count); - foreach (var i84 in message.mm) - { - var keyElement85 = i84.Key; - var valueElement86 = i84.Value; - buffer.WriteInt(keyElement85); - ProtocolManager.GetProtocol(1116).Write(buffer, valueElement86); + var element11 = message.lllll[i10]; + buffer.WriteIntStringMap(element11); } } + buffer.WriteIntStringMap(message.m); + buffer.WriteIntPacketMap(message.mm, 102); if ((message.mmm == null) || (message.mmm.Count == 0)) { buffer.WriteInt(0); @@ -579,25 +248,12 @@ namespace CsProtocol else { buffer.WriteInt(message.mmm.Count); - foreach (var i87 in message.mmm) + foreach (var i12 in message.mmm) { - var keyElement88 = i87.Key; - var valueElement89 = i87.Value; - ProtocolManager.GetProtocol(1116).Write(buffer, keyElement88); - if (valueElement89 == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(valueElement89.Count); - int length90 = valueElement89.Count; - for (int i91 = 0; i91 < length90; i91++) - { - var element92 = valueElement89[i91]; - buffer.WriteInt(element92); - } - } + var keyElement13 = i12.Key; + var valueElement14 = i12.Value; + ProtocolManager.GetProtocol(102).Write(buffer, keyElement13); + buffer.WriteIntList(valueElement14); } } if ((message.mmmm == null) || (message.mmmm.Count == 0)) @@ -607,73 +263,47 @@ namespace CsProtocol else { buffer.WriteInt(message.mmmm.Count); - foreach (var i93 in message.mmmm) + foreach (var i15 in message.mmmm) { - var keyElement94 = i93.Key; - var valueElement95 = i93.Value; - if (keyElement94 == null) + var keyElement16 = i15.Key; + var valueElement17 = i15.Value; + if (keyElement16 == null) { buffer.WriteInt(0); } else { - buffer.WriteInt(keyElement94.Count); - int length96 = keyElement94.Count; - for (int i97 = 0; i97 < length96; i97++) + buffer.WriteInt(keyElement16.Count); + int length18 = keyElement16.Count; + for (int i19 = 0; i19 < length18; i19++) { - var element98 = keyElement94[i97]; - if (element98 == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(element98.Count); - int length99 = element98.Count; - for (int i100 = 0; i100 < length99; i100++) - { - var element101 = element98[i100]; - ProtocolManager.GetProtocol(1116).Write(buffer, element101); - } - } + var element20 = keyElement16[i19]; + buffer.WritePacketList(element20, 102); } } - if (valueElement95 == null) + if (valueElement17 == null) { buffer.WriteInt(0); } else { - buffer.WriteInt(valueElement95.Count); - int length102 = valueElement95.Count; - for (int i103 = 0; i103 < length102; i103++) + buffer.WriteInt(valueElement17.Count); + int length21 = valueElement17.Count; + for (int i22 = 0; i22 < length21; i22++) { - var element104 = valueElement95[i103]; - if (element104 == null) + var element23 = valueElement17[i22]; + if (element23 == null) { buffer.WriteInt(0); } else { - buffer.WriteInt(element104.Count); - int length105 = element104.Count; - for (int i106 = 0; i106 < length105; i106++) + buffer.WriteInt(element23.Count); + int length24 = element23.Count; + for (int i25 = 0; i25 < length24; i25++) { - var element107 = element104[i106]; - if (element107 == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(element107.Count); - int length108 = element107.Count; - for (int i109 = 0; i109 < length108; i109++) - { - var element110 = element107[i109]; - buffer.WriteInt(element110); - } - } + var element26 = element23[i25]; + buffer.WriteIntList(element26); } } } @@ -687,78 +317,39 @@ namespace CsProtocol else { buffer.WriteInt(message.mmmmm.Count); - foreach (var i111 in message.mmmmm) + foreach (var i27 in message.mmmmm) { - var keyElement112 = i111.Key; - var valueElement113 = i111.Value; - if (keyElement112 == null) + var keyElement28 = i27.Key; + var valueElement29 = i27.Value; + if (keyElement28 == null) { buffer.WriteInt(0); } else { - buffer.WriteInt(keyElement112.Count); - int length114 = keyElement112.Count; - for (int i115 = 0; i115 < length114; i115++) + buffer.WriteInt(keyElement28.Count); + int length30 = keyElement28.Count; + for (int i31 = 0; i31 < length30; i31++) { - var element116 = keyElement112[i115]; - if ((element116 == null) || (element116.Count == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(element116.Count); - foreach (var i117 in element116) - { - var keyElement118 = i117.Key; - var valueElement119 = i117.Value; - buffer.WriteInt(keyElement118); - buffer.WriteString(valueElement119); - } - } + var element32 = keyElement28[i31]; + buffer.WriteIntStringMap(element32); } } - if (valueElement113 == null) + if (valueElement29 == null) { buffer.WriteInt(0); } else { - buffer.WriteInt(valueElement113.Count); - foreach (var i120 in valueElement113) + buffer.WriteInt(valueElement29.Count); + foreach (var i33 in valueElement29) { - if ((i120 == null) || (i120.Count == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(i120.Count); - foreach (var i121 in i120) - { - var keyElement122 = i121.Key; - var valueElement123 = i121.Value; - buffer.WriteInt(keyElement122); - buffer.WriteString(valueElement123); - } - } + buffer.WriteIntStringMap(i33); } } } } - if (message.s == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.s.Count); - foreach (var i124 in message.s) - { - buffer.WriteInt(i124); - } - } + buffer.WriteIntSet(message.s); if (message.ss == null) { buffer.WriteInt(0); @@ -766,31 +357,18 @@ namespace CsProtocol else { buffer.WriteInt(message.ss.Count); - foreach (var i125 in message.ss) + foreach (var i34 in message.ss) { - if (i125 == null) + if (i34 == null) { buffer.WriteInt(0); } else { - buffer.WriteInt(i125.Count); - foreach (var i126 in i125) + buffer.WriteInt(i34.Count); + foreach (var i35 in i34) { - if (i126 == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(i126.Count); - int length127 = i126.Count; - for (int i128 = 0; i128 < length127; i128++) - { - var element129 = i126[i128]; - buffer.WriteInt(element129); - } - } + buffer.WriteIntList(i35); } } } @@ -802,34 +380,12 @@ namespace CsProtocol else { buffer.WriteInt(message.sss.Count); - foreach (var i130 in message.sss) + foreach (var i36 in message.sss) { - if (i130 == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(i130.Count); - foreach (var i131 in i130) - { - ProtocolManager.GetProtocol(1116).Write(buffer, i131); - } - } - } - } - if (message.ssss == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.ssss.Count); - foreach (var i132 in message.ssss) - { - buffer.WriteString(i132); + buffer.WritePacketSet(i36, 102); } } + buffer.WriteStringSet(message.ssss); if (message.sssss == null) { buffer.WriteInt(0); @@ -837,23 +393,9 @@ namespace CsProtocol else { buffer.WriteInt(message.sssss.Count); - foreach (var i133 in message.sssss) + foreach (var i37 in message.sssss) { - if ((i133 == null) || (i133.Count == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(i133.Count); - foreach (var i134 in i133) - { - var keyElement135 = i134.Key; - var valueElement136 = i134.Value; - buffer.WriteInt(keyElement135); - buffer.WriteString(valueElement136); - } - } + buffer.WriteIntStringMap(i37); } } } @@ -865,576 +407,255 @@ namespace CsProtocol return null; } ComplexObject packet = new ComplexObject(); - byte result137 = buffer.ReadByte(); - packet.a = result137; - byte result138 = buffer.ReadByte(); - packet.aa = result138; - int size141 = buffer.ReadInt(); - byte[] result139 = new byte[size141]; - if (size141 > 0) + byte result38 = buffer.ReadByte(); + packet.a = result38; + byte result39 = buffer.ReadByte(); + packet.aa = result39; + var array40 = buffer.ReadByteArray(); + packet.aaa = array40; + var array41 = buffer.ReadByteArray(); + packet.aaaa = array41; + short result42 = buffer.ReadShort(); + packet.b = result42; + short result43 = buffer.ReadShort(); + packet.bb = result43; + var array44 = buffer.ReadShortArray(); + packet.bbb = array44; + var array45 = buffer.ReadShortArray(); + packet.bbbb = array45; + int result46 = buffer.ReadInt(); + packet.c = result46; + int result47 = buffer.ReadInt(); + packet.cc = result47; + var array48 = buffer.ReadIntArray(); + packet.ccc = array48; + var array49 = buffer.ReadIntArray(); + packet.cccc = array49; + long result50 = buffer.ReadLong(); + packet.d = result50; + long result51 = buffer.ReadLong(); + packet.dd = result51; + var array52 = buffer.ReadLongArray(); + packet.ddd = array52; + var array53 = buffer.ReadLongArray(); + packet.dddd = array53; + float result54 = buffer.ReadFloat(); + packet.e = result54; + float result55 = buffer.ReadFloat(); + packet.ee = result55; + var array56 = buffer.ReadFloatArray(); + packet.eee = array56; + var array57 = buffer.ReadFloatArray(); + packet.eeee = array57; + double result58 = buffer.ReadDouble(); + packet.f = result58; + double result59 = buffer.ReadDouble(); + packet.ff = result59; + var array60 = buffer.ReadDoubleArray(); + packet.fff = array60; + var array61 = buffer.ReadDoubleArray(); + packet.ffff = array61; + bool result62 = buffer.ReadBool(); + packet.g = result62; + bool result63 = buffer.ReadBool(); + packet.gg = result63; + var array64 = buffer.ReadBooleanArray(); + packet.ggg = array64; + var array65 = buffer.ReadBooleanArray(); + packet.gggg = array65; + char result66 = buffer.ReadChar(); + packet.h = result66; + char result67 = buffer.ReadChar(); + packet.hh = result67; + var array68 = buffer.ReadCharArray(); + packet.hhh = array68; + var array69 = buffer.ReadCharArray(); + packet.hhhh = array69; + string result70 = buffer.ReadString(); + packet.jj = result70; + var array71 = buffer.ReadStringArray(); + packet.jjj = array71; + ObjectA result72 = (ObjectA) ProtocolManager.GetProtocol(102).Read(buffer); + packet.kk = result72; + var array73 = buffer.ReadPacketArray(102); + packet.kkk = array73; + var list74 = buffer.ReadIntList(); + packet.l = list74; + int size77 = buffer.ReadInt(); + var result75 = new List>>(size77); + if (size77 > 0) { - for (int index140 = 0; index140 < size141; index140++) + for (int index76 = 0; index76 < size77; index76++) { - byte result142 = buffer.ReadByte(); - result139[index140] = result142; - } - } - packet.aaa = result139; - int size145 = buffer.ReadInt(); - byte[] result143 = new byte[size145]; - if (size145 > 0) - { - for (int index144 = 0; index144 < size145; index144++) - { - byte result146 = buffer.ReadByte(); - result143[index144] = result146; - } - } - packet.aaaa = result143; - short result147 = buffer.ReadShort(); - packet.b = result147; - short result148 = buffer.ReadShort(); - packet.bb = result148; - int size151 = buffer.ReadInt(); - short[] result149 = new short[size151]; - if (size151 > 0) - { - for (int index150 = 0; index150 < size151; index150++) - { - short result152 = buffer.ReadShort(); - result149[index150] = result152; - } - } - packet.bbb = result149; - int size155 = buffer.ReadInt(); - short[] result153 = new short[size155]; - if (size155 > 0) - { - for (int index154 = 0; index154 < size155; index154++) - { - short result156 = buffer.ReadShort(); - result153[index154] = result156; - } - } - packet.bbbb = result153; - int result157 = buffer.ReadInt(); - packet.c = result157; - int result158 = buffer.ReadInt(); - packet.cc = result158; - int size161 = buffer.ReadInt(); - int[] result159 = new int[size161]; - if (size161 > 0) - { - for (int index160 = 0; index160 < size161; index160++) - { - int result162 = buffer.ReadInt(); - result159[index160] = result162; - } - } - packet.ccc = result159; - int size165 = buffer.ReadInt(); - int[] result163 = new int[size165]; - if (size165 > 0) - { - for (int index164 = 0; index164 < size165; index164++) - { - int result166 = buffer.ReadInt(); - result163[index164] = result166; - } - } - packet.cccc = result163; - long result167 = buffer.ReadLong(); - packet.d = result167; - long result168 = buffer.ReadLong(); - packet.dd = result168; - int size171 = buffer.ReadInt(); - long[] result169 = new long[size171]; - if (size171 > 0) - { - for (int index170 = 0; index170 < size171; index170++) - { - long result172 = buffer.ReadLong(); - result169[index170] = result172; - } - } - packet.ddd = result169; - int size175 = buffer.ReadInt(); - long[] result173 = new long[size175]; - if (size175 > 0) - { - for (int index174 = 0; index174 < size175; index174++) - { - long result176 = buffer.ReadLong(); - result173[index174] = result176; - } - } - packet.dddd = result173; - float result177 = buffer.ReadFloat(); - packet.e = result177; - float result178 = buffer.ReadFloat(); - packet.ee = result178; - int size181 = buffer.ReadInt(); - float[] result179 = new float[size181]; - if (size181 > 0) - { - for (int index180 = 0; index180 < size181; index180++) - { - float result182 = buffer.ReadFloat(); - result179[index180] = result182; - } - } - packet.eee = result179; - int size185 = buffer.ReadInt(); - float[] result183 = new float[size185]; - if (size185 > 0) - { - for (int index184 = 0; index184 < size185; index184++) - { - float result186 = buffer.ReadFloat(); - result183[index184] = result186; - } - } - packet.eeee = result183; - double result187 = buffer.ReadDouble(); - packet.f = result187; - double result188 = buffer.ReadDouble(); - packet.ff = result188; - int size191 = buffer.ReadInt(); - double[] result189 = new double[size191]; - if (size191 > 0) - { - for (int index190 = 0; index190 < size191; index190++) - { - double result192 = buffer.ReadDouble(); - result189[index190] = result192; - } - } - packet.fff = result189; - int size195 = buffer.ReadInt(); - double[] result193 = new double[size195]; - if (size195 > 0) - { - for (int index194 = 0; index194 < size195; index194++) - { - double result196 = buffer.ReadDouble(); - result193[index194] = result196; - } - } - packet.ffff = result193; - bool result197 = buffer.ReadBool(); - packet.g = result197; - bool result198 = buffer.ReadBool(); - packet.gg = result198; - int size201 = buffer.ReadInt(); - bool[] result199 = new bool[size201]; - if (size201 > 0) - { - for (int index200 = 0; index200 < size201; index200++) - { - bool result202 = buffer.ReadBool(); - result199[index200] = result202; - } - } - packet.ggg = result199; - int size205 = buffer.ReadInt(); - bool[] result203 = new bool[size205]; - if (size205 > 0) - { - for (int index204 = 0; index204 < size205; index204++) - { - bool result206 = buffer.ReadBool(); - result203[index204] = result206; - } - } - packet.gggg = result203; - char result207 = buffer.ReadChar(); - packet.h = result207; - char result208 = buffer.ReadChar(); - packet.hh = result208; - int size211 = buffer.ReadInt(); - char[] result209 = new char[size211]; - if (size211 > 0) - { - for (int index210 = 0; index210 < size211; index210++) - { - char result212 = buffer.ReadChar(); - result209[index210] = result212; - } - } - packet.hhh = result209; - int size215 = buffer.ReadInt(); - char[] result213 = new char[size215]; - if (size215 > 0) - { - for (int index214 = 0; index214 < size215; index214++) - { - char result216 = buffer.ReadChar(); - result213[index214] = result216; - } - } - packet.hhhh = result213; - string result217 = buffer.ReadString(); - packet.jj = result217; - int size220 = buffer.ReadInt(); - string[] result218 = new string[size220]; - if (size220 > 0) - { - for (int index219 = 0; index219 < size220; index219++) - { - string result221 = buffer.ReadString(); - result218[index219] = result221; - } - } - packet.jjj = result218; - ObjectA result222 = (ObjectA) ProtocolManager.GetProtocol(1116).Read(buffer); - packet.kk = result222; - int size225 = buffer.ReadInt(); - ObjectA[] result223 = new ObjectA[size225]; - if (size225 > 0) - { - for (int index224 = 0; index224 < size225; index224++) - { - ObjectA result226 = (ObjectA) ProtocolManager.GetProtocol(1116).Read(buffer); - result223[index224] = result226; - } - } - packet.kkk = result223; - int size229 = buffer.ReadInt(); - var result227 = new List(size229); - if (size229 > 0) - { - for (int index228 = 0; index228 < size229; index228++) - { - int result230 = buffer.ReadInt(); - result227.Add(result230); - } - } - packet.l = result227; - int size233 = buffer.ReadInt(); - var result231 = new List>>(size233); - if (size233 > 0) - { - for (int index232 = 0; index232 < size233; index232++) - { - int size236 = buffer.ReadInt(); - var result234 = new List>(size236); - if (size236 > 0) + int size80 = buffer.ReadInt(); + var result78 = new List>(size80); + if (size80 > 0) { - for (int index235 = 0; index235 < size236; index235++) + for (int index79 = 0; index79 < size80; index79++) { - int size239 = buffer.ReadInt(); - var result237 = new List(size239); - if (size239 > 0) + var list81 = buffer.ReadIntList(); + result78.Add(list81); + } + } + result75.Add(result78); + } + } + packet.ll = result75; + int size84 = buffer.ReadInt(); + var result82 = new List>(size84); + if (size84 > 0) + { + for (int index83 = 0; index83 < size84; index83++) + { + var list85 = buffer.ReadPacketList(102); + result82.Add(list85); + } + } + packet.lll = result82; + var list86 = buffer.ReadStringList(); + packet.llll = list86; + int size89 = buffer.ReadInt(); + var result87 = new List>(size89); + if (size89 > 0) + { + for (int index88 = 0; index88 < size89; index88++) + { + var map90 = buffer.ReadIntStringMap(); + result87.Add(map90); + } + } + packet.lllll = result87; + var map91 = buffer.ReadIntStringMap(); + packet.m = map91; + var map92 = buffer.ReadIntPacketMap(102); + packet.mm = map92; + int size94 = buffer.ReadInt(); + var result93 = new Dictionary>(size94); + if (size94 > 0) + { + for (var index95 = 0; index95 < size94; index95++) + { + ObjectA result96 = (ObjectA) ProtocolManager.GetProtocol(102).Read(buffer); + var list97 = buffer.ReadIntList(); + result93[result96] = list97; + } + } + packet.mmm = result93; + int size99 = buffer.ReadInt(); + var result98 = new Dictionary>, List>>>(size99); + if (size99 > 0) + { + for (var index100 = 0; index100 < size99; index100++) + { + int size103 = buffer.ReadInt(); + var result101 = new List>(size103); + if (size103 > 0) + { + for (int index102 = 0; index102 < size103; index102++) + { + var list104 = buffer.ReadPacketList(102); + result101.Add(list104); + } + } + int size107 = buffer.ReadInt(); + var result105 = new List>>(size107); + if (size107 > 0) + { + for (int index106 = 0; index106 < size107; index106++) + { + int size110 = buffer.ReadInt(); + var result108 = new List>(size110); + if (size110 > 0) { - for (int index238 = 0; index238 < size239; index238++) + for (int index109 = 0; index109 < size110; index109++) { - int result240 = buffer.ReadInt(); - result237.Add(result240); + var list111 = buffer.ReadIntList(); + result108.Add(list111); } } - result234.Add(result237); + result105.Add(result108); } } - result231.Add(result234); + result98[result101] = result105; } } - packet.ll = result231; - int size243 = buffer.ReadInt(); - var result241 = new List>(size243); - if (size243 > 0) + packet.mmmm = result98; + int size113 = buffer.ReadInt(); + var result112 = new Dictionary>, HashSet>>(size113); + if (size113 > 0) { - for (int index242 = 0; index242 < size243; index242++) + for (var index114 = 0; index114 < size113; index114++) { - int size246 = buffer.ReadInt(); - var result244 = new List(size246); - if (size246 > 0) + int size117 = buffer.ReadInt(); + var result115 = new List>(size117); + if (size117 > 0) { - for (int index245 = 0; index245 < size246; index245++) + for (int index116 = 0; index116 < size117; index116++) { - ObjectA result247 = (ObjectA) ProtocolManager.GetProtocol(1116).Read(buffer); - result244.Add(result247); + var map118 = buffer.ReadIntStringMap(); + result115.Add(map118); } } - result241.Add(result244); - } - } - packet.lll = result241; - int size250 = buffer.ReadInt(); - var result248 = new List(size250); - if (size250 > 0) - { - for (int index249 = 0; index249 < size250; index249++) - { - string result251 = buffer.ReadString(); - result248.Add(result251); - } - } - packet.llll = result248; - int size254 = buffer.ReadInt(); - var result252 = new List>(size254); - if (size254 > 0) - { - for (int index253 = 0; index253 < size254; index253++) - { - int size256 = buffer.ReadInt(); - var result255 = new Dictionary(size256); - if (size256 > 0) + int size121 = buffer.ReadInt(); + var result119 = new HashSet>(); + if (size121 > 0) { - for (var index257 = 0; index257 < size256; index257++) + for (int index120 = 0; index120 < size121; index120++) { - int result258 = buffer.ReadInt(); - string result259 = buffer.ReadString(); - result255[result258] = result259; + var map122 = buffer.ReadIntStringMap(); + result119.Add(map122); } } - result252.Add(result255); + result112[result115] = result119; } } - packet.lllll = result252; - int size261 = buffer.ReadInt(); - var result260 = new Dictionary(size261); - if (size261 > 0) + packet.mmmmm = result112; + var set123 = buffer.ReadIntSet(); + packet.s = set123; + int size126 = buffer.ReadInt(); + var result124 = new HashSet>>(); + if (size126 > 0) { - for (var index262 = 0; index262 < size261; index262++) + for (int index125 = 0; index125 < size126; index125++) { - int result263 = buffer.ReadInt(); - string result264 = buffer.ReadString(); - result260[result263] = result264; - } - } - packet.m = result260; - int size266 = buffer.ReadInt(); - var result265 = new Dictionary(size266); - if (size266 > 0) - { - for (var index267 = 0; index267 < size266; index267++) - { - int result268 = buffer.ReadInt(); - ObjectA result269 = (ObjectA) ProtocolManager.GetProtocol(1116).Read(buffer); - result265[result268] = result269; - } - } - packet.mm = result265; - int size271 = buffer.ReadInt(); - var result270 = new Dictionary>(size271); - if (size271 > 0) - { - for (var index272 = 0; index272 < size271; index272++) - { - ObjectA result273 = (ObjectA) ProtocolManager.GetProtocol(1116).Read(buffer); - int size276 = buffer.ReadInt(); - var result274 = new List(size276); - if (size276 > 0) + int size129 = buffer.ReadInt(); + var result127 = new HashSet>(); + if (size129 > 0) { - for (int index275 = 0; index275 < size276; index275++) + for (int index128 = 0; index128 < size129; index128++) { - int result277 = buffer.ReadInt(); - result274.Add(result277); + var list130 = buffer.ReadIntList(); + result127.Add(list130); } } - result270[result273] = result274; + result124.Add(result127); } } - packet.mmm = result270; - int size279 = buffer.ReadInt(); - var result278 = new Dictionary>, List>>>(size279); - if (size279 > 0) + packet.ss = result124; + int size133 = buffer.ReadInt(); + var result131 = new HashSet>(); + if (size133 > 0) { - for (var index280 = 0; index280 < size279; index280++) + for (int index132 = 0; index132 < size133; index132++) { - int size283 = buffer.ReadInt(); - var result281 = new List>(size283); - if (size283 > 0) - { - for (int index282 = 0; index282 < size283; index282++) - { - int size286 = buffer.ReadInt(); - var result284 = new List(size286); - if (size286 > 0) - { - for (int index285 = 0; index285 < size286; index285++) - { - ObjectA result287 = (ObjectA) ProtocolManager.GetProtocol(1116).Read(buffer); - result284.Add(result287); - } - } - result281.Add(result284); - } - } - int size290 = buffer.ReadInt(); - var result288 = new List>>(size290); - if (size290 > 0) - { - for (int index289 = 0; index289 < size290; index289++) - { - int size293 = buffer.ReadInt(); - var result291 = new List>(size293); - if (size293 > 0) - { - for (int index292 = 0; index292 < size293; index292++) - { - int size296 = buffer.ReadInt(); - var result294 = new List(size296); - if (size296 > 0) - { - for (int index295 = 0; index295 < size296; index295++) - { - int result297 = buffer.ReadInt(); - result294.Add(result297); - } - } - result291.Add(result294); - } - } - result288.Add(result291); - } - } - result278[result281] = result288; + var set134 = buffer.ReadPacketSet(102); + result131.Add(set134); } } - packet.mmmm = result278; - int size299 = buffer.ReadInt(); - var result298 = new Dictionary>, HashSet>>(size299); - if (size299 > 0) + packet.sss = result131; + var set135 = buffer.ReadStringSet(); + packet.ssss = set135; + int size138 = buffer.ReadInt(); + var result136 = new HashSet>(); + if (size138 > 0) { - for (var index300 = 0; index300 < size299; index300++) + for (int index137 = 0; index137 < size138; index137++) { - int size303 = buffer.ReadInt(); - var result301 = new List>(size303); - if (size303 > 0) - { - for (int index302 = 0; index302 < size303; index302++) - { - int size305 = buffer.ReadInt(); - var result304 = new Dictionary(size305); - if (size305 > 0) - { - for (var index306 = 0; index306 < size305; index306++) - { - int result307 = buffer.ReadInt(); - string result308 = buffer.ReadString(); - result304[result307] = result308; - } - } - result301.Add(result304); - } - } - int size311 = buffer.ReadInt(); - var result309 = new HashSet>(); - if (size311 > 0) - { - for (int index310 = 0; index310 < size311; index310++) - { - int size313 = buffer.ReadInt(); - var result312 = new Dictionary(size313); - if (size313 > 0) - { - for (var index314 = 0; index314 < size313; index314++) - { - int result315 = buffer.ReadInt(); - string result316 = buffer.ReadString(); - result312[result315] = result316; - } - } - result309.Add(result312); - } - } - result298[result301] = result309; + var map139 = buffer.ReadIntStringMap(); + result136.Add(map139); } } - packet.mmmmm = result298; - int size319 = buffer.ReadInt(); - var result317 = new HashSet(); - if (size319 > 0) - { - for (int index318 = 0; index318 < size319; index318++) - { - int result320 = buffer.ReadInt(); - result317.Add(result320); - } - } - packet.s = result317; - int size323 = buffer.ReadInt(); - var result321 = new HashSet>>(); - if (size323 > 0) - { - for (int index322 = 0; index322 < size323; index322++) - { - int size326 = buffer.ReadInt(); - var result324 = new HashSet>(); - if (size326 > 0) - { - for (int index325 = 0; index325 < size326; index325++) - { - int size329 = buffer.ReadInt(); - var result327 = new List(size329); - if (size329 > 0) - { - for (int index328 = 0; index328 < size329; index328++) - { - int result330 = buffer.ReadInt(); - result327.Add(result330); - } - } - result324.Add(result327); - } - } - result321.Add(result324); - } - } - packet.ss = result321; - int size333 = buffer.ReadInt(); - var result331 = new HashSet>(); - if (size333 > 0) - { - for (int index332 = 0; index332 < size333; index332++) - { - int size336 = buffer.ReadInt(); - var result334 = new HashSet(); - if (size336 > 0) - { - for (int index335 = 0; index335 < size336; index335++) - { - ObjectA result337 = (ObjectA) ProtocolManager.GetProtocol(1116).Read(buffer); - result334.Add(result337); - } - } - result331.Add(result334); - } - } - packet.sss = result331; - int size340 = buffer.ReadInt(); - var result338 = new HashSet(); - if (size340 > 0) - { - for (int index339 = 0; index339 < size340; index339++) - { - string result341 = buffer.ReadString(); - result338.Add(result341); - } - } - packet.ssss = result338; - int size344 = buffer.ReadInt(); - var result342 = new HashSet>(); - if (size344 > 0) - { - for (int index343 = 0; index343 < size344; index343++) - { - int size346 = buffer.ReadInt(); - var result345 = new Dictionary(size346); - if (size346 > 0) - { - for (var index347 = 0; index347 < size346; index347++) - { - int result348 = buffer.ReadInt(); - string result349 = buffer.ReadString(); - result345[result348] = result349; - } - } - result342.Add(result345); - } - } - packet.sssss = result342; + packet.sssss = result136; return packet; } } diff --git a/protocol/src/test/resources/csTest/CsProtocol/Packet/NormalObject.cs b/protocol/src/test/resources/csTest/CsProtocol/Packet/NormalObject.cs index 90b4eff6..f4129f54 100644 --- a/protocol/src/test/resources/csTest/CsProtocol/Packet/NormalObject.cs +++ b/protocol/src/test/resources/csTest/CsProtocol/Packet/NormalObject.cs @@ -5,61 +5,44 @@ using CsProtocol.Buffer; namespace CsProtocol { // @author jaysunxiao - // @version 1.0 - // @since 2021-02-07 17:18 + // @version 3.0 public class NormalObject : IPacket { public byte a; public byte[] aaa; public short b; - public short[] bbb; public int c; - public int[] ccc; public long d; - public long[] ddd; public float e; - public float[] eee; public double f; - public double[] fff; public bool g; - public bool[] ggg; - public char h; - public char[] hhh; public string jj; - public string[] jjj; public ObjectA kk; - public ObjectA[] kkk; public List l; + public List ll; + public List lll; public List llll; public Dictionary m; public Dictionary mm; public HashSet s; public HashSet ssss; - public static NormalObject ValueOf(byte a, byte[] aaa, short b, short[] bbb, int c, int[] ccc, long d, long[] ddd, float e, float[] eee, double f, double[] fff, bool g, bool[] ggg, char h, char[] hhh, string jj, string[] jjj, ObjectA kk, ObjectA[] kkk, List l, List llll, Dictionary m, Dictionary mm, HashSet s, HashSet ssss) + public static NormalObject ValueOf(byte a, byte[] aaa, short b, int c, long d, float e, double f, bool g, string jj, ObjectA kk, List l, List ll, List lll, List llll, Dictionary m, Dictionary mm, HashSet s, HashSet ssss) { var packet = new NormalObject(); packet.a = a; packet.aaa = aaa; packet.b = b; - packet.bbb = bbb; packet.c = c; - packet.ccc = ccc; packet.d = d; - packet.ddd = ddd; packet.e = e; - packet.eee = eee; packet.f = f; - packet.fff = fff; packet.g = g; - packet.ggg = ggg; - packet.h = h; - packet.hhh = hhh; packet.jj = jj; - packet.jjj = jjj; packet.kk = kk; - packet.kkk = kkk; packet.l = l; + packet.ll = ll; + packet.lll = lll; packet.llll = llll; packet.m = m; packet.mm = mm; @@ -71,7 +54,7 @@ namespace CsProtocol public short ProtocolId() { - return 1161; + return 101; } } @@ -80,250 +63,34 @@ namespace CsProtocol { public short ProtocolId() { - return 1161; + return 101; } public void Write(ByteBuffer buffer, IPacket packet) { - if (packet == null) + if (buffer.WritePacketFlag(packet)) { - buffer.WriteBool(false); return; } - buffer.WriteBool(true); NormalObject message = (NormalObject) packet; buffer.WriteByte(message.a); - if ((message.aaa == null) || (message.aaa.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.aaa.Length); - int length0 = message.aaa.Length; - for (int i1 = 0; i1 < length0; i1++) - { - byte element2 = message.aaa[i1]; - buffer.WriteByte(element2); - } - } + buffer.WriteByteArray(message.aaa); buffer.WriteShort(message.b); - if ((message.bbb == null) || (message.bbb.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.bbb.Length); - int length3 = message.bbb.Length; - for (int i4 = 0; i4 < length3; i4++) - { - short element5 = message.bbb[i4]; - buffer.WriteShort(element5); - } - } buffer.WriteInt(message.c); - if ((message.ccc == null) || (message.ccc.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.ccc.Length); - int length6 = message.ccc.Length; - for (int i7 = 0; i7 < length6; i7++) - { - int element8 = message.ccc[i7]; - buffer.WriteInt(element8); - } - } buffer.WriteLong(message.d); - if ((message.ddd == null) || (message.ddd.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.ddd.Length); - int length9 = message.ddd.Length; - for (int i10 = 0; i10 < length9; i10++) - { - long element11 = message.ddd[i10]; - buffer.WriteLong(element11); - } - } buffer.WriteFloat(message.e); - if ((message.eee == null) || (message.eee.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.eee.Length); - int length12 = message.eee.Length; - for (int i13 = 0; i13 < length12; i13++) - { - float element14 = message.eee[i13]; - buffer.WriteFloat(element14); - } - } buffer.WriteDouble(message.f); - if ((message.fff == null) || (message.fff.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.fff.Length); - int length15 = message.fff.Length; - for (int i16 = 0; i16 < length15; i16++) - { - double element17 = message.fff[i16]; - buffer.WriteDouble(element17); - } - } buffer.WriteBool(message.g); - if ((message.ggg == null) || (message.ggg.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.ggg.Length); - int length18 = message.ggg.Length; - for (int i19 = 0; i19 < length18; i19++) - { - bool element20 = message.ggg[i19]; - buffer.WriteBool(element20); - } - } - buffer.WriteChar(message.h); - if ((message.hhh == null) || (message.hhh.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.hhh.Length); - int length21 = message.hhh.Length; - for (int i22 = 0; i22 < length21; i22++) - { - char element23 = message.hhh[i22]; - buffer.WriteChar(element23); - } - } buffer.WriteString(message.jj); - if ((message.jjj == null) || (message.jjj.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.jjj.Length); - int length24 = message.jjj.Length; - for (int i25 = 0; i25 < length24; i25++) - { - string element26 = message.jjj[i25]; - buffer.WriteString(element26); - } - } - ProtocolManager.GetProtocol(1116).Write(buffer, message.kk); - if ((message.kkk == null) || (message.kkk.Length == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.kkk.Length); - int length27 = message.kkk.Length; - for (int i28 = 0; i28 < length27; i28++) - { - ObjectA element29 = message.kkk[i28]; - ProtocolManager.GetProtocol(1116).Write(buffer, element29); - } - } - if (message.l == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.l.Count); - int length30 = message.l.Count; - for (int i31 = 0; i31 < length30; i31++) - { - var element32 = message.l[i31]; - buffer.WriteInt(element32); - } - } - if (message.llll == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.llll.Count); - int length33 = message.llll.Count; - for (int i34 = 0; i34 < length33; i34++) - { - var element35 = message.llll[i34]; - buffer.WriteString(element35); - } - } - if ((message.m == null) || (message.m.Count == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.m.Count); - foreach (var i36 in message.m) - { - var keyElement37 = i36.Key; - var valueElement38 = i36.Value; - buffer.WriteInt(keyElement37); - buffer.WriteString(valueElement38); - } - } - if ((message.mm == null) || (message.mm.Count == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.mm.Count); - foreach (var i39 in message.mm) - { - var keyElement40 = i39.Key; - var valueElement41 = i39.Value; - buffer.WriteInt(keyElement40); - ProtocolManager.GetProtocol(1116).Write(buffer, valueElement41); - } - } - if (message.s == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.s.Count); - foreach (var i42 in message.s) - { - buffer.WriteInt(i42); - } - } - if (message.ssss == null) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.ssss.Count); - foreach (var i43 in message.ssss) - { - buffer.WriteString(i43); - } - } + ProtocolManager.GetProtocol(102).Write(buffer, message.kk); + buffer.WriteIntList(message.l); + buffer.WriteLongList(message.ll); + buffer.WritePacketList(message.lll, 102); + buffer.WriteStringList(message.llll); + buffer.WriteIntStringMap(message.m); + buffer.WriteIntPacketMap(message.mm, 102); + buffer.WriteIntSet(message.s); + buffer.WriteStringSet(message.ssss); } public IPacket Read(ByteBuffer buffer) @@ -333,204 +100,42 @@ namespace CsProtocol return null; } NormalObject packet = new NormalObject(); - byte result44 = buffer.ReadByte(); - packet.a = result44; - int size47 = buffer.ReadInt(); - byte[] result45 = new byte[size47]; - if (size47 > 0) - { - for (int index46 = 0; index46 < size47; index46++) - { - byte result48 = buffer.ReadByte(); - result45[index46] = result48; - } - } - packet.aaa = result45; - short result49 = buffer.ReadShort(); - packet.b = result49; - int size52 = buffer.ReadInt(); - short[] result50 = new short[size52]; - if (size52 > 0) - { - for (int index51 = 0; index51 < size52; index51++) - { - short result53 = buffer.ReadShort(); - result50[index51] = result53; - } - } - packet.bbb = result50; - int result54 = buffer.ReadInt(); - packet.c = result54; - int size57 = buffer.ReadInt(); - int[] result55 = new int[size57]; - if (size57 > 0) - { - for (int index56 = 0; index56 < size57; index56++) - { - int result58 = buffer.ReadInt(); - result55[index56] = result58; - } - } - packet.ccc = result55; - long result59 = buffer.ReadLong(); - packet.d = result59; - int size62 = buffer.ReadInt(); - long[] result60 = new long[size62]; - if (size62 > 0) - { - for (int index61 = 0; index61 < size62; index61++) - { - long result63 = buffer.ReadLong(); - result60[index61] = result63; - } - } - packet.ddd = result60; - float result64 = buffer.ReadFloat(); - packet.e = result64; - int size67 = buffer.ReadInt(); - float[] result65 = new float[size67]; - if (size67 > 0) - { - for (int index66 = 0; index66 < size67; index66++) - { - float result68 = buffer.ReadFloat(); - result65[index66] = result68; - } - } - packet.eee = result65; - double result69 = buffer.ReadDouble(); - packet.f = result69; - int size72 = buffer.ReadInt(); - double[] result70 = new double[size72]; - if (size72 > 0) - { - for (int index71 = 0; index71 < size72; index71++) - { - double result73 = buffer.ReadDouble(); - result70[index71] = result73; - } - } - packet.fff = result70; - bool result74 = buffer.ReadBool(); - packet.g = result74; - int size77 = buffer.ReadInt(); - bool[] result75 = new bool[size77]; - if (size77 > 0) - { - for (int index76 = 0; index76 < size77; index76++) - { - bool result78 = buffer.ReadBool(); - result75[index76] = result78; - } - } - packet.ggg = result75; - char result79 = buffer.ReadChar(); - packet.h = result79; - int size82 = buffer.ReadInt(); - char[] result80 = new char[size82]; - if (size82 > 0) - { - for (int index81 = 0; index81 < size82; index81++) - { - char result83 = buffer.ReadChar(); - result80[index81] = result83; - } - } - packet.hhh = result80; - string result84 = buffer.ReadString(); - packet.jj = result84; - int size87 = buffer.ReadInt(); - string[] result85 = new string[size87]; - if (size87 > 0) - { - for (int index86 = 0; index86 < size87; index86++) - { - string result88 = buffer.ReadString(); - result85[index86] = result88; - } - } - packet.jjj = result85; - ObjectA result89 = (ObjectA) ProtocolManager.GetProtocol(1116).Read(buffer); - packet.kk = result89; - int size92 = buffer.ReadInt(); - ObjectA[] result90 = new ObjectA[size92]; - if (size92 > 0) - { - for (int index91 = 0; index91 < size92; index91++) - { - ObjectA result93 = (ObjectA) ProtocolManager.GetProtocol(1116).Read(buffer); - result90[index91] = result93; - } - } - packet.kkk = result90; - int size96 = buffer.ReadInt(); - var result94 = new List(size96); - if (size96 > 0) - { - for (int index95 = 0; index95 < size96; index95++) - { - int result97 = buffer.ReadInt(); - result94.Add(result97); - } - } - packet.l = result94; - int size100 = buffer.ReadInt(); - var result98 = new List(size100); - if (size100 > 0) - { - for (int index99 = 0; index99 < size100; index99++) - { - string result101 = buffer.ReadString(); - result98.Add(result101); - } - } - packet.llll = result98; - int size103 = buffer.ReadInt(); - var result102 = new Dictionary(size103); - if (size103 > 0) - { - for (var index104 = 0; index104 < size103; index104++) - { - int result105 = buffer.ReadInt(); - string result106 = buffer.ReadString(); - result102[result105] = result106; - } - } - packet.m = result102; - int size108 = buffer.ReadInt(); - var result107 = new Dictionary(size108); - if (size108 > 0) - { - for (var index109 = 0; index109 < size108; index109++) - { - int result110 = buffer.ReadInt(); - ObjectA result111 = (ObjectA) ProtocolManager.GetProtocol(1116).Read(buffer); - result107[result110] = result111; - } - } - packet.mm = result107; - int size114 = buffer.ReadInt(); - var result112 = new HashSet(); - if (size114 > 0) - { - for (int index113 = 0; index113 < size114; index113++) - { - int result115 = buffer.ReadInt(); - result112.Add(result115); - } - } - packet.s = result112; - int size118 = buffer.ReadInt(); - var result116 = new HashSet(); - if (size118 > 0) - { - for (int index117 = 0; index117 < size118; index117++) - { - string result119 = buffer.ReadString(); - result116.Add(result119); - } - } - packet.ssss = result116; + byte result0 = buffer.ReadByte(); + packet.a = result0; + var array1 = buffer.ReadByteArray(); + packet.aaa = array1; + short result2 = buffer.ReadShort(); + packet.b = result2; + int result3 = buffer.ReadInt(); + packet.c = result3; + long result4 = buffer.ReadLong(); + packet.d = result4; + float result5 = buffer.ReadFloat(); + packet.e = result5; + double result6 = buffer.ReadDouble(); + packet.f = result6; + bool result7 = buffer.ReadBool(); + packet.g = result7; + string result8 = buffer.ReadString(); + packet.jj = result8; + ObjectA result9 = (ObjectA) ProtocolManager.GetProtocol(102).Read(buffer); + packet.kk = result9; + var list10 = buffer.ReadIntList(); + packet.l = list10; + var list11 = buffer.ReadLongList(); + packet.ll = list11; + var list12 = buffer.ReadPacketList(102); + packet.lll = list12; + var list13 = buffer.ReadStringList(); + packet.llll = list13; + var map14 = buffer.ReadIntStringMap(); + packet.m = map14; + var map15 = buffer.ReadIntPacketMap(102); + packet.mm = map15; + var set16 = buffer.ReadIntSet(); + packet.s = set16; + var set17 = buffer.ReadStringSet(); + packet.ssss = set17; return packet; } } diff --git a/protocol/src/test/resources/csTest/CsProtocol/Packet/ObjectA.cs b/protocol/src/test/resources/csTest/CsProtocol/Packet/ObjectA.cs index 0e4e9c6d..fe134d6f 100644 --- a/protocol/src/test/resources/csTest/CsProtocol/Packet/ObjectA.cs +++ b/protocol/src/test/resources/csTest/CsProtocol/Packet/ObjectA.cs @@ -5,8 +5,7 @@ using CsProtocol.Buffer; namespace CsProtocol { // @author jaysunxiao - // @version 1.0 - // @since 2017 10.12 15:39 + // @version 3.0 public class ObjectA : IPacket { public int a; @@ -25,7 +24,7 @@ namespace CsProtocol public short ProtocolId() { - return 1116; + return 102; } } @@ -34,35 +33,19 @@ namespace CsProtocol { public short ProtocolId() { - return 1116; + return 102; } public void Write(ByteBuffer buffer, IPacket packet) { - if (packet == null) + if (buffer.WritePacketFlag(packet)) { - buffer.WriteBool(false); return; } - buffer.WriteBool(true); ObjectA message = (ObjectA) packet; buffer.WriteInt(message.a); - if ((message.m == null) || (message.m.Count == 0)) - { - buffer.WriteInt(0); - } - else - { - buffer.WriteInt(message.m.Count); - foreach (var i0 in message.m) - { - var keyElement1 = i0.Key; - var valueElement2 = i0.Value; - buffer.WriteInt(keyElement1); - buffer.WriteString(valueElement2); - } - } - ProtocolManager.GetProtocol(1117).Write(buffer, message.objectB); + buffer.WriteIntStringMap(message.m); + ProtocolManager.GetProtocol(103).Write(buffer, message.objectB); } public IPacket Read(ByteBuffer buffer) @@ -72,22 +55,12 @@ namespace CsProtocol return null; } ObjectA packet = new ObjectA(); - int result3 = buffer.ReadInt(); - packet.a = result3; - int size5 = buffer.ReadInt(); - var result4 = new Dictionary(size5); - if (size5 > 0) - { - for (var index6 = 0; index6 < size5; index6++) - { - int result7 = buffer.ReadInt(); - string result8 = buffer.ReadString(); - result4[result7] = result8; - } - } - packet.m = result4; - ObjectB result9 = (ObjectB) ProtocolManager.GetProtocol(1117).Read(buffer); - packet.objectB = result9; + int result0 = buffer.ReadInt(); + packet.a = result0; + var map1 = buffer.ReadIntStringMap(); + packet.m = map1; + ObjectB result2 = (ObjectB) ProtocolManager.GetProtocol(103).Read(buffer); + packet.objectB = result2; return packet; } } diff --git a/protocol/src/test/resources/csTest/CsProtocol/Packet/ObjectB.cs b/protocol/src/test/resources/csTest/CsProtocol/Packet/ObjectB.cs index f4401cec..fe38bd06 100644 --- a/protocol/src/test/resources/csTest/CsProtocol/Packet/ObjectB.cs +++ b/protocol/src/test/resources/csTest/CsProtocol/Packet/ObjectB.cs @@ -5,8 +5,7 @@ using CsProtocol.Buffer; namespace CsProtocol { // @author jaysunxiao - // @version 1.0 - // @since 2017 10.12 15:39 + // @version 3.0 public class ObjectB : IPacket { public bool flag; @@ -21,7 +20,7 @@ namespace CsProtocol public short ProtocolId() { - return 1117; + return 103; } } @@ -30,17 +29,15 @@ namespace CsProtocol { public short ProtocolId() { - return 1117; + return 103; } public void Write(ByteBuffer buffer, IPacket packet) { - if (packet == null) + if (buffer.WritePacketFlag(packet)) { - buffer.WriteBool(false); return; } - buffer.WriteBool(true); ObjectB message = (ObjectB) packet; buffer.WriteBool(message.flag); } diff --git a/protocol/src/test/resources/csTest/CsProtocol/Packet/SimpleObject.cs b/protocol/src/test/resources/csTest/CsProtocol/Packet/SimpleObject.cs index 51aef542..0d0a67ed 100644 --- a/protocol/src/test/resources/csTest/CsProtocol/Packet/SimpleObject.cs +++ b/protocol/src/test/resources/csTest/CsProtocol/Packet/SimpleObject.cs @@ -5,8 +5,7 @@ using CsProtocol.Buffer; namespace CsProtocol { // @author jaysunxiao - // @version 1.0 - // @since 2021-03-27 15:18 + // @version 3.0 public class SimpleObject : IPacket { public int c; @@ -23,7 +22,7 @@ namespace CsProtocol public short ProtocolId() { - return 1163; + return 104; } } @@ -32,17 +31,15 @@ namespace CsProtocol { public short ProtocolId() { - return 1163; + return 104; } public void Write(ByteBuffer buffer, IPacket packet) { - if (packet == null) + if (buffer.WritePacketFlag(packet)) { - buffer.WriteBool(false); return; } - buffer.WriteBool(true); SimpleObject message = (SimpleObject) packet; buffer.WriteInt(message.c); buffer.WriteBool(message.g); diff --git a/protocol/src/test/resources/csTest/CsProtocol/ProtocolManager.cs b/protocol/src/test/resources/csTest/CsProtocol/ProtocolManager.cs index fe33cf75..f35909ec 100644 --- a/protocol/src/test/resources/csTest/CsProtocol/ProtocolManager.cs +++ b/protocol/src/test/resources/csTest/CsProtocol/ProtocolManager.cs @@ -50,20 +50,20 @@ namespace CsProtocol return protocol; } - public static void Write(ByteBuffer byteBuffer, IPacket packet) + public static void Write(ByteBuffer buffer, IPacket packet) { var protocolId = packet.ProtocolId(); // 写入协议号 - byteBuffer.WriteShort(protocolId); + buffer.WriteShort(protocolId); // 写入包体 - GetProtocol(protocolId).Write(byteBuffer, packet); + GetProtocol(protocolId).Write(buffer, packet); } - public static IPacket Read(ByteBuffer byteBuffer) + public static IPacket Read(ByteBuffer buffer) { - var protocolId = byteBuffer.ReadShort(); - return GetProtocol(protocolId).Read(byteBuffer); + var protocolId = buffer.ReadShort(); + return GetProtocol(protocolId).Read(buffer); } } } \ No newline at end of file