src/Response/StreamReader.php
public function readValue($type){
        $binaryLength = substr($this->data, $this->offset, 4);
        $this->offset += 4;

        if ($binaryLength === "\xff\xff\xff\xff")
            return null;

        $length = unpack('N', $binaryLength)[1];

        // do not use $this->read() for performance
        // substr() returns FALSE when OFFSET is equal to the length of data
        $data = ($length == 0) ? '' : substr($this->data, $this->offset, $length);
        $this->offset += $length;
        if(!is_array($type)){
            $class = Type\Base::$typeClassMap[$type];
            return $class::parse($data);
        }
        else{
            if (!isset(Type\Base::$typeClassMap[$type['type']]))
                throw new Type\Exception('Unknown type ' . var_export($type, true));
            $class = Type\Base::$typeClassMap[$type['type']];
            return $class::parse($data, $type['definition']);
        }
    }
public function readValue($type){
        $binaryLength = substr($this->data, $this->offset, 4);
        $this->offset += 4;

        if ($binaryLength === "\xff\xff\xff\xff")
            return null;

        $length = unpack('N', $binaryLength)[1];

        // do not use $this->read() for performance
        // substr() returns FALSE when OFFSET is equal to the length of data
        $data = ($length == 0) ? '' : substr($this->data, $this->offset, $length);
        $this->offset += $length;
        if(!is_array($type)){
            $class = Type\Base::$typeClassMap[$type];
            return $class::parse($data);
        }
        else{
            if (!isset(Type\Base::$typeClassMap[$type['type']]))
                throw new Type\Exception('Unknown type ' . var_export($type, true));
            $class = Type\Base::$typeClassMap[$type['type']];
            return $class::parse($data, $type['definition']);
        }
    }
read a [bytes] and read by type

@param int|array $type
@return mixed