]> asedeno.scripts.mit.edu Git - cl-protobufs.git/blobdiff - text-format.lisp
Merge branch 'rework-schema-import-and-lookup'
[cl-protobufs.git] / text-format.lisp
index 183b1a88d71adcefd7d3d3f182b33d9f4051c3c5..3b4bb5c1332c6dc974298cb0f9f8202824b512cd 100644 (file)
                    (when (or slot reader)
                      (cond ((eq (proto-required field) :repeated)
                             (cond ((keywordp type)
-                                   (map () #'(lambda (v)
-                                               (print-prim v type field stream
-                                                           (or suppress-line-breaks indent)))
-                                           (read-slot object slot reader)))
+                                   (doseq (v (read-slot object slot reader))
+                                     (print-prim v type field stream
+                                                 (or suppress-line-breaks indent))))
                                   ((typep (setq msg (and type (or (find-message trace type)
                                                                   (find-enum trace type)
                                                                   (find-type-alias trace type))))
                                            (if suppress-line-breaks
                                              (format stream "~A { " (proto-name field))
                                              (format stream "~&~VT~A {~%" indent (proto-name field)))
-                                           (map () (curry #'do-field v msg indent)
-                                                   (proto-fields msg))
+                                           (dolist (f (proto-fields msg))
+                                            (do-field v msg indent f))
                                            (if suppress-line-breaks
                                              (format stream "} ")
                                              (format stream "~&~VT}~%" indent)))))))
                                   ((typep msg 'protobuf-enum)
-                                   (map () #'(lambda (v)
-                                               (print-enum v msg field stream
-                                                           (or suppress-line-breaks indent)))
-                                           (read-slot object slot reader)))
+                                   (doseq (v (read-slot object slot reader))
+                                     (print-enum v msg field stream
+                                                 (or suppress-line-breaks indent))))
                                   ((typep msg 'protobuf-type-alias)
                                    (let ((type (proto-proto-type msg)))
-                                     (map () #'(lambda (v)
-                                                 (let ((v (funcall (proto-serializer msg) v)))
-                                                   (print-prim v type field stream
-                                                               (or suppress-line-breaks indent))))
-                                             (read-slot object slot reader))))))
+                                     (doseq (v (read-slot object slot reader))
+                                       (let ((v (funcall (proto-serializer msg) v)))
+                                         (print-prim v type field stream
+                                                     (or suppress-line-breaks indent))))))
+                                  (t
+                                   (undefined-field-type "While printing ~S to text format,"
+                                                         object type field))))
                            (t
                             (cond ((eq type :bool)
                                    (let ((v (cond ((or (eq (proto-required field) :required)
@@ -91,7 +91,7 @@
                                                    (or suppress-line-breaks indent)))))
                                   ((keywordp type)
                                    (let ((v (read-slot object slot reader)))
-                                     (when v
+                                     (when (and v (not (equal v (proto-default field))))
                                        (print-prim v type field stream
                                                    (or suppress-line-breaks indent)))))
                                   ((typep (setq msg (and type (or (find-message trace type)
                                          (if suppress-line-breaks
                                              (format stream "~A { " (proto-name field))
                                              (format stream "~&~VT~A {~%" indent (proto-name field)))
-                                         (map () (curry #'do-field v msg indent)
-                                                 (proto-fields msg))
+                                         (dolist (f (proto-fields msg))
+                                           (do-field v msg indent f))
                                          (if suppress-line-breaks
                                              (format stream "} ")
                                              (format stream "~&~VT}~%" indent))))))
                                   ((typep msg 'protobuf-enum)
                                    (let ((v (read-slot object slot reader)))
-                                     (when v
+                                     (when (and v (not (eql v (proto-default field))))
                                        (print-enum v msg field stream
                                                    (or suppress-line-breaks indent)))))
                                   ((typep msg 'protobuf-type-alias)
                                        (let ((v    (funcall (proto-serializer msg) v))
                                              (type (proto-proto-type msg)))
                                          (print-prim v type field stream
-                                                     (or suppress-line-breaks indent)))))))))))))
+                                                     (or suppress-line-breaks indent))))))
+                                  (t
+                                   (undefined-field-type "While printing ~S to text format,"
+                                                         object type field)))))))))
         (declare (dynamic-extent #'do-field))
         (if print-name
           (if suppress-line-breaks
             (format stream "~A { " (proto-name message))
             (format stream "~&~A {~%" (proto-name message)))
           (format stream "{"))
-        (map () (curry #'do-field object message 0) (proto-fields message))
+        (dolist (f (proto-fields message))
+          (do-field object message 0 f))
         (if suppress-line-breaks
           (format stream "}")
           (format stream "~&}~%"))
                                        (when slot
                                          (pushnew slot rslots)
                                          (push (funcall (proto-deserializer msg) val)
-                                               (slot-value object slot))))))))
+                                               (slot-value object slot))))))
+                                  (t
+                                   (undefined-field-type "While parsing ~S from text format,"
+                                                         message type field))))
                            (t
                             (cond ((keywordp type)
                                    (expect-char stream #\:)
                                                   (otherwise (parse-signed-int stream)))))
                                        (when slot
                                          (setf (slot-value object slot)
-                                               (funcall (proto-deserializer msg) val)))))))))))))))
+                                               (funcall (proto-deserializer msg) val))))))
+                                  (t
+                                   (undefined-field-type "While parsing ~S from text format,"
+                                                         message type field)))))))))))
     (declare (dynamic-extent #'deserialize))
     (deserialize (proto-class message) message)))