Decode a whole buffer of AMF values according to rules and return in array
@param rules
@param buffer
@returns {Array}
770908
function amfXDecode(rules, buffer) {
    // We shall receive clean buffer and will respond with an array of values
    var resp = [];
    var res;
    for (var i = 0; i < buffer.length;) {
        res = amfXDecodeOne(rules, buffer.slice(i));
        i += res.len;
        resp.push(res.value); // Add the response
    }
    return resp;
}
652565
function amf0encSArray(a) {
    console.log('Do strict array!');
    var buf = new Buffer(5);
    buf.writeUInt8(0x0A,0);
    buf.writeUInt32BE(a.length,1);
    var i;
    for (i=0;i< a.length;i++) {
        buf = Buffer.concat([buf,amf0EncodeOne(a[i])]);
    }
    return buf;
}
96863
function decode(str) {
	// FIXME: Check for multiplication overflow
	if (str.length > 12) {
		throw new TypeError("Number encoded is too large");
	}

	var num = new UInt64();
	for (let i=0; i<str.length; i++) {
		let n = CHARS.indexOf(str[i]);
		if (n === -1) {
			throw new TypeError("Unknown character in string");
		}
		num.multiply(SIXTY_TWO);
		num.add(new UInt64(n));
	}

	var buf = new Buffer(8);
	num.div(UINT32_CAPACITY);
	buf.writeUInt32BE(parseInt(num.toString()), 0);
	buf.writeUInt32BE(num.remainder, 4);
	return buf;
}
1041991
function (chrs, buffer, pos, strict, opts) {
                        var isValid = opts.regex.val1.test(chrs);
                        if (!strict && !isValid) {
                            if (chrs.charAt(1) == opts.separator || "-./".indexOf(chrs.charAt(1)) != -1) {
                                isValid = opts.regex.val1.test("0" + chrs.charAt(0));
                                if (isValid) {
                                    buffer[pos - 1] = "0";
                                    return { "pos": pos, "c": chrs.charAt(0) };
                                }
                            }
                        }
                        return isValid;
                    }
1251248
function decode (bufOrString) {
  if (Buffer.isBuffer(bufOrString)) {
    bufOrString = bufOrString.toString()
  }

  const code = bufOrString.substring(0, 1)
  bufOrString = bufOrString.substring(1, bufOrString.length)

  if (typeof bufOrString === 'string') {
    bufOrString = Buffer.from(bufOrString)
  }

  const base = getBase(code)
  return Buffer.from(base.decode(bufOrString.toString()))
}
896801
function rules () {
        var pub = {};
        pub.maxLength = function (val, max) {

            if (!Array.isArray(val) && typeof val !== 'string' || typeof max !== 'number') {
                return getResult(new Error('rules.maxLength(fail): value must be a string or array, max must be a number'));
            }

            if (val.length > max) {
                return getResult(getError('maxLength', max, val));
            }

            return getResult(null);
        };
        pub.minLength = function (val, min) {

            if (!Array.isArray(val) && typeof val !== 'string' || typeof min !== 'number') {
                return getResult(new Error('rules.minLength(fail): value must be a string or array, min must be a number'));
            }

            if (val.length < min) {
                return getResult(getError('minLength', min, val));
            }

            return getResult(null);
        };
        pub.minimum = function (val, min) {

            if (typeof val !== 'number' || typeof min !== 'number') {
                return getResult(new Error('rules.minimum(fail): value must be a number, min must be a number'));
            }

            if (val < min) {
                return getResult(getError('minimum', min, val));
            }

            return getResult(null);
        };
        pub.maximum = function (val, max) {

            if (typeof val !== 'number' || typeof max !== 'number') {
                return getResult(new Error('rules.maximum(fail): value must be a number, max must be a number'));
            }

            if (val > max) {
                return getResult(getError('maximum', max, val));
            }

            return getResult(null);
        };
        pub.exclusiveMinimum = function (val, min) {

            if (typeof val !== 'number' || typeof min !== 'number') {
                return getResult(new Error('rules.exclusiveMinimum(fail): value must be a number, min must be a number'));
            }

            if (val <= min) {
                return getResult(getError('exclusiveMinimum', min, val));
            }

            return getResult(null);
        };
        pub.exclusiveMaximum = function (val, max) {

            if (typeof val !== 'number' || typeof max !== 'number') {
                return getResult(new Error('rules.exclusiveMaximum(fail): value must be a number, max must be a number'));
            }

            if (val >= max) {
                return getResult(getError('exclusiveMinimum', max, val));
            }

            return getResult(null);
        };
        pub.divisibleBy = function (val, div) {

            if (typeof val !== 'number' || typeof div !== 'number') {
                return getResult(new Error('rules.divisibleBy(fail): value must be a number, div must be a number'));
            }

            var multiplier = Math.max((val - Math.floor(val)).toString().length - 2,
                (div - Math.floor(div)).toString().length - 2);
            multiplier = multiplier > 0 ? Math.pow(10, multiplier) : 1;

            if ((val * multiplier) % (div * multiplier) !== 0) {
                return getResult(getError('divisibleBy', div, val));
            }

            return getResult(null);
        };
        pub.minItems = function (val, min) {

            if (!Array.isArray(val) || typeof min !== 'number') {
                return getResult(new Error('rules.minItems(fail): value must be a array, min must be a number'));
            }

            if (val.length < min) {
                return getResult(getError('minItems', min, val.length));
            }

            return getResult(null);
        };
        pub.maxItems = function (val, max) {

            if (!Array.isArray(val) || typeof max !== 'number') {
                return getResult(new Error('rules.maxItems(fail): value must be a array, max must be a number'));
            }

            if (val.length > max) {
                return getResult(getError('maxItems', max, val.length));
            }

            return getResult(null);
        };
        pub.uniqueItems = function (val) {

            if (!Array.isArray(val)) {
                return getResult(new Error('rules.uniqueItems(fail): value must be a array'));
            }

            if (!(uniqueArrayHelper(val))) {
                return getResult(getError('uniqueItems', val, true));
            }

            return getResult(null);
        };
        pub['enum'] = function (val, en) {

            if (typeof val === 'undefined' || !Array.isArray(en)) {
                return getResult(new Error('rules.enum(fail): value must be a defined and enum mus be a array'));
            }

            if (en.indexOf(val) === -1) {
                return getResult(getError('enum', en, val));
            }

            return getResult(null);
        };

        return pub;
    }
953644
function amf3Encode(a) {
    var buf = new Buffer(0);
    a.forEach(function (o) {
        buf = Buffer.concat([buf, amf3EncodeOne(o)]);
    });
    return buf;
}
1255749
public byte decodeBuffer(InputStream in)[] throws IOException {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        decodeBuffer(in, outStream);
        return (outStream.toByteArray());
    }
610508
function magicBuffer(buf, cb) {
  try {
    buf = bufferUtils.toBuffer(buf);
    magic(buf, cb);
  } catch(err) {
    cb(err);
  }
}
620207
private void parsePreamble(ByteBuffer buffer) {
        if (_partialBoundary > 0) {
            int partial = _delimiterSearch.startsWith(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining(), _partialBoundary);
            if (partial > 0) {
                if (partial == _delimiterSearch.getLength()) {
                    buffer.position(buffer.position() + partial - _partialBoundary);
                    _partialBoundary = 0;
                    setState(State.DELIMITER);
                    return;
                }

                _partialBoundary = partial;
                BufferUtils.clear(buffer);
                return;
            }

            _partialBoundary = 0;
        }

        int delimiter = _delimiterSearch.match(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
        if (delimiter >= 0) {
            buffer.position(delimiter - buffer.arrayOffset() + _delimiterSearch.getLength());
            setState(State.DELIMITER);
            return;
        }

        _partialBoundary = _delimiterSearch.endsWith(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
        BufferUtils.clear(buffer);
    }
1158095
function toArray(buffer) {
    if(!buffer) buffer = new Buffer(0);
    var view = new Uint8Array(buffer.length);
    for (var i = 0; i < buffer.length; ++i) {
        view[i] = buffer[i];
    }
    return view;
  }
231904
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        int nciphers = SMBUtil.readInt2(buffer, bufferIndex);
        bufferIndex += 2;

        this.ciphers = new int[nciphers];
        for ( int i = 0; i < nciphers; i++ ) {
            this.ciphers[ i ] = SMBUtil.readInt2(buffer, bufferIndex);
            bufferIndex += 2;
        }

        return bufferIndex - start;
    }
1249251
function amf0decLongString(buf) {
    var sLen = buf.readUInt32BE(1);
    return { len: 5 + sLen, value: buf.toString('utf8', 5, 5 + sLen) }
}
1259556
function amf0encArray(a) {
    var l = 0;
    if (a instanceof Array) l = a.length; else l = Object.keys(a).length;
    console.log('Array encode', l, a);
    var buf = new Buffer(5);
    buf.writeUInt8(8,0);
    buf.writeUInt32BE(l,1);
    var data = amf0encObject(a);
    return Buffer.concat([buf,data.slice(1)]);
}
52452
function ab2hex(buffer) {
  const hexArr = Array.prototype.map.call(
    new Uint8Array(buffer),
    function (bit) {
      return ('00' + bit.toString(16)).slice(-2)
    }
  )
  return hexArr.join('')
}
252161
function decodeAMF0Cmd(dbuf) {
    var buffer = dbuf;
    var resp = {};

    var cmd = amf0DecodeOne(buffer);
    resp.cmd = cmd.value;
    buffer = buffer.slice(cmd.len);

    if (rtmpCmdDecode[cmd.value]) {
        rtmpCmdDecode[cmd.value].forEach(function (n) {
            if (buffer.length > 0) {
                var r = amf0DecodeOne(buffer);
                buffer = buffer.slice(r.len);
                resp[n] = r.value;
            }
        });
    } else {
        console.log('Unknown command', resp);
    }
    return resp
}
1298329
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        this.chunksWritten = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        this.chunkBytesWritten = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        this.totalBytesWritten = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        return bufferIndex - start;
    }