;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ;;;
-;;; Confidential and proprietary information of ITA Software, Inc. ;;;
+;;; Free Software published under an MIT-like license. See LICENSE ;;;
;;; ;;;
-;;; Copyright (c) 2012 ITA Software, Inc. All rights reserved. ;;;
+;;; Copyright (c) 2012 Google, Inc. All rights reserved. ;;;
;;; ;;;
;;; Original author: Scott McKay ;;;
;;; ;;;
(defmethod reinitialize-object (object (message protobuf-message))
(dolist (field (proto-fields message))
- (reinitialize-field object field message))
+ (reinitialize-field object message field))
object)
-(defmethod reinitialize-field (object field (message protobuf-message))
- (macrolet ((write-slot (object slot writer value)
- `(if ,writer
- (funcall ,writer ,object ,value)
- (setf (slot-value ,object ,slot) ,value))))
- (let ((default (proto-default field))
- (slot (proto-value field))
- (writer (proto-writer field)))
- (cond ((null slot)
- (unless (empty-default-p field)
- (write-slot object slot writer default)))
- (t
- (if (empty-default-p field)
- (slot-makunbound object slot)
- (write-slot object slot writer default)))))))
-
-(defmethod reinitialize-slot (object slot (message protobuf-message))
- (let ((field (find slot (proto-fields message) :key #'proto-value)))
- (reinitialize-field object field message)))
+(defgeneric reinitialize-field (object message field)
+ (:method (object (message protobuf-message) field)
+ (macrolet ((write-slot (object slot writer value)
+ `(if ,writer
+ (funcall ,writer ,object ,value)
+ (setf (slot-value ,object ,slot) ,value))))
+ (let ((default (proto-default field))
+ (slot (proto-value field))
+ (writer (proto-writer field)))
+ (cond ((null slot)
+ (unless (empty-default-p field)
+ (write-slot object slot writer default)))
+ (t
+ (if (empty-default-p field)
+ (slot-makunbound object slot)
+ (write-slot object slot writer default))))))))
+
+(defgeneric reinitialize-slot (object message slot)
+ (:method (object (message protobuf-message) slot)
+ (let ((field (find slot (proto-fields message) :key #'proto-value)))
+ (reinitialize-field object message field))))
\f
;;; A Python-like, Protobufs2-compatible API
(: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))
(buffer (or buffer (make-byte-vector size))))
(assert (>= (length buffer) size) ()
"The buffer ~S is not large enough to hold ~S" buffer object)
- (serialize-object object type buffer start visited)
- buffer))))
+ (multiple-value-bind (nbuf nend)
+ (serialize-object object type buffer start visited)
+ (declare (ignore nbuf))
+ (values nend buffer))))))
(defgeneric merge-from-array (object buffer &optional start end)
(:documentation
"There is no Protobufs message for the class ~S" class)
(assert (eq class (type-of source)) ()
"The objects ~S and ~S are of not of the same class" object source)
- ;;--- Do this
+ ;;--- Do this (should return side-effected 'object', not 'source')
type
- object)))
+ source)))