]> asedeno.scripts.mit.edu Git - cl-protobufs.git/commitdiff
wire-format: Start using ENCODE-INT and DECODE-INT
authorAlejandro R Sedeño <asedeno@google.com>
Fri, 5 Apr 2013 05:04:26 +0000 (01:04 -0400)
committerAlejandro R Sedeño <asedeno@google.com>
Wed, 29 May 2013 18:26:19 +0000 (14:26 -0400)
tests/wire-tests.lisp
wire-format.lisp

index 8b2765a24d7d62d7be5336854d65242eb6145078..7ff9d02487ef342cf4c1f2cd396b47876acdcffc 100644 (file)
               (#x10000000 (#x80 #x80 #x80 #x80 #x01))
               (#xffffffff (#xff #xff #xff #xff #x0f))))
     (verify nil
-            #'decode-int32
+            #'decode-int
             '((#x0 (#x00))
               (#x1 (#x01))
               (#x7fffffff (#xff #xff #xff #xff #x07))
               (#x8000000000000000 (#x80 #x80 #x80 #x80 #x80 #x80 #x80 #x80 #x80 #x01))
               (#xffffffffffffffff (#xff #xff #xff #xff #xff #xff #xff #xff #xff #x01))))
     (verify nil
-            #'decode-int64
+            #'decode-int
             '((#x0 (#x00))
               (#x1 (#x01))
               (#x7fffffffffffffff (#xff #xff #xff #xff #xff #xff #xff #xff #xff #x00))
index 6c6170bbd6d3ff40d62437cbba2cd33476225ede..6debf206249d5e9df0016ba70e9e5992c8e7789d 100644 (file)
     (let ((idx (encode-uint32 tag buffer index)))
       (declare (type fixnum idx))
       (ecase type
-        ((:int32 :uint32)
-         (encode-uint32 (ldb (byte 32 0) val) buffer idx))
-        ((:int64 :uint64)
-         (encode-uint64 (ldb (byte 64 0) val) buffer idx))
+        ((:int32 :int64)
+         (encode-int val buffer idx))
+        ((:uint32)
+         (encode-uint32 val buffer idx))
+        ((:uint64)
+         (encode-uint64 val buffer idx))
         ((:sint32)
          (encode-uint32 (zig-zag-encode32 val) buffer idx))
         ((:sint64)
        (let ((idx (encode-uint32 ,tag ,buffer ,index)))
          (declare (type fixnum idx))
          ,(ecase type
-            ((:int32)
-             `(encode-uint32 (ldb (byte 32 0) ,val) ,buffer idx))
-            ((:int64)
-             `(encode-uint64 (ldb (byte 64 0) ,val) ,buffer idx))
+            ((:int32 :int64)
+             `(encode-int ,val ,buffer idx))
             ((:uint32)
              `(encode-uint32 ,val ,buffer idx))
             ((:uint64)
         (declare (type fixnum len) (ignore full-len))
         (setq idx (encode-uint32 len buffer idx)))
       (ecase type
-        ((:int32 :uint32)
-         (map () #'(lambda (val) (setq idx (encode-uint32 (ldb (byte 32 0) val) buffer idx))) values))
-        ((:int64 :uint64)
-         (map () #'(lambda (val) (setq idx (encode-uint64 (ldb (byte 64 0) val) buffer idx))) values))
+        ((:int32 :int64)
+         (map () #'(lambda (val) (setq idx (encode-int val buffer idx))) values))
+        ((:uint32)
+         (map () #'(lambda (val) (setq idx (encode-uint32 val buffer idx))) values))
+        ((:uint64)
+         (map () #'(lambda (val) (setq idx (encode-uint64 val buffer idx))) values))
         ((:sint32)
          (map () #'(lambda (val) (setq idx (encode-uint32 (zig-zag-encode32 val) buffer idx))) values))
         ((:sint64)
            (setq idx (encode-uint32 len ,buffer idx)))
          (,(if vectorp 'dovector 'dolist) (val ,values)
             ,(ecase type
-               ((:int32)
-                `(setq idx (encode-uint32 (ldb (byte 32 0) val) ,buffer idx)))
-               ((:int64)
-                `(setq idx (encode-uint64 (ldb (byte 64 0) val) ,buffer idx)))
+               ((:int32 :int64)
+                `(setq idx (encode-int val ,buffer idx)))
                ((:uint32)
                 `(setq idx (encode-uint32 val ,buffer idx)))
                ((:uint64)
            (type fixnum index))
   (locally (declare #.$optimize-serialization)
     (ecase type
-      ((:int32)
-       (decode-int32 buffer index))
-      ((:int64)
-       (decode-int64 buffer index))
+      ((:int32 :int64)
+       (decode-int buffer index))
       ((:uint32)
        (decode-uint32 buffer index))
       ((:uint64)
                        (type (simple-array (unsigned-byte 8)) ,buffer)
                        (type fixnum ,index))
        ,(ecase type
-          ((:int32)
-           `(decode-int32 ,buffer ,index))
-          ((:int64)
-           `(decode-int64 ,buffer ,index))
+          ((:int32 :int64)
+           `(decode-int ,buffer ,index))
           ((:uint32)
            `(decode-uint32 ,buffer ,index))
           ((:uint64)
               (return-from deserialize-packed (values values idx)))
             (multiple-value-bind (val nidx)
                 (ecase type
-                  ((:int32)
-                   (decode-int32 buffer idx))
-                  ((:int64)
-                   (decode-int64 buffer idx))
+                  ((:int32 :int64)
+                   (decode-int buffer idx))
                   ((:uint32)
                    (decode-uint32 buffer idx))
                   ((:uint64)
                    (return-from deserialize-packed (values values idx)))
                  (multiple-value-bind (val nidx)
                      ,(ecase type
-                        ((:int32)
-                         `(decode-int32 ,buffer idx))
-                        ((:int64)
-                         `(decode-int64 ,buffer idx))
+                        ((:int32 :int64)
+                         `(decode-int ,buffer idx))
                         ((:uint32)
                          `(decode-uint32 ,buffer idx))
                         ((:uint64)
            (type fixnum index))
   (locally (declare #.$optimize-serialization)
     (multiple-value-bind (val idx)
-        (decode-int32 buffer index)
+        (decode-int buffer index)
       (let ((val (let ((e (find val enum-values :key #'proto-index)))
                    (and e (proto-value e)))))
         (values val idx)))))
             (when (>= idx end)
               (return-from deserialize-packed-enum (values values idx)))
             (multiple-value-bind (val nidx)
-                (decode-int32 buffer idx)
+                (decode-int buffer idx)
               (let ((val (let ((e (find val enum-values :key #'proto-index)))
                            (and e (proto-value e)))))
                 (collect-value val)