I’m testing out code for a C++ API wrapper for Windows and I’d like to test out long API words, specifically API words that require 4 or 5 bytes. So far, I have been using /system/script/add and /system/script/print for writing and reading long API words, respectively. For the source, I’m just using a :put command with a string after it. For the most part, this works great, since I just need to make sure what goes up matches what comes down. The content of the script doesn’t matter, just the length.
/system/script/add
=name=echo1
=owner=admin
=source=:put “1234567890”
Everything works up to the point where I hit a length of 0x200000 (2MB), which requires a 4-byte encoded length. At that point, the socket is being closed, which implies I’m doing something wrong. Anyway, I don’t know whether there is some limitation or restriction that is preventing me from using long API words or if it is just my bad code. I’ve included the source code for encoding the length of API words requiring 3 byte and 4 bytes (see bottom). The 3-byte (and everything smaller) encoding works; the 4-byte encoding seems to kill the socket.
Can anyone provide sample API calls where I can send and receive large API words? If someone can provide something that I know works, I’ll know it’s just my code.
// Write 3 byte length
else if (length < 0x200000)
{
length |= 0xC00000;
byte = ((length >> 16) & 0xff);
if (!_WriteByte(byte))
return false;
byte = ((length >> 8) & 0xff);
if (!_WriteByte(byte))
return false;
byte = (length & 0xff);
if (!_WriteByte(byte))
return false;
}
// Write 4 byte length
else if (length < 0x10000000)
{
length |= 0xE0000000;
byte = ((length >> 24) & 0xff);
if (!_WriteByte(byte))
return false;
byte = ((length >> 16) & 0xff);
if (!_WriteByte(byte))
return false;
byte = ((length >> 8) & 0xff);
if (!_WriteByte(byte))
return false;
byte = (length & 0xff);
if (!_WriteByte(byte))
return false;
}