You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
49 lines
1.4 KiB
namespace WhiteRabbit
|
|
{
|
|
internal unsafe struct Phrase
|
|
{
|
|
public fixed byte Buffer[32];
|
|
|
|
public Phrase(byte[][] words, int numberOfCharacters)
|
|
{
|
|
fixed (byte* bufferPointer = this.Buffer)
|
|
{
|
|
var length = numberOfCharacters + words.Length - 1;
|
|
|
|
byte* end = bufferPointer + length;
|
|
byte[] currentWord = words[0];
|
|
var j = 0;
|
|
var wordIndex = 0;
|
|
for (var currentPointer = bufferPointer; currentPointer < end; currentPointer++)
|
|
{
|
|
if (j >= currentWord.Length)
|
|
{
|
|
j = 0;
|
|
wordIndex++;
|
|
currentWord = words[wordIndex];
|
|
}
|
|
|
|
*currentPointer = currentWord[j];
|
|
j++;
|
|
}
|
|
|
|
bufferPointer[31] = (byte)length;
|
|
}
|
|
}
|
|
|
|
public byte[] GetBytes()
|
|
{
|
|
fixed(byte* bufferPointer = this.Buffer)
|
|
{
|
|
var length = bufferPointer[31];
|
|
var result = new byte[length];
|
|
for (var i = 0; i < length; i++)
|
|
{
|
|
result[i] = bufferPointer[i];
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|