diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-16 07:06:42 +0200 |
---|---|---|
committer | dec05eba <0xdec05eba@gmail.com> | 2018-05-16 07:06:53 +0200 |
commit | c7c1312db2ef886326c09005d19ac19b79b84f23 (patch) | |
tree | 71f4b9723c34a2b63f9db8756ff6ed80893aac9b | |
parent | 8315157349bc1a98613bcc9c6e3a6bec532b4691 (diff) |
Add move constructor to serializer1.0.1
-rw-r--r-- | project.conf | 2 | ||||
-rw-r--r-- | sibs/SafeSerializer.hpp | 4 | ||||
-rw-r--r-- | tests/main.cpp | 53 |
3 files changed, 36 insertions, 23 deletions
diff --git a/project.conf b/project.conf index 0fd1d74..6f9e677 100644 --- a/project.conf +++ b/project.conf @@ -1,6 +1,6 @@ [package] name = "sibs-serializer" -version = "1.0.0" +version = "1.0.1" type = "static" platforms = ["any"] tests = "tests" diff --git a/sibs/SafeSerializer.hpp b/sibs/SafeSerializer.hpp index 379b7c8..9576053 100644 --- a/sibs/SafeSerializer.hpp +++ b/sibs/SafeSerializer.hpp @@ -16,6 +16,10 @@ namespace sibs DISABLE_COPY(SafeSerializer); public: SafeSerializer(){} + SafeSerializer(SafeSerializer &&other) + { + buffer = std::move(other.buffer); + } template <typename T> void add(const T &data) diff --git a/tests/main.cpp b/tests/main.cpp index e879e6a..7cb9c1d 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -13,29 +13,10 @@ struct TestStruct uint8_t b; }; -int main() -{ -#if BYTE_ORDER == BIG_ENDIAN - const char *endianessStr = "big"; -#elif BYTE_ORDER == LITTLE_ENDIAN - const char *endianessStr = "little"; -#else - const char *endianessStr = "Unknown"; -#endif - printf("System endianess: %s\n", endianessStr); - - TestStruct expectedTestStruct; - expectedTestStruct.a = 0x38956326; - expectedTestStruct.b = 0x34; - - sibs::SafeSerializer serializer; - serializer.add((uint32_t)3563634); - serializer.add((uint64_t)204232532533423632); - serializer.add((uint8_t)2); - serializer.add((uint8_t*)"hello", 5); - serializer.add(expectedTestStruct); - REQUIRE(serializer.getBuffer().size() == 18 + sizeof(expectedTestStruct)); +static TestStruct expectedTestStruct; +void testDeserialize(sibs::SafeSerializer &serializer) +{ sibs::SafeDeserializer deserializer(serializer.getBuffer().data(), serializer.getBuffer().size()); REQUIRE(deserializer.extract<uint32_t>() == 3563634); REQUIRE(deserializer.extract<uint64_t>() == 204232532533423632); @@ -57,6 +38,34 @@ int main() { } +} + +int main() +{ +#if BYTE_ORDER == BIG_ENDIAN + const char *endianessStr = "big"; +#elif BYTE_ORDER == LITTLE_ENDIAN + const char *endianessStr = "little"; +#else + const char *endianessStr = "Unknown"; +#endif + printf("System endianess: %s\n", endianessStr); + + expectedTestStruct.a = 0x38956326; + expectedTestStruct.b = 0x34; + + sibs::SafeSerializer serializer; + serializer.add((uint32_t)3563634); + serializer.add((uint64_t)204232532533423632); + serializer.add((uint8_t)2); + serializer.add((uint8_t*)"hello", 5); + serializer.add(expectedTestStruct); + REQUIRE(serializer.getBuffer().size() == 18 + sizeof(expectedTestStruct)); + + testDeserialize(serializer); + sibs::SafeSerializer movedSerializer(std::move(serializer)); + REQUIRE(serializer.getBuffer().empty()); + testDeserialize(movedSerializer); return 0; } |