From a52733eb07a124cdf5dd44f6666e52306ca82223 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 27 Apr 2016 14:22:44 -0700 Subject: [PATCH] Use protozero functions for zigzag encoding and decoding --- serial.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/serial.cpp b/serial.cpp index 0150baa..d0cb4b4 100644 --- a/serial.cpp +++ b/serial.cpp @@ -2,6 +2,7 @@ #include #include #include +#include "protozero/varint.hpp" #include "serial.hpp" size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream, const char *fname) { @@ -18,7 +19,7 @@ void serialize_int(FILE *out, int n, long long *fpos, const char *fname) { } void serialize_long_long(FILE *out, long long n, long long *fpos, const char *fname) { - unsigned long long zigzag = (n << 1) ^ (n >> 63); + unsigned long long zigzag = protozero::encode_zigzag32(n); while (1) { unsigned char b = zigzag & 0x7F; @@ -74,7 +75,7 @@ void deserialize_long_long(char **f, long long *n) { } } - *n = (zigzag >> 1) ^ (-(zigzag & 1)); + *n = protozero::decode_zigzag32(zigzag); } void deserialize_uint(char **f, unsigned *n) { @@ -108,7 +109,7 @@ int deserialize_long_long_io(FILE *f, long long *n, long long *geompos) { } } - *n = (zigzag >> 1) ^ (-(zigzag & 1)); + *n = protozero::decode_zigzag32(zigzag); return 1; }