public function setState($state)
    {
        $state &= ~248; // 0b11111000

        if (($state & ($state - 1)) !== 0) {
            throw new InvalidArgumentException("State must be a valid state value");
        }

        $this->setFlags($state);
        $this->streamCallback = null;
    }