From 9848f8445292ad3f7ff92bd4abfeb8f2d08ec32d Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 26 Apr 2016 11:44:32 +0100 Subject: Add some logging to help understand what's going on --- include/olm/memory.hh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'include/olm/memory.hh') diff --git a/include/olm/memory.hh b/include/olm/memory.hh index 128990a..89afd99 100644 --- a/include/olm/memory.hh +++ b/include/olm/memory.hh @@ -1,4 +1,4 @@ -/* Copyright 2015 OpenMarket Ltd +/* Copyright 2015, 2016 OpenMarket Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,9 @@ #include #include #include +#include +#include +#include #include namespace olm { @@ -84,4 +87,23 @@ std::uint8_t * store_array( return destination + sizeof(T); } +/** convert an array of bytes to a string representation */ +template +std::string bytes_to_string(T start, T end) { + std::ostringstream ss; + ss << std::hex << std::setfill('0'); + while (start != end) { + ss << std::setw(2) << static_cast(*start++); + if (start != end) { + ss << ":"; + } + } + return ss.str(); +} + +template +std::string bytes_to_string(T start, size_t len) { + return bytes_to_string(start, start+len); +} + } // namespace olm -- cgit v1.2.3