public function writePendingResponses(AssessmentTestSeeker $seeker, PendingResponses $pendingResponses)
    {
        try {
            $state = $pendingResponses->getState();
            $itemRef = $pendingResponses->getAssessmentItemRef();
            $occurence = $pendingResponses->getOccurence();

            // Write the state.
            $responseDeclarations = $itemRef->getResponseDeclarations();
            $varCount = count($state);
            $this->writeTinyInt($varCount);

            foreach ($state as $responseVariable) {
                $respId = $responseVariable->getIdentifier();
                if (isset($responseDeclarations[$respId]) === true) {
                    $this->writeShort($seeker->seekPosition($responseDeclarations[$respId]));
                    $this->writeVariableValue($responseVariable);
                } else {
                    $msg = "No response variable with identifier '${respId}' found in related assessmentItemRef.";
                    throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES);
                }
            }

            // Write the assessmentItemRef.
            $this->writeShort($seeker->seekPosition($itemRef));

            // Write the occurence number.
            $this->writeTinyInt($occurence);
        } catch (BinaryStreamAccessException $e) {
            $msg = "An error occured while reading some pending responses.";
            throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
        } catch (OutOfBoundsException $e) {
            $msg = "A QTI component position could not be found in the assessmentTest tree structure.";
            throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
        }
    }