Madegeneric

This commit is contained in:
Tristan B. Kildaire 2020-06-16 18:09:41 +02:00
parent a8d654bf6a
commit 2d26cde27e
1 changed files with 3 additions and 6 deletions

View File

@ -3,7 +3,7 @@ module bmessage;
import std.socket : Socket, SocketFlags;
import std.json : JSONValue, parseJSON, toJSON;
public bool receiveMessage(Socket originator, ref JSONValue receiveMessage)
public bool receiveMessage(Socket originator, ref byte[] receiveMessage)
{
/* Construct a buffer to receive into */
byte[] receiveBuffer;
@ -106,19 +106,16 @@ public bool receiveMessage(Socket originator, ref JSONValue receiveMessage)
// writeln("Message ", fullMessage);
/* Set the message in `receiveMessage */
receiveMessage = parseJSON(cast(string)fullMessage);
receiveMessage = fullMessage;
return true;
}
public bool sendMessage(Socket recipient, JSONValue jsonMessage)
public bool sendMessage(Socket recipient, byte[] message)
{
/* The message buffer */
byte[] messageBuffer;
/* Get the JSON as a string */
string message = toJSON(jsonMessage);
/* Encode the 4 byte message length header (little endian) */
int payloadLength = cast(int)message.length;
byte* lengthBytes = cast(byte*)&payloadLength;