wiseService/wiseService.js
/**
   * Add a field
   *
   * @param {string} field - An encoded field definition
   */
Add a field
@param {string} field - An encoded field definition
Add a field @param { string } field - An encoded field definition
addField (field) {
    let match = field.match(/field:([^;]+)/);
    const fieldName = match[1];
    let db;
    if ((match = field.match(/db:([^;]+)/))) {
      db = match[1];
    }
    let friendly;
    if ((match = field.match(/friendly:([^;]+)/))) {
      friendly = match[1];
    }
    if (WISESource.field2Pos[fieldName] !== undefined) {
      return WISESource.field2Pos[fieldName];
    }
    if (internals.debug > 1) {
      console.log(`Adding field name:${fieldName} db:${db} friendly:${friendly} from '${field}'`);
    }
    const pos = internals.fields.length;
    newFieldsTS();
    internals.fields.push(field);
    internals.fieldsSize += field.length + 10;
    let offset;
    if (internals.fields.length < 256) {
      internals.fieldsBuf0 = Buffer.alloc(internals.fieldsSize + 9);
      internals.fieldsBuf0.writeUInt32BE(internals.fieldsTS, 0);
      internals.fieldsBuf0.writeUInt32BE(0, 4);
      internals.fieldsBuf0.writeUInt8(internals.fields.length, 8);
      offset = 9;
      for (let i = 0; i < internals.fields.length; i++) {
        const len = internals.fieldsBuf0.write(internals.fields[i], offset + 2);
        internals.fieldsBuf0.writeUInt16BE(len + 1, offset);
        internals.fieldsBuf0.writeUInt8(0, offset + 2 + len);
        offset += 3 + len;
      }
      internals.fieldsBuf0 = internals.fieldsBuf0.slice(0, offset);
    }
    internals.fieldsBuf1 = Buffer.alloc(internals.fieldsSize + 9);
    internals.fieldsBuf1.writeUInt32BE(internals.fieldsTS, 0);
    internals.fieldsBuf1.writeUInt32BE(1, 4);
    internals.fieldsBuf1.writeUInt16BE(internals.fields.length, 8);
    offset = 10;
    for (let i = 0; i < internals.fields.length; i++) {
      const len = internals.fieldsBuf1.write(internals.fields[i], offset + 2);
      internals.fieldsBuf1.writeUInt16BE(len + 1, offset);
      internals.fieldsBuf1.writeUInt8(0, offset + 2 + len);
      offset += 3 + len;
    }
    internals.fieldsBuf1 = internals.fieldsBuf1.slice(0, offset);
    internals.fieldsMd5 = cryptoLib.createHash('md5').update(internals.fieldsBuf1.slice(8)).digest('hex');
    WISESource.pos2Field[pos] = fieldName;
    WISESource.field2Pos[fieldName] = pos;
    WISESource.field2Info[fieldName] = { pos: pos, friendly: friendly, db: db };
    return pos;
  }
addField ( field ) { let match = field . match ( / field:([^;]+) / ) ; const fieldName = match [ 1 ] ; let db ; if ( ( match = field . match ( / db:([^;]+) / ) ) ) { db = match [ 1 ] ; } let friendly ; if ( ( match = field . match ( / friendly:([^;]+) / ) ) ) { friendly = match [ 1 ] ; } if ( WISESource . field2Pos [ fieldName ] !== undefined ) { return WISESource . field2Pos [ fieldName ] ; } if ( internals . debug > 1 ) { console . log ( ` ${ fieldName } ${ db } ${ friendly } ${ field } ` ) ; } const pos = internals . fields . length ; newFieldsTS ( ) ; internals . fields . push ( field ) ; internals . fieldsSize += field . length + 10 ; let offset ; if ( internals . fields . length < 256 ) { internals . fieldsBuf0 = Buffer . alloc ( internals . fieldsSize + 9 ) ; internals . fieldsBuf0 . writeUInt32BE ( internals . fieldsTS , 0 ) ; internals . fieldsBuf0 . writeUInt32BE ( 0 , 4 ) ; internals . fieldsBuf0 . writeUInt8 ( internals . fields . length , 8 ) ; offset = 9 ; for ( let i = 0 ; i < internals . fields . length ; i ++ ) { const len = internals . fieldsBuf0 . write ( internals . fields [ i ] , offset + 2 ) ; internals . fieldsBuf0 . writeUInt16BE ( len + 1 , offset ) ; internals . fieldsBuf0 . writeUInt8 ( 0 , offset + 2 + len ) ; offset += 3 + len ; } internals . fieldsBuf0 = internals . fieldsBuf0 . slice ( 0 , offset ) ; } internals . fieldsBuf1 = Buffer . alloc ( internals . fieldsSize + 9 ) ; internals . fieldsBuf1 . writeUInt32BE ( internals . fieldsTS , 0 ) ; internals . fieldsBuf1 . writeUInt32BE ( 1 , 4 ) ; internals . fieldsBuf1 . writeUInt16BE ( internals . fields . length , 8 ) ; offset = 10 ; for ( let i = 0 ; i < internals . fields . length ; i ++ ) { const len = internals . fieldsBuf1 . write ( internals . fields [ i ] , offset + 2 ) ; internals . fieldsBuf1 . writeUInt16BE ( len + 1 , offset ) ; internals . fieldsBuf1 . writeUInt8 ( 0 , offset + 2 + len ) ; offset += 3 + len ; } internals . fieldsBuf1 = internals . fieldsBuf1 . slice ( 0 , offset ) ; internals . fieldsMd5 = cryptoLib . createHash ( 'md5' ) . update ( internals . fieldsBuf1 . slice ( 8 ) ) . digest ( 'hex' ) ; WISESource . pos2Field [ pos ] = fieldName ; WISESource . field2Pos [ fieldName ] = pos ; WISESource . field2Info [ fieldName ] = { pos : pos , friendly : friendly , db : db } ; return pos ; }
Add a field
 @param {string} field - An encoded field definition
Add a field @param { string } field - An encoded field definition
// Create version 0 of fields buf // Create version 1 of fields buf