aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--project.conf2
-rw-r--r--sibs/SafeDeserializer.hpp7
-rw-r--r--sibs/SafeSerializer.hpp5
-rw-r--r--tests/main.cpp4
5 files changed, 19 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index be24e9c..b45f630 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
sibs-build/
.vscode/
*.kdev4
+compile_commands.json
+tests/sibs-build/
+tests/compile_commands.json
diff --git a/project.conf b/project.conf
index c143277..7649ac7 100644
--- a/project.conf
+++ b/project.conf
@@ -1,6 +1,6 @@
[package]
name = "sibs-serializer"
-version = "1.0.2"
+version = "1.0.3"
type = "static"
platforms = ["any"]
tests = "tests"
diff --git a/sibs/SafeDeserializer.hpp b/sibs/SafeDeserializer.hpp
index 0110920..763140a 100644
--- a/sibs/SafeDeserializer.hpp
+++ b/sibs/SafeDeserializer.hpp
@@ -97,6 +97,13 @@ namespace sibs
{
return size;
}
+
+ void skip(usize bytesToSkip)
+ {
+ bytesToSkip = bytesToSkip < size ? bytesToSkip : size;
+ size -= bytesToSkip;
+ data += bytesToSkip;
+ }
private:
void verifyExtractSize(usize typeSize) const
{
diff --git a/sibs/SafeSerializer.hpp b/sibs/SafeSerializer.hpp
index efc4ecd..fe8ee58 100644
--- a/sibs/SafeSerializer.hpp
+++ b/sibs/SafeSerializer.hpp
@@ -64,6 +64,11 @@ namespace sibs
memcpy(&buffer[offset], data, size);
}
}
+
+ void add(const char *data, usize size)
+ {
+ add((const u8*)data, size);
+ }
std::vector<u8>& getBuffer()
{
diff --git a/tests/main.cpp b/tests/main.cpp
index 7cb9c1d..0521e50 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -21,6 +21,7 @@ void testDeserialize(sibs::SafeSerializer &serializer)
REQUIRE(deserializer.extract<uint32_t>() == 3563634);
REQUIRE(deserializer.extract<uint64_t>() == 204232532533423632);
REQUIRE(deserializer.extract<uint8_t>() == 2);
+ deserializer.skip(4);
char str[6];
str[5] = '\0';
deserializer.extract((uint8_t*)str, 5);
@@ -58,9 +59,10 @@ int main()
serializer.add((uint32_t)3563634);
serializer.add((uint64_t)204232532533423632);
serializer.add((uint8_t)2);
+ serializer.add("skip", 4);
serializer.add((uint8_t*)"hello", 5);
serializer.add(expectedTestStruct);
- REQUIRE(serializer.getBuffer().size() == 18 + sizeof(expectedTestStruct));
+ REQUIRE(serializer.getBuffer().size() == 22 + sizeof(expectedTestStruct));
testDeserialize(serializer);
sibs::SafeSerializer movedSerializer(std::move(serializer));