mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-16 22:14:53 +00:00
feat[net]: await grammar for unity
This commit is contained in:
1 parent
d01aa91f6d
commit
0362c33865
10 files changed
+22
-20
No files matched your search
@@ -14,6 +14,7 @@ package com.zfoo.net.packet;
|
|||||||
|
|
||||||
import com.zfoo.net.NetContext;
|
import com.zfoo.net.NetContext;
|
||||||
import com.zfoo.net.router.attachment.IAttachment;
|
import com.zfoo.net.router.attachment.IAttachment;
|
||||||
|
import com.zfoo.net.router.attachment.SignalOnlyAttachment;
|
||||||
import com.zfoo.net.router.route.PacketBus;
|
import com.zfoo.net.router.route.PacketBus;
|
||||||
import com.zfoo.protocol.ProtocolManager;
|
import com.zfoo.protocol.ProtocolManager;
|
||||||
import com.zfoo.protocol.buffer.ByteBufUtils;
|
import com.zfoo.protocol.buffer.ByteBufUtils;
|
||||||
@@ -73,6 +74,7 @@ public class PacketService implements IPacketService {
|
|||||||
|
|
||||||
private final Predicate<IProtocolRegistration> netGenerateProtocolFilter = registration
|
private final Predicate<IProtocolRegistration> netGenerateProtocolFilter = registration
|
||||||
-> ProtocolManager.moduleByModuleId(registration.module()).getName().matches(NET_COMMON_MODULE)
|
-> 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_REQUEST_SUFFIX)
|
||||||
|| registration.protocolConstructor().getDeclaringClass().getSimpleName().endsWith(NET_RESPONSE_SUFFIX)
|
|| registration.protocolConstructor().getDeclaringClass().getSimpleName().endsWith(NET_RESPONSE_SUFFIX)
|
||||||
|| registration.protocolConstructor().getDeclaringClass().getSimpleName().endsWith(NET_NOTICE_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"
|
private static Set<String> protocolReserved = Set.of("Buffer", "ByteBuf", "ByteBuffer", "LittleEndianByteBuffer", "NormalByteBuffer"
|
||||||
, "IPacket", "IProtocolRegistration", "ProtocolManager", "IFieldRegistration"
|
, "IProtocol", "IProtocolRegistration", "ProtocolManager", "IFieldRegistration"
|
||||||
, "ByteBufUtils", "ArrayUtils", "CollectionUtils"
|
, "ByteBufUtils", "ArrayUtils", "CollectionUtils"
|
||||||
, "Boolean", "Byte", "Short", "Integer", "Long", "Float", "Double", "String", "Character", "Object"
|
, "Boolean", "Byte", "Short", "Integer", "Long", "Float", "Double", "String", "Character", "Object"
|
||||||
, "Collections", "Iterator", "List", "ArrayList", "Map", "HashMap", "Set", "HashSet");
|
, "Collections", "Iterator", "List", "ArrayList", "Map", "HashMap", "Set", "HashSet");
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ public class CutDownListSerializer implements ICutDownSerializer {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// List<IPacket>
|
// List<IProtocol>
|
||||||
if (listField.getListElementRegistration() instanceof ObjectProtocolField) {
|
if (listField.getListElementRegistration() instanceof ObjectProtocolField) {
|
||||||
var protocolId = ((ObjectProtocolField) listField.getListElementRegistration()).getProtocolId();
|
var protocolId = ((ObjectProtocolField) listField.getListElementRegistration()).getProtocolId();
|
||||||
switch (language) {
|
switch (language) {
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ public class CutDownSetSerializer implements ICutDownSerializer {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Set<IPacket>
|
// Set<IProtocol>
|
||||||
if (setField.getSetElementRegistration() instanceof ObjectProtocolField) {
|
if (setField.getSetElementRegistration() instanceof ObjectProtocolField) {
|
||||||
var protocolId = ((ObjectProtocolField) setField.getSetElementRegistration()).getProtocolId();
|
var protocolId = ((ObjectProtocolField) setField.getSetElementRegistration()).getProtocolId();
|
||||||
switch (language) {
|
switch (language) {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public abstract class GenerateCsUtils {
|
|||||||
public static void createProtocolManager() throws IOException {
|
public static void createProtocolManager() throws IOException {
|
||||||
var list = List.of("csharp/ProtocolManager.cs"
|
var list = List.of("csharp/ProtocolManager.cs"
|
||||||
, "csharp/IProtocolRegistration.cs"
|
, "csharp/IProtocolRegistration.cs"
|
||||||
, "csharp/IPacket.cs"
|
, "csharp/IProtocol.cs"
|
||||||
, "csharp/Buffer/ByteBuffer.cs"
|
, "csharp/Buffer/ByteBuffer.cs"
|
||||||
, "csharp/Buffer/LittleEndianByteBuffer.cs"
|
, "csharp/Buffer/LittleEndianByteBuffer.cs"
|
||||||
, "csharp/Buffer/BigEndianByteBuffer.cs");
|
, "csharp/Buffer/BigEndianByteBuffer.cs");
|
||||||
|
|||||||
@@ -563,7 +563,7 @@ namespace CsProtocol.Buffer
|
|||||||
return Encoding.UTF8.GetString(value, 0, value.Length);
|
return Encoding.UTF8.GetString(value, 0, value.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool WritePacketFlag(IPacket packet)
|
public bool WritePacketFlag(IProtocol packet)
|
||||||
{
|
{
|
||||||
bool flag = packet == null;
|
bool flag = packet == null;
|
||||||
WriteBool(!flag);
|
WriteBool(!flag);
|
||||||
@@ -871,7 +871,7 @@ namespace CsProtocol.Buffer
|
|||||||
int length = array.Length;
|
int length = array.Length;
|
||||||
for (int index = 0; index < length; index++)
|
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;
|
int length = list.Count;
|
||||||
for (int index = 0; index < length; index++)
|
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);
|
WriteInt(set.Count);
|
||||||
foreach (var element in set)
|
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)
|
foreach (var element in map)
|
||||||
{
|
{
|
||||||
WriteInt(element.Key);
|
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)
|
foreach (var element in map)
|
||||||
{
|
{
|
||||||
WriteLong(element.Key);
|
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)
|
foreach (var element in map)
|
||||||
{
|
{
|
||||||
WriteString(element.Key);
|
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)
|
public void WritePacket<T>(T packet, short protocolId)
|
||||||
{
|
{
|
||||||
IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId);
|
IProtocolRegistration protocolRegistration = ProtocolManager.GetProtocol(protocolId);
|
||||||
protocolRegistration.Write(this, (IPacket) packet);
|
protocolRegistration.Write(this, (IProtocol) packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T ReadPacket<T>(short protocolId)
|
public T ReadPacket<T>(short protocolId)
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
namespace CsProtocol.Buffer
|
namespace CsProtocol.Buffer
|
||||||
{
|
{
|
||||||
public interface IPacket
|
public interface IProtocol
|
||||||
{
|
{
|
||||||
short ProtocolId();
|
short ProtocolId();
|
||||||
}
|
}
|
||||||
@@ -4,9 +4,9 @@
|
|||||||
{
|
{
|
||||||
short ProtocolId();
|
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;
|
return protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Write(ByteBuffer buffer, IPacket packet)
|
public static void Write(ByteBuffer buffer, IProtocol packet)
|
||||||
{
|
{
|
||||||
var protocolId = packet.ProtocolId();
|
var protocolId = packet.ProtocolId();
|
||||||
// 写入协议号
|
// 写入协议号
|
||||||
@@ -60,7 +60,7 @@ namespace CsProtocol
|
|||||||
GetProtocol(protocolId).Write(buffer, packet);
|
GetProtocol(protocolId).Write(buffer, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IPacket Read(ByteBuffer buffer)
|
public static IProtocol Read(ByteBuffer buffer)
|
||||||
{
|
{
|
||||||
var protocolId = buffer.ReadShort();
|
var protocolId = buffer.ReadShort();
|
||||||
return GetProtocol(protocolId).Read(buffer);
|
return GetProtocol(protocolId).Read(buffer);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using CsProtocol.Buffer;
|
|||||||
namespace CsProtocol
|
namespace CsProtocol
|
||||||
{
|
{
|
||||||
{}
|
{}
|
||||||
public class {} : IPacket
|
public class {} : IProtocol
|
||||||
{
|
{
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ namespace CsProtocol
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(ByteBuffer buffer, IPacket packet)
|
public void Write(ByteBuffer buffer, IProtocol packet)
|
||||||
{
|
{
|
||||||
if (buffer.WritePacketFlag(packet))
|
if (buffer.WritePacketFlag(packet))
|
||||||
{
|
{
|
||||||
@@ -41,7 +41,7 @@ namespace CsProtocol
|
|||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPacket Read(ByteBuffer buffer)
|
public IProtocol Read(ByteBuffer buffer)
|
||||||
{
|
{
|
||||||
if (!buffer.ReadBool())
|
if (!buffer.ReadBool())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user