* 🚧 WIP v2.

Signed-off-by: 秋雨落 <i@rain.cx>

* 🚧 WIP v2 * 2.

Signed-off-by: 秋雨落 <i@rain.cx>

* ✨ It works?

Signed-off-by: 秋雨落 <i@rain.cx>

* ✨ Publish to nexus.

Signed-off-by: 秋雨落 <i@rain.cx>

---------

Signed-off-by: 秋雨落 <i@rain.cx>
This commit is contained in:
秋 雨落
2024-01-10 09:52:50 +08:00
committed by GitHub
parent 3af3badcc5
commit 84f4e3543c
32 changed files with 2361 additions and 385 deletions
@@ -0,0 +1,50 @@
using CrystalConnector.Protocol.Packets.C2S;
using CrystalConnector.Protocol.Packets.S2C;
using Google.Protobuf;
namespace CrystalConnector.Protocol.Packets;
public interface IPacket
{
public void Read(byte[] bytes);
public byte[] Write();
public static IPacket? From(byte[] data)
{
var result = TryForm<AuthenticatePacket>(data);
if (result is not null)
{
return result;
}
result = TryForm<PublishPacket>(data);
if (result is not null)
{
return result;
}
result = TryForm<ForwardPacket>(data);
if (result is not null)
{
return result;
}
result = TryForm<ResultPacket>(data);
return result;
}
private static IPacket? TryForm<T>(byte[] data) where T : IPacket, new()
{
try
{
var message = new T();
message.Read(data);
return message;
}
catch (InvalidProtocolBufferException ex)
{
return null;
}
}
}