public function decode($d, &$pos = 0)
	{
		if (!is_string($d)) {
			throw new Exception('Tried to decode non-string data.', 1);
		}

		if (strlen($d) <= $pos) {
			return null;
		}

		switch ($d[$pos]) {
			case 'd':
				$ret = [];
				$pos++;
				
				while ($d[$pos] != 'e') {
					$key = $this->decode($d, $pos);
					$value = $this->decode($d, $pos);
					if (is_null($key) || is_null($value)) {
						break;
					}
					$ret[$key] = $value;
				}
				$pos++;
				return $ret;
			case 'l':
				$ret = [];
				$pos++;
				while ($d[$pos] != 'e') {
					$value = $this->decode($d, $pos);
					if (is_null($value)) {
						break;
					}
					$ret[] = $value;
				}
				$pos++;
				return $ret;
			case 'i':
				$pos++;
				$length = strpos($d, 'e', $pos) - $pos;
				$value = intval(substr($d, $pos, $length));
				$pos += $length + 1;
				return $value;
			default:
				$length = strpos($d, ':', $pos) - $pos;

				if (!$this->validLength($length)) {
					return null;
				}

				$valueLength = intval(substr($d, $pos, $length));
				$pos += $length + 1;
				$str = substr($d, $pos, $valueLength);
				$pos += $valueLength;
				return $str;
		}
	}