Datasheet

API In CPP
125
********************************************************************/
void MikrotikAPI::WriteSentence(Sentence &writeSentence)
{
if (writeSentence.Length() == 0) {
return;
}
DEBUG ? printf("Writing sentence\n"): 0;
DEBUG ? writeSentence.Print() : 0;
for (int i = 0; i < writeSentence.Length(); ++i) {
WriteWord(writeSentence[i]);
}
WriteWord("\0");
}
/********************************************************************
* Read a message length from the socket
*
* 80 = 10000000 (2 character encoded length)
* C0 = 11000000 (3 character encoded length)
* E0 = 11100000 (4 character encoded length)
*
* Message length is returned
********************************************************************/
int MikrotikAPI::ReadLength()
{
char firstChar; // first character read from socket
char *lengthData; // length of next message to read...will be cast to int at the end
int *messageLength; // calculated length of next message (Cast to int)
lengthData = (char *) calloc(sizeof(int), 1);
DEBUG ? printf("Start ReadLength()\n") : 0;
read(fdSock, &firstChar, 1);
DEBUG ? printf("byte1 = %#x\n", firstChar) : 0;
// read 4 bytes
// this code SHOULD work, but is untested...
if ((firstChar & 0xE0) == 0xE0) {
DEBUG ? printf("4-byte encoded length\n") : 0;
if (littleEndian){
lengthData[3] = firstChar;