]> asedeno.scripts.mit.edu Git - cl-protobufs.git/blobdiff - api.lisp
define-proto: refactor DEFINE-EXTEND
[cl-protobufs.git] / api.lisp
index 1dde4e21458ae4b859c7ea31c1e48a97e296c514..e2743be1ae19e28b9472263f3d69b1e245dd7997 100644 (file)
--- a/api.lisp
+++ b/api.lisp
@@ -2,7 +2,7 @@
 ;;;                                                                  ;;;
 ;;; Free Software published under an MIT-like license. See LICENSE   ;;;
 ;;;                                                                  ;;;
-;;; Copyright (c) 2012 Google, Inc.  All rights reserved.            ;;;
+;;; Copyright (c) 2012-2013 Google, Inc.  All rights reserved.       ;;;
 ;;;                                                                  ;;;
 ;;; Original author: Scott McKay                                     ;;;
 ;;;                                                                  ;;;
            (type    (and message (proto-class message))))
       (assert message ()
               "There is no Protobufs message for the class ~S" class)
-      (let ((visited (make-hash-table)))
+      (let ((visited (make-size-cache object type)))
         (object-size object type visited)))))
 
 ;; This is simpler than 'serialize-object', but doesn't fully support aliasing
   (:documentation
    "Serialize 'object' into 'buffer' using the wire format, starting at the index
    'start' and going no farther than 'end'. 'object' is an object whose Lisp class
-   corresponds to a Protobufs message.")
+   corresponds to a Protobufs message.
+   Returns two values, the final index and the buffer.")
   (:method ((object standard-object) &optional buffer (start 0) end)
     (declare (ignore end))
     (let* ((class   (type-of object))
            (type    (and message (proto-class message))))
       (assert message ()
               "There is no Protobufs message for the class ~S" class)
-      (let* ((visited (make-hash-table))
+      (let* ((visited (make-size-cache object type))
              (size    (object-size object type visited))
              (start   (or start 0))
              (buffer  (or buffer (make-byte-vector size))))
         (multiple-value-bind (nbuf nend)
             (serialize-object object type buffer start visited)
         (declare (ignore nbuf))
-        nend)))))
+        (values nend buffer))))))
 
 (defgeneric merge-from-array (object buffer &optional start end)
   (:documentation