You are here

private function Decoder::decodeByType in Smart IP 7.2

Same name and namespace in other branches
  1. 6.2 includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Decoder.php \MaxMind\Db\Reader\Decoder::decodeByType()
1 call to Decoder::decodeByType()
Decoder::decode in includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Decoder.php

File

includes/vendor/maxmind-db/reader/src/MaxMind/Db/Reader/Decoder.php, line 101

Class

Decoder

Namespace

MaxMind\Db\Reader

Code

private function decodeByType($type, $offset, $size) {
  switch ($type) {
    case 'map':
      return $this
        ->decodeMap($size, $offset);
    case 'array':
      return $this
        ->decodeArray($size, $offset);
    case 'boolean':
      return array(
        $this
          ->decodeBoolean($size),
        $offset,
      );
  }
  $newOffset = $offset + $size;
  $bytes = Util::read($this->fileStream, $offset, $size);
  switch ($type) {
    case 'utf8_string':
      return array(
        $this
          ->decodeString($bytes),
        $newOffset,
      );
    case 'double':
      $this
        ->verifySize(8, $size);
      return array(
        $this
          ->decodeDouble($bytes),
        $newOffset,
      );
    case 'float':
      $this
        ->verifySize(4, $size);
      return array(
        $this
          ->decodeFloat($bytes),
        $newOffset,
      );
    case 'bytes':
      return array(
        $bytes,
        $newOffset,
      );
    case 'uint16':
    case 'uint32':
      return array(
        $this
          ->decodeUint($bytes),
        $newOffset,
      );
    case 'int32':
      return array(
        $this
          ->decodeInt32($bytes),
        $newOffset,
      );
    case 'uint64':
    case 'uint128':
      return array(
        $this
          ->decodeBigUint($bytes, $size),
        $newOffset,
      );
    default:
      throw new InvalidDatabaseException("Unknown or unexpected type: " . $type);
  }
}