X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Fpickle.hpp;h=84b643a93ab7301c2e4fdbaa5520fa7bb8e176d9;hb=e7102bf755210f9e215fb048b637dda6bab96334;hp=f333960a7adefb31a57d48165c2da5ac753bdb6e;hpb=447576da195e098d54c8e1279f7bb3ff1b5f2d49;p=apitrace diff --git a/common/pickle.hpp b/common/pickle.hpp index f333960..84b643a 100644 --- a/common/pickle.hpp +++ b/common/pickle.hpp @@ -36,6 +36,7 @@ #include #include +#include class PickleWriter @@ -106,13 +107,15 @@ private: public: PickleWriter(std::ostream &_os) : - os(_os) - { + os(_os) { + } + + inline void begin() { os.put(PROTO); os.put(2); } - ~PickleWriter() { + inline void end() { os.put(STOP); } @@ -266,6 +269,16 @@ public: os.put(u.c[0]); } + inline void writeByteArray(const void *buf, size_t length) { + os.put(GLOBAL); + os << "__builtin__\nbytearray\n"; + os.put(BINPUT); + os.put(1); + writeString(static_cast(buf), length); + os.put(TUPLE1); + os.put(REDUCE); + } + protected: inline void putInt16(uint16_t i) { os.put( i & 0xff); @@ -288,12 +301,20 @@ protected: return; } - unsigned c = 1; // Same as l >> (8 * sizeof l), but without the warnings - T sign = l < 0 ? ~0 : 0; - while ((l >> (8 * c)) != sign) { - ++c; + T sign; + if (std::numeric_limits::is_signed) { + sign = l < 0 ? ~0 : 0; + } else { + sign = 0; } + + T sl = l; + unsigned c = 0; + do { + ++c; + } while (sl >>= 8 != sign); + // Add an extra byte if sign bit doesn't match if (((l >> (8 * c - 1)) & 1) != ((l >> (8 * sizeof l - 1)) & 1)) { ++c;