ndef-lib/index.js
function (ndefBytes) {

        // ndefBytes can be an array of bytes e.g. [0x03, 0x31, 0xd1] or a Buffer
        var bytes;
        // if (ndefBytes instanceof Buffer) {
        //     // get an array of bytes
        //     bytes = Array.prototype.slice.call(ndefBytes, 0);
        // } else if (ndefBytes instanceof Array) {
        if (ndefBytes instanceof Array) {
            bytes = ndefBytes.slice(0);
        } else {
            throw new Error('ndef.decodeMessage requires a Buffer or an Array of bytes');
        }

        var bytes = bytes.slice(0), // clone since parsing is destructive
            ndef_message = [],
            tnf_byte,
            header,
            type_length = 0,
            payload_length = 0,
            id_length = 0,
            record_type = [],
            id = [],
            payload = [];

        while(bytes.length) {

            tnf_byte = bytes.shift();
            header = ndef.decodeTnf(tnf_byte);

            type_length = bytes.shift();

            if (header.sr) {
                payload_length = bytes.shift();
            } else {
                // next 4 bytes are length
                payload_length = ((0xFF & bytes.shift()) << 24) |
                    ((0xFF & bytes.shift()) << 16) |
                    ((0xFF & bytes.shift()) << 8) |
                    (0xFF & bytes.shift());
            }

            id_length = header.il ? bytes.shift() : 0;

            record_type = bytes.splice(0, type_length);
            id = bytes.splice(0, id_length);
            payload = bytes.splice(0, payload_length);

            ndef_message.push(
                ndef.record(header.tnf, record_type, id, payload)
            );

            if (header.me) break; // last message
        }

        return ndef_message;
    }
function (ndefBytes) {

        // ndefBytes can be an array of bytes e.g. [0x03, 0x31, 0xd1] or a Buffer
        var bytes;
        // if (ndefBytes instanceof Buffer) {
        //     // get an array of bytes
        //     bytes = Array.prototype.slice.call(ndefBytes, 0);
        // } else if (ndefBytes instanceof Array) {
        if (ndefBytes instanceof Array) {
            bytes = ndefBytes.slice(0);
        } else {
            throw new Error('ndef.decodeMessage requires a Buffer or an Array of bytes');
        }

        var bytes = bytes.slice(0), // clone since parsing is destructive
            ndef_message = [],
            tnf_byte,
            header,
            type_length = 0,
            payload_length = 0,
            id_length = 0,
            record_type = [],
            id = [],
            payload = [];

        while(bytes.length) {

            tnf_byte = bytes.shift();
            header = ndef.decodeTnf(tnf_byte);

            type_length = bytes.shift();

            if (header.sr) {
                payload_length = bytes.shift();
            } else {
                // next 4 bytes are length
                payload_length = ((0xFF & bytes.shift()) << 24) |
                    ((0xFF & bytes.shift()) << 16) |
                    ((0xFF & bytes.shift()) << 8) |
                    (0xFF & bytes.shift());
            }

            id_length = header.il ? bytes.shift() : 0;

            record_type = bytes.splice(0, type_length);
            id = bytes.splice(0, id_length);
            payload = bytes.splice(0, payload_length);

            ndef_message.push(
                ndef.record(header.tnf, record_type, id, payload)
            );

            if (header.me) break; // last message
        }

        return ndef_message;
    }
function ( ndefBytes ) { // ndefBytes can be an array of bytes e.g. [0x03, 0x31, 0xd1] or a Buffer var bytes ; // if (ndefBytes instanceof Buffer) { //     // get an array of bytes //     bytes = Array.prototype.slice.call(ndefBytes, 0); // } else if (ndefBytes instanceof Array) { if ( ndefBytes instanceof Array ) { bytes = ndefBytes . slice ( 0 ) ; } else { throw new Error ( 'ndef.decodeMessage requires a Buffer or an Array of bytes' ) ; } var bytes = bytes . slice ( 0 ) , // clone since parsing is destructive ndef_message = [ ] , tnf_byte , header , type_length = 0 , payload_length = 0 , id_length = 0 , record_type = [ ] , id = [ ] , payload = [ ] ; while ( bytes . length ) { tnf_byte = bytes . shift ( ) ; header = ndef . decodeTnf ( tnf_byte ) ; type_length = bytes . shift ( ) ; if ( header . sr ) { payload_length = bytes . shift ( ) ; } else { // next 4 bytes are length payload_length = ( ( 0xFF & bytes . shift ( ) ) << 24 ) | ( ( 0xFF & bytes . shift ( ) ) << 16 ) | ( ( 0xFF & bytes . shift ( ) ) << 8 ) | ( 0xFF & bytes . shift ( ) ) ; } id_length = header . il ? bytes . shift ( ) : 0 ; record_type = bytes . splice ( 0 , type_length ) ; id = bytes . splice ( 0 , id_length ) ; payload = bytes . splice ( 0 , payload_length ) ; ndef_message . push ( ndef . record ( header . tnf , record_type , id , payload ) ) ; if ( header . me ) break ; // last message } return ndef_message ; }
Decodes an array bytes into an NDEF Message

@ndefBytes an array bytes or Buffer that was read from a NFC tag

@returns array of NDEF Records

@see NFC Data Exchange Format (NDEF) http://www.nfc-forum.org/specs/spec_list/
Decodes an array bytes into an NDEF Message