Used to convert a ganglions decompressed back into a buffer
@param arr {Array} - An array of four numbers
@param data {Buffer} - A buffer to store into
439812
function convertGanglionArrayToBuffer (arr, data) {
  for (let i = 0; i < k.OBCINumberOfChannelsGanglion; i++) {
    data.writeInt16BE(arr[i] >> 8, (i * 3));
    data.writeInt8(arr[i] & 255, (i * 3) + 2);
  }
}
1373023
function _Matrix4x4(data) {
  Matrix.apply(this, [4, 4, data]);

  for(var i=0; i<4; i++)
    for(var j=0; j<4; j++)
      readonly(this, "m" + (i+1) + (j+1), this.values[4 * i + j]);
}
172985
function(data) {
    var values = [],
        i      = 0;
    for (i = 0; i < data.length; i++) {
      values.push(this.normalise(data[i]));
    }
    return values;
  }
645289
function expandRLEData(rleData, padding) {
  padding = padding || [];
  const data = [];
  for (let ii = 0; ii < rleData.length; ii += 4) {
    const runLength = rleData[ii];
    const element = rleData.slice(ii + 1, ii + 4);
    element.push.apply(element, padding);
    for (let jj = 0; jj < runLength; ++jj) {
      data.push.apply(data, element);
    }
  }
  return data;
}
514968
@Override
    public INDArray compress(double[] data) {
        return compress(data, new int[] {1, data.length}, Nd4j.order());
    }
737159
function __serializeArrayBuffer(data) {
	let length = data.byteLength;
	let lengthData = new Uint32Array([length]);
	return [lengthData.buffer, data];
}
1047790
function __getLengthByArrayBuffers(data) {
	let length = 0;
	for (let key in data) {
		length += data[key].byteLength;
	}
	return length;
}
770903
function(data) {
            var paramArray = [],
                key, value;
        // TODO: use `object` module
            for (key in data) {
                value = data[key];
                key = ENCODE_URI_COMPONENT(key);
                paramArray.push((value === null) ? key : (key + '=' + ENCODE_URI_COMPONENT(value)));
            }
            console.log(NAME, '_toQueryString --> '+paramArray.join('&'));
            return paramArray.join('&');
        }
3949
function encodeArrayBuffer(packet, supportsBinary, callback) {
  if (!supportsBinary) {
    return exports.encodeBase64Packet(packet, callback);
  }

  var data = packet.data;
  var contentArray = new Uint8Array(data);
  var resultBuffer = new Uint8Array(1 + data.byteLength);

  resultBuffer[0] = packets[packet.type];
  for (var i = 0; i < contentArray.length; i++) {
    resultBuffer[i+1] = contentArray[i];
  }

  return callback(resultBuffer.buffer);
}
901380
@Override
    public INDArray compress(float[] data, int[] shape, char order) {
        FloatPointer pointer = new FloatPointer(data);

        DataBuffer shapeInfo = Nd4j.getShapeInfoProvider().createShapeInformation(ArrayUtil.toLongArray(shape), order, DataType.FLOAT).getFirst();
        DataBuffer buffer = compressPointer(DataTypeEx.FLOAT, pointer, data.length, 4);

        return Nd4j.createArrayFromShapeBuffer(buffer, shapeInfo);
    }
715203
function decompress( buffer ) {

  var chunks = []
  var chunkType = ADC.CHUNK_UNKNOWN
  var position = 0
  var length = 0

  windowOffset = 0

  while( position < buffer.length ) {
    chunkType = ADC.getChunkType( buffer[ position ] )
    length = ADC.getSequenceLength( buffer[ position ] )
    switch( chunkType ) {
      case ADC.CHUNK_DATA:
        chunks.push( decodeData( window, buffer, position ) )
        break
      case ADC.CHUNK_THREE:
        chunks.push( decodeRunlength( window, buffer, position ) )
        break
      case ADC.CHUNK_TWO:
        chunks.push( decodeRunlength( window, buffer, position ) )
        break
      default:
        throw new Error( 'Unknown chunk type 0x' + buffer[ position ].toString(16) + ' at ' + position )
    }
    position += length
  }

  return Buffer.concat( chunks )

}
1359522
private static int[] calculate(byte[] data) {
    int A = 0x67452301;
    int B = 0xEFCDAB89;
    int C = 0x98BADCFE;
    int D = 0x10325476;
    int E = 0xC3D2E1F0;

    int[] W = new int[80]; // working buffer
    int len = data.length;
    int off = 0;
    int   X, i, n = len/4;

    boolean done = false;
    boolean padded = false;

    while( !done ) {
      // Fill W array
      for(i=0; (i<16) && (n > 0); n--, off+=4)
        W[i++] = (data[off+3] & 0xFF) | ((data[off+2] & 0xFF) << 8) |
          ((data[off+1] & 0xFF) << 16) | ((data[off] & 0xFF) << 24);

      if (i < 16) {             // pad
        if( !padded ) {         // first time past end of data
          X=len%4;
          int pad1 = 0;
          for (int j = 0; j < X; ++j) {
            pad1 |= ((int) (data[off + j] & 0xFF)) << (24 - 8 * j);
          }
          W[i++] = pad1 | (1 << (31 - X * 8));
//            W[i++] = (X!=0)?(((int)msbf(data,off,X)<<((4-X)*8))|(1<<(31-X*8))):(1<<31);
          if (i==15) W[15]=0;   // 64 bit length of data as bits can't fit
          padded = true;        // don't pad again if there is another iteration
        }
        if (i <= 14) {          // last iteration
          while( i<14 ) W[i++] = 0;
          // bit count = len*8
          W[14] = len >>> 29;
          W[15] = len << 3;
          done = true;
        }
        i = 16;
      }

      do {
        W[i] = ((X = W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16]) << 1) | (X >>> 31);
      } while(++i<80);

      // Transform
      int A0 = A;
      int B0 = B;
      int C0 = C;
      int D0 = D;
      int E0 = E;
      i = 0;
      do { X=((A<<5)|(A>>>27))+((B&C)|(~B&D))+E+W[i]+0x5A827999;
      E=D;D=C;C=(B<<30)|(B>>>2);B=A;A=X; } while(++i<20);
      do { X=((A<<5)|(A>>>27))+(B^C^D)+E+W[i]+0x6ED9EBA1;
      E=D;D=C;C=(B<<30)|(B>>>2);B=A;A=X; } while(++i<40);
      do { X=((A<<5)|(A>>>27))+((B&C)|(B&D)|(C&D))+E+W[i]+0x8F1BBCDC;
      E=D;D=C;C=(B<<30)|(B>>>2);B=A;A=X; } while(++i<60);
      do { X=((A<<5)|(A>>>27))+(B^C^D)+E+W[i]+0xCA62C1D6;
      E=D;D=C;C=(B<<30)|(B>>>2);B=A;A=X; } while(++i<80);
      A += A0;
      B += B0;
      C += C0;
      D += D0;
      E += E0;
    }

    int[] result = {A, B, C, D, E};
    return result;
  }
414917
function _gpfNodeBuffer2JsArray (buffer) {
    var result = [],
        len = buffer.length,
        idx;
    for (idx = 0; idx < len; ++idx) {
        result.push(buffer.readUInt8(idx));
    }
    return result;
}
1335292
function stringToArrayBuffer(text) {
      if (window.TextEncoder !== undefined) {
        return new TextEncoder().encode(text).buffer;
      }

      var array = new Uint8Array(new ArrayBuffer(text.length));

      for (var i = 0, il = text.length; i < il; i++) {
        var value = text.charCodeAt(i);

        // Replacing multi-byte character with space(0x20).
        array[i] = value > 0xff ? 0x20 : value;
      }

      return array.buffer;
    }
749021
function(into, data) {
                            var existingDataLen = into.length == 0 ? 0 : into[0].length - 1;
                            var i = 0;
                            var j = 0;
                            for (; i<into.length && j<data.length; ) {
                                if (into[i][0] == data[j][0]) {
                                    into[i].push(data[j][1]);
                                    i++;
                                    j++;
                                }
                                else if (into[i][0] < data[j][0]) {
                                    into[i].push(null);
                                    i++;
                                }
                                else {
                                    var arr = [data[j][0]];
                                    for (var k=1; k<into[i].length; k++) {
                                        arr.push(null);
                                    }
                                    arr.push(data[j][1]);
                                    into.splice(i,0,arr);
                                    i++;
                                    j++;
                                }
                            }
                            while (j<data.length) {
                                var arr = [data[j][0]];
                                for (var k=0; k<existingDataLen; k++) {
                                    arr.push(null);
                                }
                                arr.push(data[j][1]);
                                into.push(arr);
                                j++;
                            }
                        }
279401
function(arr, i) {
			var ret = arr.slice(0);
			for (var j = 0; j < i; j++) {
				ret = [ret[ret.length - 1]].concat(ret.slice(0, ret.length - 1));
			}
			return ret;
		}
903886
function stringToBuffer(data) {
    return (typeof Buffer.from === 'function' && Buffer.from !== Uint8Array.from) ?
        Buffer.from(data) : new Buffer(data);
}