]> asedeno.scripts.mit.edu Git - cl-protobufs.git/blobdiff - serialize.lisp
fix cross-package and forward references in cl-protobufs
[cl-protobufs.git] / serialize.lisp
index e324cbf479ab51324c40fab8d9b2b04a520cf974..981b87e945a26ae3539888d65a0f2c10b5ea28dd 100644 (file)
                                           (tag  (make-tag type (proto-index field))))
                                      (doseq (v (read-slot object slot reader))
                                        (let ((v (funcall (proto-serializer msg) v)))
-                                         (setq index (serialize-prim v type tag buffer index))))))))
+                                         (setq index (serialize-prim v type tag buffer index))))))
+                                  (t
+                                   (error 'undefined-field-type
+                                          :format-control "While serializing ~s to protobuf,"
+                                          :format-arguments (list object)
+                                          :type-name (prin1-to-string type)
+                                          :field field))))
                            (t
                             (cond ((eq type :bool)
                                    ;; We have to handle optional boolean fields specially
                                        (let* ((v    (funcall (proto-serializer msg) v))
                                               (type (proto-proto-type msg))
                                               (tag  (make-tag type (proto-index field))))
-                                         (setq index (serialize-prim v type tag buffer index)))))))))))))
+                                         (setq index (serialize-prim v type tag buffer index))))))
+                                  (t
+                                   (error 'undefined-field-type
+                                          :format-control "While serializing ~s to protobuf,"
+                                          :format-arguments (list object)
+                                          :type-name (prin1-to-string type)
+                                          :field field)))))))))
         (declare (dynamic-extent #'do-field))
         (dolist (field (proto-fields message))
           (do-field object message field))))
                                           (tag  (make-tag type (proto-index field))))
                                      (doseq (v (read-slot object slot reader))
                                        (let ((v (funcall (proto-serializer msg) v)))
-                                         (iincf size (prim-size v type tag))))))))
+                                         (iincf size (prim-size v type tag))))))
+                                  (t
+                                   (error 'undefined-field-type
+                                          :format-control "While computing the size of ~s in bytes,"
+                                          :format-arguments (list object)
+                                          :type-name (prin1-to-string type)
+                                          :field field))))
                            (t
                             (cond ((eq type :bool)
                                    (let ((v (cond ((or (eq (proto-required field) :required)
                                        (let* ((v    (funcall (proto-serializer msg) v))
                                               (type (proto-proto-type msg))
                                               (tag  (make-tag type (proto-index field))))
-                                         (iincf size (prim-size v type tag)))))))))))))
+                                         (iincf size (prim-size v type tag))))))
+                                  (t
+                                   (error 'undefined-field-type
+                                          :format-control "While computing the size of ~s in bytes,"
+                                          :format-arguments (list object)
+                                          :type-name (prin1-to-string type)
+                                          :field field)))))))))
         (declare (dynamic-extent #'do-field))
         (dolist (field (proto-fields message))
           (do-field object message field))
                                     (tag   (make-tag class (proto-index field))))
                                `(,iterator (,vval ,reader)
                                   (let ((,vval (funcall #',(proto-serializer msg) ,vval)))
-                                    (setq ,vidx (serialize-prim ,vval ,class ,tag ,vbuf ,vidx))))))))))
+                                    (setq ,vidx (serialize-prim ,vval ,class ,tag ,vbuf ,vidx)))))))
+                           (t
+                            (error 'undefined-field-type
+                                   :format-control "While generating the serialize-object method ~
+                                                    for ~s,"
+                                   :format-arguments (list message)
+                                   :type-name (prin1-to-string class)
+                                   :field field)))))
                   (t
                    (cond ((keywordp class)
                           (collect-serializer
                              `(let ((,vval ,reader))
                                 (when ,vval
                                   (let ((,vval (funcall #',(proto-serializer msg) ,vval)))
-                                    (setq ,vidx (serialize-prim ,vval ,class ,tag ,vbuf ,vidx))))))))))))))
+                                    (setq ,vidx (serialize-prim ,vval ,class ,tag ,vbuf ,vidx))))))))
+                         (t
+                          (error 'undefined-field-type
+                                 :format-control "While generating the serialize-object method ~
+                                                  for ~s,"
+                                 :format-arguments (list message)
+                                 :type-name (prin1-to-string class)
+                                 :field field))))))))
       `(defmethod serialize-object
            (,vobj (,vclass (eql ,message)) ,vbuf &optional (,vidx 0) visited)
          (declare #.$optimize-serialization)
                                (multiple-value-bind (,vval idx)
                                    (deserialize-prim ,class ,vbuf ,vidx)
                                  (setq ,vidx idx)
-                                 (push (funcall #',(proto-deserializer msg) ,vval) ,temp))))))))
+                                 (push (funcall #',(proto-deserializer msg) ,vval) ,temp))))))
+                         (t
+                          (error 'undefined-field-type
+                                 :format-control "While generating the deserialize-object method ~
+                                                  for ~s,"
+                                 :format-arguments (list message)
+                                 :type-name (prin1-to-string class)
+                                 :field field))))
                   (t
                    (cond ((keywordp class)
                           (collect-deserializer
                                      (deserialize-prim ,class ,vbuf ,vidx)
                                    (let ((,vval (funcall #',(proto-deserializer msg) ,vval)))
                                      (setq ,vidx idx)
-                                     ,(write-slot vobj field vval)))))))))))))
+                                     ,(write-slot vobj field vval)))))))
+                         (t
+                          (error 'undefined-field-type
+                                 :format-control "While generating the deserialize-object method ~
+                                                  for ~s,"
+                                 :format-arguments (list message)
+                                 :type-name (prin1-to-string class)
+                                 :field field))))))))
       (let* ((rslots  (delete-duplicates rslots :key #'first))
              (rfields (mapcar #'first  rslots))
              (rtemps  (mapcar #'second rslots)))
                                     (tag   (make-tag class index)))
                                `(,iterator (,vval ,reader)
                                   (let ((,vval (funcall #',(proto-serializer msg) ,vval)))
-                                    (iincf ,vsize (prim-size ,vval ,class ,tag))))))))))
+                                    (iincf ,vsize (prim-size ,vval ,class ,tag)))))))
+                           (t
+                            (error 'undefined-field-type
+                                   :format-control "While generating the object-size method for ~s,"
+                                   :format-arguments (list message)
+                                   :type-name (prin1-to-string class)
+                                   :field field)))))
                   (t
                    (cond ((keywordp class)
                           (let ((tag (make-tag class index)))
                                 (when ,vval
                                   (iincf ,vsize (prim-size
                                                  (funcall #',(proto-serializer msg) ,vval)
-                                                 ,class ,tag)))))))))))))
+                                                 ,class ,tag)))))))
+                         (t
+                          (error 'undefined-field-type
+                                 :format-control "While generating the object-size method for ~s,"
+                                 :format-arguments (list message)
+                                 :type-name (prin1-to-string class)
+                                 :field field))))))))
       `(defmethod object-size
            (,vobj (,vclass (eql ,message)) &optional visited)
          (declare #.$optimize-serialization)