Testing API length encoding on long words

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;
}

maybe

/file/set
=numbers=text.txt
=contents=[insert more than 2MB data here]

for the encoder?

In all honesty, I haven’t been able to reach 4 byte length words “for real” with my API client either… I only know it’s not my length encoder/decoder, as I have made my encoder and decoder be able to work without a real connection in place, and supplying values near, at, or well within the different ranges works exactly as described in the spec, and equally importantly, each function does produce sequences that the other one can reverse.

Is there possibly a way to debug it on the Mikrotik side?

Well, you can enable some logging topics in “/system logging”, but that’s not really going to tell you much, so… pretty much “no”.