Example #1
0
 void BroadcastSock::loadShort(uint16_t x)//uint16
 {
     uint16_t temp;
     temp = nlSwaps(x);
     memcpy(outbuf+obp,&temp,2);
     obp += 2;
 }
Example #2
0
int _tmain(int argc, NLchar **argv)
#endif
{
    NLbyte      buffer[NL_MAX_STRING_LENGTH];
    NLint       count = 0;
    NLbyte      b = (NLbyte)99;
    NLushort    s = 0x1122;
    NLulong     l = 0x11223344;
    NLfloat     f = 12.3141592651f;
    NLdouble    d = 123.12345678901234;
    NLchar      string[NL_MAX_STRING_LENGTH] = TEXT("Hello");
    NLbyte      block[] = {9,8,7,6,5,4,3,2,1,0};

    if(nlInit() == NL_FALSE)
        printErrorExit();

    nlEnable(NL_BIG_ENDIAN_DATA);
    _tprintf(TEXT("nl_big_endian_data = %d\n"), nlGetBoolean(NL_BIG_ENDIAN_DATA));
    _tprintf(TEXT("nlGetString(NL_VERSION) = %s\n\n"), nlGetString(NL_VERSION));
    _tprintf(TEXT("nlGetString(NL_NETWORK_TYPES) = %s\n\n"), nlGetString(NL_NETWORK_TYPES));

    if(nlSelectNetwork(NL_IP) == NL_FALSE)
        printErrorExit();

    _tprintf(TEXT("Short number: %#x, "), s);
    s = nlSwaps(s);
    _tprintf(TEXT("swapped: %#x, "), s);
    s = nlSwaps(s);
    _tprintf(TEXT("swapped back: %#x\n"), s);

    _tprintf(TEXT("Long number: %#lx, "), l);
    l = nlSwapl(l);
    _tprintf(TEXT("swapped: %#lx, "), l);
    l = nlSwapl(l);
    _tprintf(TEXT("swapped back: %#lx\n"), l);

    _tprintf(TEXT("Float number: %.10f, "), f);
    f = nlSwapf(f);
    _tprintf(TEXT("swapped: %.10f, "), f);
    f = nlSwapf(f);
    _tprintf(TEXT("swapped back: %.10f\n"), f);

    _tprintf(TEXT("Double number: %.14f, "), d);
    d = nlSwapd(d);
    _tprintf(TEXT("swapped: %.24f, "), d);
    d = nlSwapd(d);
    _tprintf(TEXT("swapped back: %.14f\n"), d);
    _tprintf(TEXT("\n"));

    _tprintf(TEXT("write byte %d to buffer\n"), b);
    _tprintf(TEXT("write short %#x to buffer\n"), s);
    _tprintf(TEXT("write long %#lx to buffer\n"), l);
    _tprintf(TEXT("write float %f to buffer\n"), f);
    _tprintf(TEXT("write double %.14f to buffer\n"), d);
    _tprintf(TEXT("write string %s to buffer\n"), string);
    _tprintf(TEXT("write block %d%d%d%d%d%d%d%d%d%d to buffer\n"), block[0]
            , block[1], block[2], block[3], block[4], block[5], block[6]
            , block[7], block[8], block[9]);
    _tprintf(TEXT("\n"));
    writeByte(buffer, count, b);
    writeShort(buffer, count, s);
    writeLong(buffer, count, l);
    writeFloat(buffer, count, f);
    writeDouble(buffer, count, d);
    writeString(buffer, count, string);
    writeBlock(buffer, count, block, 10);

    /* reset count to zero to read from start of buffer */
    count = 0;

    readByte(buffer, count, b);
    readShort(buffer, count, s);
    readLong(buffer, count, l);
    readFloat(buffer, count, f);
    readDouble(buffer, count, d);
    readString(buffer, count, string);
    readBlock(buffer, count, block, 10);
    _tprintf(TEXT("read byte %d from buffer\n"), b);
    _tprintf(TEXT("read short %#x from buffer\n"), s);
    _tprintf(TEXT("read long %#lx from buffer\n"), l);
    _tprintf(TEXT("read float %f from buffer\n"), f);
    _tprintf(TEXT("read double %.14f from buffer\n"), d);
    _tprintf(TEXT("read string %s from buffer\n"), string);
    _tprintf(TEXT("read block %d%d%d%d%d%d%d%d%d%d from buffer\n"), block[0]
            , block[1], block[2], block[3], block[4], block[5], block[6]
            , block[7], block[8], block[9]);

    nlShutdown();
    return 0;
}