Decode one value from the Buffer according to the applied rules
@param rules
@param buffer
@returns {*}
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);
}
753970
function decode(payload) {
    var base = 58;

    var length = payload.length;
    var num = int(0);
    var leading_zero = 0;
    var seen_other = false;
    for (var i=0; i<length ; ++i) {
        var char = payload[i];
        var p = positions[char];

        // if we encounter an invalid character, decoding fails
        if (p === undefined) {
            throw new Error('invalid base58 string: ' + payload);
        }

        num = num.mul(base).add(p);

        if (char == '1' && !seen_other) {
            ++leading_zero;
        }
        else {
            seen_other = true;
        }
    }

    var hex = num.toString(16);

    // num.toString(16) does not have leading 0
    if (hex.length % 2 !== 0) {
        hex = '0' + hex;
    }

    // strings starting with only ones need to be adjusted
    // e.g. '1' should map to '00' and not '0000'
    if (leading_zero && !seen_other) {
      --leading_zero;
    }

    while (leading_zero-- > 0) {
        hex = '00' + hex;
    }

    return hex;
}
808915
function (buffer) {
        var header = new Uint32Array(buffer, 0, 4);
        if (header[0] !== 0x46546C67) {
            this.trigger('error', 'Invalid glTF binary format: Invalid header');
            return;
        }
        if (header[0] < 2) {
            this.trigger('error', 'Only glTF2.0 is supported.');
            return;
        }

        var dataView = new DataView(buffer, 12);

        var json;
        var buffers = [];
        // Read chunks
        for (var i = 0; i < dataView.byteLength;) {
            var chunkLength = dataView.getUint32(i, true);
            i += 4;
            var chunkType = dataView.getUint32(i, true);
            i += 4;

            // json
            if (chunkType === 0x4E4F534A) {
                var arr = new Uint8Array(buffer, i + 12, chunkLength);
                // TODO, for the browser not support TextDecoder.
                var decoder = new TextDecoder();
                var str = decoder.decode(arr);
                try {
                    json = JSON.parse(str);
                }
                catch (e) {
                    this.trigger('error', 'JSON Parse error:' + e.toString());
                    return;
                }
            }
            else if (chunkType === 0x004E4942) {
                buffers.push(buffer.slice(i + 12, i + 12 + chunkLength));
            }

            i += chunkLength;
        }
        if (!json) {
            this.trigger('error', 'Invalid glTF binary format: Can\'t find JSON.');
            return;
        }

        return this.parse(json, buffers);
    }
1109657
int decode(Buffer b) {
        int ptr = 0;
        DecodeAux t = decode_tree;
        int lok = b.look(t.tabn);

        if (lok >= 0) {
            ptr = t.tab[lok];
            b.adv(t.tabl[lok]);
            if (ptr <= 0) {
                return -ptr;
            }
        }
        do {
            switch (b.read1()) {
                case 0:
                    ptr = t.ptr0[ptr];
                    break;
                case 1:
                    ptr = t.ptr1[ptr];
                    break;
                case -1:
                default:
                    return (-1);
            }
        } while (ptr > 0);
        return (-ptr);
    }
627266
function decode(msg) {
  const len = msg.length;
  if (len > 0) {
    const c = msg.charCodeAt(len - 1);
    if (c >= 1 && c <= 8) {
      const provided = msg.substr(len - c);
      const computed = String.fromCharCode(c).repeat(c);
      if (provided === computed) {
        return msg.substr(0, len - c);
      }
    }
  }
  throw new Error('Invalid padding');
}
148537
function decode(data) {
    var prefix = protocols[data[0]];
    if (!prefix) { // 36 to 255 should be ""
        prefix = "";
    }    
    return prefix + util.bytesToString(data.slice(1));      
}
496821
public int decode(final InputStream stream, final ByteBuffer buffer) throws IOException {
        while (buffer.remaining() >= 64) {
            int val = stream.read();
            if (val < 0) {
                break; // EOF
            }

            if ((val & COMPRESSED_RUN_MASK) == COMPRESSED_RUN_MASK) {
                int count = val & ~COMPRESSED_RUN_MASK;

                int pixel = stream.read();
                if (pixel < 0) {
                    break; // EOF
                }

                for (int i = 0; i < count; i++) {
                    buffer.put((byte) pixel);
                }
            }
            else {
                buffer.put((byte) val);
            }
        }

        return buffer.position();
    }
167154
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        this.replaceIfExists = buffer[ bufferIndex ] != 0;
        bufferIndex += 8;
        bufferIndex += 8;

        int nameLen = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        byte[] nameBytes = new byte[nameLen];
        System.arraycopy(buffer, bufferIndex, nameBytes, 0, nameBytes.length);
        bufferIndex += nameLen;
        this.fileName = new String(nameBytes, StandardCharsets.UTF_16LE);
        return bufferIndex - start;
    }
372140
public static Histogram decodeFromByteBuffer(final ByteBuffer buffer,
                                                 final long minBarForHighestTrackableValue) {
        return (Histogram) decodeFromByteBuffer(buffer, Histogram.class, minBarForHighestTrackableValue);
    }
1349946
def decode_options(self, buffer):
        """"""
        fmt = b"!"
        options = {}

        log.debug("decode_options: buffer is: %s", repr(buffer))
        log.debug("size of buffer is %d bytes", len(buffer))
        if len(buffer) == 0:
            log.debug("size of buffer is zero, returning empty hash")
            return {}

        # Count the nulls in the buffer. Each one terminates a string.
        log.debug("about to iterate options buffer counting nulls")
        length = 0
        for i in range(len(buffer)):
            if ord(buffer[i:i+1]) == 0:
                log.debug("found a null at length %d", length)
                if length > 0:
                    fmt += b"%dsx" % length
                    length = -1
                else:
                    raise TftpException("Invalid options in buffer")
            length += 1

        log.debug("about to unpack, fmt is: %s", fmt)
        mystruct = struct.unpack(fmt, buffer)

        tftpassert(len(mystruct) % 2 == 0,
                   "packet with odd number of option/value pairs")

        for i in range(0, len(mystruct), 2):
            key = mystruct[i].decode('ascii')
            val = mystruct[i+1].decode('ascii')
            log.debug("setting option %s to %s", key, val)
            log.debug("types are %s and %s", type(key), type(val))
            options[key] = val

        return options
1059716
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;

        // Read total allocation units.
        this.alloc = SMBUtil.readInt8(buffer, bufferIndex);
        bufferIndex += 8;

        // read caller available allocation units
        this.free = SMBUtil.readInt8(buffer, bufferIndex);
        bufferIndex += 8;

        // skip actual free units
        bufferIndex += 8;

        this.sectPerAlloc = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;

        this.bytesPerSect = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;

        return bufferIndex - start;
    }
899076
function decode(base32String) {
	// Decode to Buffer
	var bytes = base32.parse(base32String, {
		out: Buffer.alloc,
		loose: true
	});

	return bytes.toString("hex");
}
174035
function typeOf (rule) {
  var ruleType = typeof rule
  
  return ruleType === 'function'
    ? ruleType
    : ruleType !== 'object'
      ? (rule.length === 0
          ? 'noop'
          : (rule === 0
              ? 'zero'
              : ruleType
            )
        )
      : Buffer.isBuffer(rule)
        ? 'buffer'
        : !isArray(rule)
          ? ((has(rule, 'start') && has(rule, 'end')
              ? 'range'
              : has(rule, 'start')
                ? 'rangestart'
                : has(rule, 'end')
                  ? 'rangeend'
                  : has(rule, 'firstOf')
                    ? (( (isArray(rule.firstOf) && sameTypeArray(rule.firstOf) )
                        || typeof rule.firstOf === 'string'
                        )
                      && rule.firstOf.length > 1
                      )
                        ? 'firstof'
                        : 'invalid firstof'
                    : 'invalid'
              )
              + '_object'
            )
          : !sameTypeArray(rule)
            ? 'multi types array'
            : ((Buffer.isBuffer( rule[0] )
                ? 'buffer'
                : typeof rule[0]
                )
                + '_array'
              )
}
1183219
function (buffer) {
        var str = '',
            uArrayVal = new Uint8Array(buffer),

            i,
            ii;

        for (i = 0, ii = uArrayVal.length; i < ii; i++) {
            str += String.fromCharCode(uArrayVal[i]);
        }

        return str;
    }
738367
function decode(events) {
  let indexList = [];
  let eventsByte = parseInt(events, 16);

  if(eventsByte & APPEARANCE_MASK) {
    indexList.push(APPEARANCE);
  }
  if(eventsByte & DISPLACEMENT_MASK) {
    indexList.push(DISPLACEMENT);
  }
  if(eventsByte & PACKETS_MASK) {
    indexList.push(PACKETS);
  }
  if(eventsByte & KEEPALIVE_MASK) {
    indexList.push(KEEPALIVE);
  }
  if(eventsByte & DISAPPEARANCE_MASK) {
    indexList.push(DISAPPEARANCE);
  }

  return indexList;
}
506742
@Override
    public int decode ( byte[] buffer, int bufferIndex, int len ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        this.createTime = SMBUtil.readTime(buffer, bufferIndex);
        bufferIndex += 8;
        this.lastAccessTime = SMBUtil.readTime(buffer, bufferIndex);
        bufferIndex += 8;
        this.lastWriteTime = SMBUtil.readTime(buffer, bufferIndex);
        bufferIndex += 8;
        this.changeTime = SMBUtil.readTime(buffer, bufferIndex);
        bufferIndex += 8;
        this.attributes = SMBUtil.readInt4(buffer, bufferIndex);
        bufferIndex += 4;
        return bufferIndex - start;
    }
1309979
@Override
    public int decode ( byte[] buffer, int bufferIndex ) throws SMBProtocolDecodingException {
        int len = super.decode(buffer, bufferIndex);
        if ( this.byteCount == 0 ) {
            // otherwise hasMore may not be correctly set
            readBytesWireFormat(buffer, len + bufferIndex);
        }
        nextElement();
        return len;
    }