- Restructured module layout

- `TestMessage` now has a `toString()` override
This commit is contained in:
Tristan B. Velloza Kildaire 2023-05-05 23:51:33 +02:00
parent f230be0df7
commit 2f081b0d1a
7 changed files with 73 additions and 83 deletions

View File

@ -0,0 +1,60 @@
module davinci.base.components;
import davinci.base.container : BaseMessage;
import msgpack;
public enum ProtocolVersion
{
VERSION_0_PHONK
}
/**
* The type of message
*/
public enum MessageType
{
/**
* If the message is client-to-server
*/
CLIENT_TO_SERVER,
/**
* If the message is server-to-server
*/
SERVER_TO_SERVER
}
public abstract class Command
{
private byte[] data;
this(byte[] data)
{
this.data = data;
}
// public abstract byte[] encode();
public final byte[] getEncoded()
{
return data;
}
// TODO: Add a way to enforce that T must be derived from or equal to BaseMessage
public static T decodeTo(T)(byte[] data)
{
// Currently we are using message pack
import msgpack;
return unpack!(T)(cast(ubyte[])data);
}
}
public enum CommandType
{
SPACER,
NOP_COMMAND
}

View File

@ -1,5 +1,6 @@
module davinci.base.base;
module davinci.base.container;
import davinci.base.components;
import msgpack;
/**
@ -115,58 +116,3 @@ public class BaseMessage
}
public enum ProtocolVersion
{
VERSION_0_PHONK
}
/**
* The type of message
*/
public enum MessageType
{
/**
* If the message is client-to-server
*/
CLIENT_TO_SERVER,
/**
* If the message is server-to-server
*/
SERVER_TO_SERVER
}
public abstract class Command
{
private byte[] data;
this(byte[] data)
{
this.data = data;
}
// public abstract byte[] encode();
public final byte[] getEncoded()
{
return data;
}
// TODO: Add a way to enforce that T must be derived from or equal to BaseMessage
public static T decodeTo(T)(byte[] data)
{
// Currently we are using message pack
import msgpack;
return unpack!(T)(cast(ubyte[])data);
}
}
public enum CommandType
{
SPACER,
NOP_COMMAND
}

View File

@ -0,0 +1,4 @@
module davinci.base;
public import davinci.base.container : BaseMessage;
public import davinci.base.components : Command, CommandType, MessageType, ProtocolVersion;

View File

@ -1,11 +0,0 @@
module davinci.c2s.client;
import davinci.base.base : BaseMessage, MessageType;
// public abstract class C2SMessage : BaseMessage
// {
// this()
// {
// super(MessageType.CLIENT_TO_SERVER);
// }
// }

View File

@ -1,7 +1,6 @@
module davinci.c2s.test;
import davinci.base.base;
import davinci.c2s.client;
import davinci.base;
import msgpack;
public class TestMessage : Command
@ -15,12 +14,15 @@ public class TestMessage : Command
super(cast(byte[])pack(this));
}
public string getTestField()
{
return testField;
}
public override string toString()
{
return "TestMessage [testField: "~testField~"]";
}
}
version(unittest)

View File

@ -1,3 +1,3 @@
module davinci;
public import davinci.base.base : BaseMessage, MessageType;
public import davinci.base;

View File

@ -1,11 +0,0 @@
module davinci.s2s.server;
import davinci.base.base : BaseMessage, MessageType;
public class S2SMessage
{
// this()
// {
// super(MessageType.SERVER_TO_SERVER);
// }
}