anchor.diff:      (prog1 (setf (bref iobuf end) octet)
         (setf (iobuf-end iobuf) (1+ end)))))
   
  -(defun replace-ub8 (destination source start1 end1 start2 end2)
  +(defun replace-ub8sv->ub8sv (destination source start1 end1 start2 end2)
     (declare (type ub8-simple-vector destination source)
  +           (type iobuf-index start1 start2 end1 end2))
  +  (let ((nbytes (min (- end1 start1)
  +                     (- end2 start2))))
  +    (replace destination source
  +             :start1 start1 :end1 end1
  +             :start2 start2 :end2 end2)
  +    (values nbytes)))
  +
  +(defun replace-ub8sv->ub8cv (destination source start1 end1 start2 end2)
  +  (declare (type ub8-simple-vector source)
  +           (type ub8-complex-vector destination)
  +           (type iobuf-index start1 start2 end1 end2))
  +  (let ((nbytes (min (- end1 start1)
  +                     (- end2 start2))))
  +    (replace destination source
  +             :start1 start1 :end1 end1
  +             :start2 start2 :end2 end2)
  +    (values nbytes)))
  +
  +(defun replace-ub8cv->ub8sv (destination source start1 end1 start2 end2)
  +  (declare (type ub8-complex-vector source)
  +           (type ub8-simple-vector destination)
              (type iobuf-index start1 start2 end1 end2))
     (let ((nbytes (min (- end1 start1)
                        (- end2 start2))))
  
positive.code: ;; almost 128 MB: large enough for a stream buffer,
  ;; but small enough to fit into a fixnum
  (deftype iobuf-index () '(unsigned-byte 27))
  (deftype iobuf-length () '(integer 0 #.(expt 2 27)))
  
  (deftype iobuf-data-vector () 'ub8-simple-vector)
  
  (defstruct (iobuf (:constructor %make-iobuf (data)))
    (lock (bt:make-lock "IObuf lock") :read-only t)
    (data nil :type iobuf-data-vector :read-only t)
    (start 0 :type iobuf-index)
    (end 0 :type iobuf-index))
  
  (defun make-iobuf-data-vector (size)
    (declare (type iobuf-index size))
    (make-array size :element-type 'ub8 :initial-element 0))
  
  (defun make-iobuf (&optional size)
    (check-type size (or null iobuf-index))
    (%make-iobuf (make-iobuf-data-vector (or size +default-iobuf-size+))))
  
  (defun iobuf-size (iobuf)
    (declare (type iobuf iobuf))
    (length (iobuf-data iobuf)))
  
  (defun iobuf-available-octets (iobuf)
    (declare (type iobuf iobuf))
  
negative.code: 
  (defun iobuf->vector (iobuf vector start end)
    (declare (type iobuf iobuf)
             (type ub8-vector vector)
             (type iobuf-index start end))
    (when (iobuf-empty-p iobuf)
      (iobuf-reset iobuf))
    (multiple-value-bind (iobuf-data data-start data-end)
        (iobuf-next-data-zone iobuf)
      (declare (type iobuf-index data-start data-end))
      (let ((nbytes
             (etypecase vector
               (ub8-simple-vector
                (replace-ub8sv->ub8sv vector iobuf-data
                                      start end
                                      data-start data-end))
               (ub8-complex-vector
                (replace-ub8sv->ub8cv vector iobuf-data
                                      start end
                                      data-start data-end)))))
        (setf (iobuf-start iobuf) (+ data-start (the iobuf-index nbytes)))
        (values nbytes))))
  
  (defun vector->iobuf (iobuf vector start end)
    (declare (type iobuf iobuf)
             (type ub8-vector vector)
             (type iobuf-index start end))
    (when (iobuf-empty-p iobuf)
      (iobuf-reset iobuf))
    (multiple-value-bind (iobuf-data data-start data-end)
        (iobuf-next-empty-zone iobuf)
      (declare (type iobuf-index data-start data-end))
      (let ((nbytes
             (etypecase vector
               (ub8-simple-vector
                (replace-ub8sv->ub8sv iobuf-data vector
                                      data-start data-end
                                      start end))
               (ub8-complex-vector
                (replace-ub8cv->ub8sv iobuf-data vector
                                      data-start data-end
                                      start end)))))
        (setf (iobuf-end iobuf) (+ data-start (the iobuf-index nbytes)))
        (values nbytes))))
  