diff options
author | Luca Barbieri <luca@luca-barbieri.com> | 2010-06-07 20:38:55 +0200 |
---|---|---|
committer | Robert Vollmert <rvollmert@gmx.net> | 2010-07-28 19:21:46 +0200 |
commit | 758743c3294c2a441de87c3c1aafd005ff76824f (patch) | |
tree | 4bbbc3271383bfb5186bfdb6dfc538ff5f83f451 /crawl-ref/source/tags.h | |
parent | f96f175a23bd889e06c85b76a50f549cc2ce4968 (diff) | |
download | crawl-ref-758743c3294c2a441de87c3c1aafd005ff76824f.tar.gz crawl-ref-758743c3294c2a441de87c3c1aafd005ff76824f.zip |
Add support for (un)marshalling variable-sized integers
The current serialization code only supports 8/16/32-bit fixed size
integers.
However, a variable sized representation is often more space efficient,
and allows to seamlessly expand the integer size without breaking
compatibility.
This patch uses the common scheme of using 7 bits for data, plus 1 bit
to indicate termination of the integer, all encoded in little endian order.
Signed integers are first transformed to unsigned ones where bit 0 is
the sign bit.
Diffstat (limited to 'crawl-ref/source/tags.h')
-rw-r--r-- | crawl-ref/source/tags.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/crawl-ref/source/tags.h b/crawl-ref/source/tags.h index 88f71096f6..acd36801da 100644 --- a/crawl-ref/source/tags.h +++ b/crawl-ref/source/tags.h @@ -145,6 +145,9 @@ inline void marshallEnum(writer& wr, enm value) marshallEnumVal(wr, &enum_details<enm>::desc, static_cast<int>(value)); } +void marshallUnsigned(writer& th, uint64_t v); +void marshallSigned(writer& th, int64_t v); + /* *********************************************************************** * reader API * *********************************************************************** */ @@ -199,6 +202,20 @@ inline enm unmarshallEnum(writer& wr) return static_cast<enm>(unmarshallEnumVal(wr, &enum_details<enm>::desc)); } +uint64_t unmarshallUnsigned(reader& th); +template<typename T> +static inline void unmarshallUnsigned(reader& th, T& v) +{ + v = (T)unmarshallUnsigned(th); +} + +int64_t unmarshallSigned(reader& th); +template<typename T> +static inline void unmarshallSigned(reader& th, T& v) +{ + v = (T)unmarshallSigned(th); +} + /* *********************************************************************** * Tag interface * *********************************************************************** */ |