aboutsummaryrefslogtreecommitdiff
path: root/src/pickle.cpp
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2016-04-26 18:10:13 +0100
committerRichard van der Hoff <richard@matrix.org>2016-04-26 18:10:13 +0100
commit11dbf2aab3e9a65148a40ac6b5b1124929344c1a (patch)
tree6550798794f5df40bcd86cd151efcc2027b0cca3 /src/pickle.cpp
parent9b010290a49243e5867dd9d4c93784a345fb2637 (diff)
Fix a bunch of compiler warnings, and turn on warnings.
Diffstat (limited to 'src/pickle.cpp')
-rw-r--r--src/pickle.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/pickle.cpp b/src/pickle.cpp
index 25580d2..00f7cd4 100644
--- a/src/pickle.cpp
+++ b/src/pickle.cpp
@@ -14,6 +14,60 @@
*/
#include "olm/pickle.hh"
+std::uint8_t * olm::pickle(
+ std::uint8_t * pos,
+ std::uint32_t value
+) {
+ pos += 4;
+ for (unsigned i = 4; i--;) { *(--pos) = value; value >>= 8; }
+ return pos + 4;
+}
+
+
+std::uint8_t const * olm::unpickle(
+ std::uint8_t const * pos, std::uint8_t const * end,
+ std::uint32_t & value
+) {
+ value = 0;
+ if (end < pos + 4) return end;
+ for (unsigned i = 4; i--;) { value <<= 8; value |= *(pos++); }
+ return pos;
+}
+
+std::uint8_t * olm::pickle(
+ std::uint8_t * pos,
+ bool value
+) {
+ *(pos++) = value ? 1 : 0;
+ return pos;
+}
+
+std::uint8_t const * olm::unpickle(
+ std::uint8_t const * pos, std::uint8_t const * end,
+ bool & value
+) {
+ if (pos == end) return end;
+ value = *(pos++);
+ return pos;
+}
+
+std::uint8_t * olm::pickle_bytes(
+ std::uint8_t * pos,
+ std::uint8_t const * bytes, std::size_t bytes_length
+) {
+ std::memcpy(pos, bytes, bytes_length);
+ return pos + bytes_length;
+}
+
+std::uint8_t const * olm::unpickle_bytes(
+ std::uint8_t const * pos, std::uint8_t const * end,
+ std::uint8_t * bytes, std::size_t bytes_length
+) {
+ if (end < pos + bytes_length) return end;
+ std::memcpy(bytes, pos, bytes_length);
+ return pos + bytes_length;
+}
+
std::size_t olm::pickle_length(
const olm::Curve25519PublicKey & value