parent
440ef79a3a
commit
aea8ac5bb6
|
@ -4,6 +4,7 @@
|
||||||
module tristanable.encoding;
|
module tristanable.encoding;
|
||||||
|
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
|
import niknaks.bits : bytesToIntegral, Order, order;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a tagged message that has been decoded
|
* Represents a tagged message that has been decoded
|
||||||
|
@ -60,31 +61,9 @@ public final class TaggedMessage
|
||||||
/* The decoded tag */
|
/* The decoded tag */
|
||||||
ulong decodedTag;
|
ulong decodedTag;
|
||||||
|
|
||||||
/* If on little endian then dump direct */
|
/* Take ulong-many bytes and only flip them to LE if not on LE host */
|
||||||
version(LittleEndian)
|
decodedTag = order(bytesToIntegral!(ushort)(cast(ubyte[])encodedMessage), Order.LE);
|
||||||
{
|
|
||||||
decodedTag = *cast(ulong*)encodedMessage.ptr;
|
|
||||||
}
|
|
||||||
/* If on big endian then reverse received 8 bytes */
|
|
||||||
else version(BigEndian)
|
|
||||||
{
|
|
||||||
/* Base of our tag */
|
|
||||||
byte* tagHighPtr = cast(byte*)decodedTag.ptr;
|
|
||||||
|
|
||||||
*(tagHighPtr+0) = encodedMessage[7];
|
|
||||||
*(tagHighPtr+1) = encodedMessage[6];
|
|
||||||
*(tagHighPtr+2) = encodedMessage[5];
|
|
||||||
*(tagHighPtr+3) = encodedMessage[4];
|
|
||||||
*(tagHighPtr+4) = encodedMessage[3];
|
|
||||||
*(tagHighPtr+5) = encodedMessage[2];
|
|
||||||
*(tagHighPtr+6) = encodedMessage[1];
|
|
||||||
*(tagHighPtr+7) = encodedMessage[0];
|
|
||||||
}
|
|
||||||
/* Blessed is the fruit of thy womb Jesus, hail Mary, mother of God, pray for our sinners - now and at the hour of our death - Amen */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pragma(msg, "Not too sure about tha 'ey 😳️");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set the tag */
|
/* Set the tag */
|
||||||
decodedMessage.setTag(decodedTag);
|
decodedMessage.setTag(decodedTag);
|
||||||
|
|
Loading…
Reference in New Issue