protected function assertRemainingPacketLength($value = null, $fromPacket = true)
    {
        if ($value === null && $this->remainingPacketLength === 0) {
            $this->throwException('Expected payload but remaining packet length is zero.', $fromPacket);
        }

        if ($value !== null && $this->remainingPacketLength !== $value) {
            $this->throwException(
                sprintf(
                    'Expected remaining packet length of %d bytes but got %d.',
                    $value,
                    $this->remainingPacketLength
                ),
                $fromPacket
            );
        }
    }