Documentation
Serializes the object to a buffer, allocates a heap block of the right
size and writes the buffer to the block. Returns the (heap position of the)
block containing the object.
Source
(defmethod save-object (object object-id (cache standard-cache)
transaction-id previous-block
&key schema)
"Serializes the object to a buffer, allocates a heap block of the right
size and writes the buffer to the block. Returns the (heap position of the)
block containing the object."
(unless schema
(setq schema
(find-or-create-schema-for-object (schema-table cache) object)))
(let* ((heap (heap cache))
(schema-id (schema-id schema))
(nr-slots (nr-persistent-slots schema))
(buffer (serialization-buffer heap)))
(reset-buffer buffer)
;; Serialize standard fields.
(serialize-previous-version-pointer previous-block buffer)
(serialize transaction-id buffer)
(serialize object-id buffer)
(serialize nr-slots buffer)
(serialize schema-id buffer)
;; Serialize slot values.
;; (Bind *dont-dereference-proxies* to T to make sure that
;; the slot-value-using-class method doesn't intercept here.)
(let ((*dont-dereference-proxies* t))
(loop for slot-name in (persistent-slot-names schema)
do (if (slot-boundp object slot-name)
(serialize (slot-value object slot-name) buffer)
(serialize-marker +unbound-slot+ buffer))))
;; Allocate a heap block of the right size.
(let* ((size (+ (buffer-count buffer)
(block-header-size heap)))
(block (allocate-block heap :size size)))
;; Save the serialized buffer in the block.
(save-buffer buffer (heap-stream heap)
:file-position (+ block (block-header-size heap)))
(handle-written-object object-id block heap)
;; Return the block.
block)))
Source Context