AMF0 Decode Strict Array
@param buf
@returns {{len: number, value: Array}}
777784
function amf0decSArray(buf) {
    var a = [];
    var len = 5;
    var ret;
    for (var count = buf.readUInt32BE(1); count; count--) {
        ret = amf0DecodeOne(buf.slice(len));
        a.push(ret.value);
        len += ret.len;
    }
    return { len: len, value: amf0markSArray(a) }
}
893697
function bufferToString (buf) {
  const a = bufferToTuples(buf)
  const b = tuplesToStringTuples(a)
  return stringTuplesToString(b)
}
619559
public static int decodeInteger(ByteBuffer buf) {
        DerId id = DerId.decode(buf);
        if (!id.matches(DerId.TagClass.UNIVERSAL, DerId.EncodingType.PRIMITIVE, ASN1_INTEGER_TAG_NUM)) {
            throw new IllegalArgumentException("Expected INTEGER identifier, received " + id);
        }
        int len = DerUtils.decodeLength(buf);
        if (buf.remaining() < len) {
            throw new IllegalArgumentException("Insufficient content for INTEGER");
        }
        int value = 0;
        for (int i = 0; i < len; i++) {
            value = (value << 8) + (0xff & buf.get());
        }
        return value;
    }
1120576
function buf_array() {
	var bufs = [], blksz = 2048;
	var newblk = function ba_newblk(sz) {
		var o = (new_buf(sz));
		prep_blob(o, 0);
		return o;
	};

	var curbuf = newblk(blksz);

	var endbuf = function ba_endbuf() {
		if(!curbuf) return;
		if(curbuf.length > curbuf.l) curbuf = curbuf.slice(0, curbuf.l);
		if(curbuf.length > 0) bufs.push(curbuf);
		curbuf = null;
	};

	var next = function ba_next(sz) {
		if(curbuf && sz < curbuf.length - curbuf.l) return curbuf;
		endbuf();
		return (curbuf = newblk(Math.max(sz+1, blksz)));
	};

	var end = function ba_end() {
		endbuf();
		return __toBuffer([bufs]);
	};

	var push = function ba_push(buf) { endbuf(); curbuf = buf; next(blksz); };

	return ({ next:next, push:push, end:end, _bufs:bufs });
}
1114679
def decode(self, buf):
        
        index = 0
        if self.length > len(buf):
            raise exc.ParseError("Insufficient data for reading header.") 
        for (name, nbytes, typecode) in self.format:
            string = buf[index:index + nbytes]
            index += nbytes
            value = struct.unpack('<' + typecode, string)[0]
            setattr(self, name, value)
        if const.DB_SIGNATURE1 != self.signature1 or \
                const.DB_SIGNATURE2 != self.signature2:
            msg = 'Bad signatures: {0} {0}'.format(hex(self.signature1),
                                                   hex(self.signature2))
            raise exc.InvalidDatabase(msg)
571521
function amf3decArray(buf) {
    var count = amf3decUI29(buf.slice(1));
    var obj = amf3decObject(buf.slice(count.len));
    if (count.value % 2 == 1) throw new Error("This is a reference to another array, which currently we don't support!");
    return { len: count.len + obj.len, value: obj.value }
}
186279
function decode(base32) {
  $.checkArgument(typeof base32 === 'string', 'Must be base32-encoded string');
  var data = [];
  for (var i=0; i<base32.length; i++) {
    var value = base32[i];
    $.checkArgument(value in CHARSET_INVERSE_INDEX, 'Non-base32, value '+ value);
    data.push(CHARSET_INVERSE_INDEX[value]);
  }
  return data;
}
845652
function byteswap64(buf) {
  var swap = new Buffer(buf.length);
  for (var i = 0; i < buf.length; i++) {
    swap[i] = buf[buf.length -1 - i];
  }
  return swap;
}
1278700
@Override
  public NamingLookupResponse decode(final byte[] buf) {
    final AvroNamingLookupResponse avroResponse = AvroUtils.fromBytes(buf, AvroNamingLookupResponse.class);
    final List<NameAssignment> nas = new ArrayList<>(avroResponse.getTuples().size());
    for (final AvroNamingAssignment tuple : avroResponse.getTuples()) {
      nas.add(
          new NameAssignmentTuple(
              factory.getNewInstance(tuple.getId().toString()),
              new InetSocketAddress(tuple.getHost().toString(), tuple.getPort())
          )
      );
    }
    return new NamingLookupResponse(nas);
  }
391992
function read_raw_string(buf, encoding) {
  var len = buf.readUInt16BE();
  return buf.toString(encoding || 'utf8', len);
}
325124
function amf0encString(str) {
    var buf = new Buffer(3);
    buf.writeUInt8(0x02, 0);
    buf.writeUInt16BE(str.length, 1);
    return Buffer.concat([buf, new Buffer(str, 'utf8')]);
}
1020808
function encodeNumber(buf, value, len) {
  var index = 0;
  
  while (len > 0) {
    var tmpValue = value >>> ((len - 1) * 8);
    buf[index++] = tmpValue & 0xFF;
    len--;
  }
}
1015472
public static DerId decodeIdAndLength(ByteBuffer buf) {
        DerId id = DerId.decode(buf);
        DerUtils.decodeLength(buf);
        return id;
    }
660308
public static DerId decode(ByteBuffer buf) {
        if (buf == null || buf.remaining() == 0) {
            throw new IllegalArgumentException("Null or empty buffer");
        }

        DerId id = new DerId();

        byte first = buf.get(); // first octet

        // Bits 8 and 7 represent the tag class
        id.tagClass = TagClass.values()[(first & 0xc0) >> 6];

        // Bit 6 represents the encoding type
        id.encodingType = EncodingType.values()[(first & 0x20) >> 5];

        // Bits 5 through 1 represent the tag number if tag number is less than 30.
        // Bits 5 through 1 are set to 1 if the tag number is greater than 30.
        int tagNum = first & 0x1f;
        if (tagNum == 0x1F) {
            // Tag number greater than 30
            if (buf.remaining() == 0) {
                throw new IllegalArgumentException("Insufficient data to decode tag number greater than 30");
            }
            tagNum = 0;
            while (buf.hasRemaining()) {
                byte octet = buf.get();
                tagNum = (tagNum << 7) + (octet & 0x7f);
                if ((octet >> 7) == 0) {
                    break;
                }
            }
        }
        id.tagNumber = tagNum;

        return id;
    }
510755
function amfXDecodeOne(rules, buffer) {
    if (!rules[buffer.readUInt8(0)]) {
        console.log('Unknown field', buffer.readUInt8(0));
        throw new Error("Error: Unknown field");
    }
    return rules[buffer.readUInt8(0)](buffer);
}
793461
function amf0encDate(ts) {
    var buf = new Buffer(11);
    buf.writeUInt8(0x0B, 0);
    buf.writeInt16BE(0, 1);
    buf.writeDoubleBE(ts, 3);
    return buf;
}
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
}