amfUtils.js
function amf3encUI29(num) {
    var len = 0;
    if (num < 0x80) len = 1;
    if (num < 0x4000) len = 2;
    if (num < 0x200000) len = 3;
    if (num >= 0x200000) len = 4;
    var buf = new Buffer(len);
    switch (len) {
        case 1:
            buf.writeUInt8(num, 0);
            break;
        case 2:
            buf.writeUInt8(num & 0x7F, 0);
            buf.writeUInt8((num >> 7) | 0x80, 1);
            break;
        case 3:
            buf.writeUInt8(num & 0x7F, 0);
            buf.writeUInt8((num >> 7) & 0x7F, 1);
            buf.writeUInt8((num >> 14) | 0x80, 2);
            break;
        case 4:
            buf.writeUInt8(num & 0xFF, 0);
            buf.writeUInt8((num >> 8) & 0x7F, 1);
            buf.writeUInt8((num >> 15) | 0x7F, 2);
            buf.writeUInt8((num >> 22) | 0x7F, 3);
            break;
    }
    return buf;
}
function amf3encUI29(num) {
    var len = 0;
    if (num < 0x80) len = 1;
    if (num < 0x4000) len = 2;
    if (num < 0x200000) len = 3;
    if (num >= 0x200000) len = 4;
    var buf = new Buffer(len);
    switch (len) {
        case 1:
            buf.writeUInt8(num, 0);
            break;
        case 2:
            buf.writeUInt8(num & 0x7F, 0);
            buf.writeUInt8((num >> 7) | 0x80, 1);
            break;
        case 3:
            buf.writeUInt8(num & 0x7F, 0);
            buf.writeUInt8((num >> 7) & 0x7F, 1);
            buf.writeUInt8((num >> 14) | 0x80, 2);
            break;
        case 4:
            buf.writeUInt8(num & 0xFF, 0);
            buf.writeUInt8((num >> 8) & 0x7F, 1);
            buf.writeUInt8((num >> 15) | 0x7F, 2);
            buf.writeUInt8((num >> 22) | 0x7F, 3);
            break;
    }
    return buf;
}
function amf3encUI29 ( num ) { var len = 0 ; if ( num < 0x80 ) len = 1 ; if ( num < 0x4000 ) len = 2 ; if ( num < 0x200000 ) len = 3 ; if ( num >= 0x200000 ) len = 4 ; var buf = new Buffer ( len ) ; switch ( len ) { case 1 : buf . writeUInt8 ( num , 0 ) ; break ; case 2 : buf . writeUInt8 ( num & 0x7F , 0 ) ; buf . writeUInt8 ( ( num >> 7 ) | 0x80 , 1 ) ; break ; case 3 : buf . writeUInt8 ( num & 0x7F , 0 ) ; buf . writeUInt8 ( ( num >> 7 ) & 0x7F , 1 ) ; buf . writeUInt8 ( ( num >> 14 ) | 0x80 , 2 ) ; break ; case 4 : buf . writeUInt8 ( num & 0xFF , 0 ) ; buf . writeUInt8 ( ( num >> 8 ) & 0x7F , 1 ) ; buf . writeUInt8 ( ( num >> 15 ) | 0x7F , 2 ) ; buf . writeUInt8 ( ( num >> 22 ) | 0x7F , 3 ) ; break ; } return buf ; }
Generic encode of AMF3 UInt29 value
@param num
@returns {Buffer}
Generic encode of AMF3 UInt29 value