function read(buf, type) {
    const regex = /\[(\w+)\]/m;
    let m;
    if ((m = regex.exec(type)) !== null) {
        const subtype = type.slice(m[0].length);
        return [...Array(parseInt(m[1], 10))].map(() => {
            return read(buf, subtype);
        });
    }
    switch (type) {
        case 'bool': return buf.uint8() ? true : false;
        case 'uint8': return buf.uint8();
        case 'byte': return buf.uint8();
        case 'uint16': return buf.uint16le();
        case 'uint32': return buf.uint32le();
        case 'uint64': return buf.uint64le();
        default: throw new Error('Invalid type : ' + type);
    }
}
// This is useful for fixed size types such as int, float etc.
This is useful for fixed size types such as int, float etc.
This is useful for fixed size types such as int float etc .
function read(buf, type) {
    const regex = /\[(\w+)\]/m;
    let m;
    if ((m = regex.exec(type)) !== null) {
        const subtype = type.slice(m[0].length);
        return [...Array(parseInt(m[1], 10))].map(() => {
            return read(buf, subtype);
        });
    }
    switch (type) {
        case 'bool': return buf.uint8() ? true : false;
        case 'uint8': return buf.uint8();
        case 'byte': return buf.uint8();
        case 'uint16': return buf.uint16le();
        case 'uint32': return buf.uint32le();
        case 'uint64': return buf.uint64le();
        default: throw new Error('Invalid type : ' + type);
    }
}
function read ( buf , type ) { const regex = / \[(\w+)\] / m ; let m ; if ( ( m = regex . exec ( type ) ) !== null ) { const subtype = type . slice ( m [ 0 ] . length ) ; return [ ... Array ( parseInt ( m [ 1 ] , 10 ) ) ] . map ( ( ) => { return read ( buf , subtype ) ; } ) ; } switch ( type ) { case 'bool' : return buf . uint8 ( ) ? true : false ; case 'uint8' : return buf . uint8 ( ) ; case 'byte' : return buf . uint8 ( ) ; case 'uint16' : return buf . uint16le ( ) ; case 'uint32' : return buf . uint32le ( ) ; case 'uint64' : return buf . uint64le ( ) ; default : throw new Error ( 'Invalid type : ' + type ) ; } }
This is useful for fixed size types such as int, float etc.
This is useful for fixed size types such as int float etc .