From: Alejandro R SedeƱo Date: Fri, 5 Apr 2013 05:04:26 +0000 (-0400) Subject: wire-format: Start using ENCODE-INT and DECODE-INT X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=8a63a8f101072dcf8af89fa68b5b89286550dff0;p=cl-protobufs.git wire-format: Start using ENCODE-INT and DECODE-INT --- diff --git a/tests/wire-tests.lisp b/tests/wire-tests.lisp index 8b2765a..7ff9d02 100644 --- a/tests/wire-tests.lisp +++ b/tests/wire-tests.lisp @@ -104,7 +104,7 @@ (#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)) @@ -164,7 +164,7 @@ (#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)) diff --git a/wire-format.lisp b/wire-format.lisp index 6c6170b..6debf20 100644 --- a/wire-format.lisp +++ b/wire-format.lisp @@ -137,10 +137,12 @@ (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) @@ -186,10 +188,8 @@ (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) @@ -235,10 +235,12 @@ (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) @@ -280,10 +282,8 @@ (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) @@ -362,10 +362,8 @@ (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) @@ -416,10 +414,8 @@ (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) @@ -474,10 +470,8 @@ (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) @@ -530,10 +524,8 @@ (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) @@ -576,7 +568,7 @@ (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))))) @@ -601,7 +593,7 @@ (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)