mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-20 14:24:50 +00:00
feat[net]: await grammar for unity
This commit is contained in:
@@ -14,6 +14,7 @@ package com.zfoo.net.packet;
|
||||
|
||||
import com.zfoo.net.NetContext;
|
||||
import com.zfoo.net.router.attachment.IAttachment;
|
||||
import com.zfoo.net.router.attachment.SignalOnlyAttachment;
|
||||
import com.zfoo.net.router.route.PacketBus;
|
||||
import com.zfoo.protocol.ProtocolManager;
|
||||
import com.zfoo.protocol.buffer.ByteBufUtils;
|
||||
@@ -73,6 +74,7 @@ public class PacketService implements IPacketService {
|
||||
|
||||
private final Predicate<IProtocolRegistration> netGenerateProtocolFilter = registration
|
||||
-> ProtocolManager.moduleByModuleId(registration.module()).getName().matches(NET_COMMON_MODULE)
|
||||
|| registration.protocolConstructor().getDeclaringClass() == SignalOnlyAttachment.class
|
||||
|| registration.protocolConstructor().getDeclaringClass().getSimpleName().endsWith(NET_REQUEST_SUFFIX)
|
||||
|| registration.protocolConstructor().getDeclaringClass().getSimpleName().endsWith(NET_RESPONSE_SUFFIX)
|
||||
|| registration.protocolConstructor().getDeclaringClass().getSimpleName().endsWith(NET_NOTICE_SUFFIX);
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ProtocolAnalysis {
|
||||
|
||||
// 临时变量,启动完成就会销毁,协议名称保留字符,即协议的名称不能用以下名称命名
|
||||
private static Set<String> protocolReserved = Set.of("Buffer", "ByteBuf", "ByteBuffer", "LittleEndianByteBuffer", "NormalByteBuffer"
|
||||
, "IPacket", "IProtocolRegistration", "ProtocolManager", "IFieldRegistration"
|
||||
, "IProtocol", "IProtocolRegistration", "ProtocolManager", "IFieldRegistration"
|
||||
, "ByteBufUtils", "ArrayUtils", "CollectionUtils"
|
||||
, "Boolean", "Byte", "Short", "Integer", "Long", "Float", "Double", "String", "Character", "Object"
|
||||
, "Collections", "Iterator", "List", "ArrayList", "Map", "HashMap", "Set", "HashSet");
|
||||
|
||||
@@ -265,7 +265,7 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// List<IPacket>
|
||||
// List<IProtocol>
|
||||
if (listField.getListElementRegistration() instanceof ObjectProtocolField) {
|
||||
var protocolId = ((ObjectProtocolField) listField.getListElementRegistration()).getProtocolId();
|
||||
switch (language) {
|
||||
|
||||
@@ -279,7 +279,7 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Set<IPacket>
|
||||
// Set<IProtocol>
|
||||
if (setField.getSetElementRegistration() instanceof ObjectProtocolField) {
|
||||
var protocolId = ((ObjectProtocolField) setField.getSetElementRegistration()).getProtocolId();
|
||||
switch (language) {
|
||||
|
||||
@@ -87,7 +87,7 @@ public abstract class GenerateCsUtils {
|
||||
public static void createProtocolManager() throws IOException {
|
||||
var list = List.of("csharp/ProtocolManager.cs"
|
||||
, "csharp/IProtocolRegistration.cs"
|
||||
, "csharp/IPacket.cs"
|
||||
, "csharp/IProtocol.cs"
|
||||
, "csharp/Buffer/ByteBuffer.cs"
|
||||
, "csharp/Buffer/LittleEndianByteBuffer.cs"
|
||||
, "csharp/Buffer/BigEndianByteBuffer.cs");
|
||||
|
||||
@@ -563,7 +563,7 @@ namespace CsProtocol.Buffer
|
||||
return Encoding.UTF8.GetString(value, 0, value.Length);
|
||||
}
|
||||
|
||||
public bool WritePacketFlag(IPacket packet)
|
||||
public bool WritePacketFlag(IProtocol packet)
|
||||
{
|
||||
bool flag = packet == null;
|
||||
WriteBool(!flag);
|
||||
@@ -871,7 +871,7 @@ namespace CsProtocol.Buffer
|
||||
int length = array.Length;
|
||||
for (int index = 0; index < length; index++)
|
||||
{
|
||||
protocolRegistration.Write(this, (IPacket) array[index]);
|
||||
protocolRegistration.Write(this, (IProtocol) array[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1193,7 +1193,7 @@ namespace CsProtocol.Buffer
|
||||
int length = list.Count;
|
||||
for (int index = 0; index < length; index++)
|
||||
{
|
||||
protocolRegistration.Write(this, (IPacket) list[index]);
|
||||
protocolRegistration.Write(this, (IProtocol) list[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1474,7 +1474,7 @@ namespace CsProtocol.Buffer
|
||||
WriteInt(set.Count);
|
||||
foreach (var element in set)
|
||||
{
|
||||
protocolRegistration.Write(this, (IPacket) element);
|
||||
protocolRegistration.Write(this, (IProtocol) element);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1611,7 +1611,7 @@ namespace CsProtocol.Buffer
|
||||
foreach (var element in map)
|
||||
{
|
||||
WriteInt(element.Key);
|
||||
protocolRegistration.Write(this, (IPacket) element.Value);
|
||||
protocolRegistration.Write(this, (IProtocol) element.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1750,7 +1750,7 @@ namespace CsProtocol.Buffer
|
||||
foreach (var element in map)
|
||||
{
|
||||
WriteLong(element.Key);
|
||||
protocolRegistration.Write(this, (IPacket) element.Value);
|
||||
protocolRegistration.Write(this, (IProtocol) element.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1889,7 +1889,7 @@ namespace CsProtocol.Buffer
|
||||
foreach (var element in map)
|
||||
{
|
||||
WriteString(element.Key);
|
||||
protocolRegistration.Write(this, (IPacket) element.Value);
|
||||
protocolRegistration.Write(this, (IProtocol) element.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1915,7 +1915,7 @@ namespace CsProtocol.Buffer
|
||||
public void WritePacket<T>(T packet, short protocolId)
|
||||
{
|
||||
IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId);
|
||||
protocolRegistration.Write(this, (IPacket) packet);
|
||||
protocolRegistration.Write(this, (IProtocol) packet);
|
||||
}
|
||||
|
||||
public T ReadPacket<T>(short protocolId)
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace CsProtocol.Buffer
|
||||
{
|
||||
public interface IPacket
|
||||
public interface IProtocol
|
||||
{
|
||||
short ProtocolId();
|
||||
}
|
||||
@@ -4,9 +4,9 @@
|
||||
{
|
||||
short ProtocolId();
|
||||
|
||||
void Write(ByteBuffer buffer, IPacket packet);
|
||||
void Write(ByteBuffer buffer, IProtocol packet);
|
||||
|
||||
IPacket Read(ByteBuffer buffer);
|
||||
IProtocol Read(ByteBuffer buffer);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ namespace CsProtocol
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public static void Write(ByteBuffer buffer, IPacket packet)
|
||||
public static void Write(ByteBuffer buffer, IProtocol packet)
|
||||
{
|
||||
var protocolId = packet.ProtocolId();
|
||||
// 写入协议号
|
||||
@@ -60,7 +60,7 @@ namespace CsProtocol
|
||||
GetProtocol(protocolId).Write(buffer, packet);
|
||||
}
|
||||
|
||||
public static IPacket Read(ByteBuffer buffer)
|
||||
public static IProtocol Read(ByteBuffer buffer)
|
||||
{
|
||||
var protocolId = buffer.ReadShort();
|
||||
return GetProtocol(protocolId).Read(buffer);
|
||||
|
||||
@@ -5,7 +5,7 @@ using CsProtocol.Buffer;
|
||||
namespace CsProtocol
|
||||
{
|
||||
{}
|
||||
public class {} : IPacket
|
||||
public class {} : IProtocol
|
||||
{
|
||||
{}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace CsProtocol
|
||||
return {};
|
||||
}
|
||||
|
||||
public void Write(ByteBuffer buffer, IPacket packet)
|
||||
public void Write(ByteBuffer buffer, IProtocol packet)
|
||||
{
|
||||
if (buffer.WritePacketFlag(packet))
|
||||
{
|
||||
@@ -41,7 +41,7 @@ namespace CsProtocol
|
||||
{}
|
||||
}
|
||||
|
||||
public IPacket Read(ByteBuffer buffer)
|
||||
public IProtocol Read(ByteBuffer buffer)
|
||||
{
|
||||
if (!buffer.ReadBool())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user