Don't click here unless you want to be banned.

LSL Wiki : AshByrne

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ia360925.us.archive.org

.ton rO .enryB hsA ,em taeb tsum uoy ,emag eht niw oT


Hi, I'm Ash. Every once in a while I come up with something cool.

This function allows you to base64-encode a list of integers with values 0-255. Sorta like a poor-man's byte array. It's based upon the curl_base64_decode function in libcurl. I needed it because I needed to output a bunch of data from SecondLife with XMLRPC, and llStringToBase64 just wasn't going to work in my case.

This function will become rather useless, in favor of llIntegerToBase64, when SL 1.5 comes out of preview mode. (I wonder where they got that idea from! :) ) Well, that doesn't work on lists of integers, but it'd be trivial to put it in a for loop.

llStringToBase64("test") gives the same result as intListToBase64([116,101,115,116]).

string  intListToBase64(list array) {
    string translation_table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    integer insize = llGetListLength(array);
    integer i;
    integer inputparts;
    list    ibuf;
    integer dataptr = 0;
    string  str;
    while (insize > 0) {
        ibuf = [];
        for (i = 0, inputparts = 0; i < 3; ++i) {
            if (insize > 0) {
                inputparts++;
                ibuf += [ llList2Integer(array,dataptr) ];
                dataptr++;
                insize--;
            } else
                ibuf += [ 0 ];
        }
        
        integer ibuf0 = llList2Integer(ibuf,0);
        integer ibuf1 = llList2Integer(ibuf,1);
        integer ibuf2 = llList2Integer(ibuf,2);
        
        integer obuf0 = (ibuf0 & 252) / 4;
        integer obuf1 = ((ibuf0 & 3) * 16) | ((ibuf1 & 240) / 16);
        integer obuf2 = ((ibuf1 & 15) * 4) | ((ibuf2 & 192) / 64);
        integer obuf3 = ibuf2 & 63;
        
        if (inputparts == 1) { // one byte read
            str += llGetSubString(translation_table, obuf0, obuf0) + 
                   llGetSubString(translation_table, obuf1, obuf1) + "==";
        } else if (inputparts == 2) { // two bytes read
            str += llGetSubString(translation_table, obuf0, obuf0) + 
                   llGetSubString(translation_table, obuf1, obuf1) + 
                   llGetSubString(translation_table, obuf2, obuf2) + "=";
        } else { // three bytes read
            str += llGetSubString(translation_table, obuf0, obuf0) + 
                   llGetSubString(translation_table, obuf1, obuf1) +
                   llGetSubString(translation_table, obuf2, obuf2) +
                   llGetSubString(translation_table, obuf3, obuf3);
        }
    }
    return str;
}
There is no comment on this page. [Display comments/form]