From f49d8349ce1af3835f54b70248a789935fc43903 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sun, 30 Apr 2023 01:03:19 +0200 Subject: [PATCH] BClient - `sendMessage(byte[])` now encodes using `bformat.marshall`'s `encodeBformat(byte[])` rather than its own code --- source/bformat/sockets.d | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/source/bformat/sockets.d b/source/bformat/sockets.d index f3814f1..c58e816 100644 --- a/source/bformat/sockets.d +++ b/source/bformat/sockets.d @@ -113,37 +113,14 @@ public class BClient /* The message buffer */ byte[] messageBuffer; - /* Encode the 4 byte message length header (little endian) */ - int payloadLength = cast(int)message.length; - byte* lengthBytes = cast(byte*)&payloadLength; - - /* On little endian simply get the bytes as is (it would be encoded as little endian) */ - version(LittleEndian) - { - messageBuffer ~= *(lengthBytes+0); - messageBuffer ~= *(lengthBytes+1); - messageBuffer ~= *(lengthBytes+2); - messageBuffer ~= *(lengthBytes+3); - } - - /* On Big Endian you must swap the big-endian-encoded number to be in little endian ordering */ - version(BigEndian) - { - messageBuffer ~= *(lengthBytes+3); - messageBuffer ~= *(lengthBytes+2); - messageBuffer ~= *(lengthBytes+1); - messageBuffer ~= *(lengthBytes+0); - } - - - /* Add the message to the buffer */ - messageBuffer ~= cast(byte[])message; + import bformat.marshall : encodeBformat; + messageBuffer = encodeBformat(message); try { /* Send the message */ stream.writeFully(messageBuffer); - + return true; } catch(StreamException streamError)