From 363bd5fdfe0ee4d6d9c4b4f08ed4f09aa74dd8f3 Mon Sep 17 00:00:00 2001 From: lucka-me Date: Fri, 24 Sep 2021 11:39:17 +0800 Subject: [PATCH] Support read and write vector with EmptyDeployment - Fixes GENIVI/capicxx-someip-tools#10 - Fixes GENIVI/capicxx-someip-tools#21 --- include/CommonAPI/SomeIP/InputStream.hpp | 59 +++++++++++++++++++++++ include/CommonAPI/SomeIP/OutputStream.hpp | 45 +++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/include/CommonAPI/SomeIP/InputStream.hpp b/include/CommonAPI/SomeIP/InputStream.hpp index 90bda22..94d0749 100644 --- a/include/CommonAPI/SomeIP/InputStream.hpp +++ b/include/CommonAPI/SomeIP/InputStream.hpp @@ -321,6 +321,29 @@ class InputStream: public CommonAPI::InputStream { return (*this); } + template::value || + std::is_same::value), int>::type = 0> + COMMONAPI_EXPORT InputStream &readValue(std::vector &_value, + const EmptyDeployment *_depl) { + bitAlign(); + + (void)_depl; + + uint32_t itsSize; + + _value.clear(); + + errorOccurred_ = _readBitValue(itsSize, 32, false); + + if (!hasError()) { + ElementType_ *base = reinterpret_cast(_readRaw(itsSize)); + _value.assign(base, base + itsSize); + } + + return (*this); + } + template::value && !std::is_same::value), int>::type = 0> @@ -381,6 +404,42 @@ class InputStream: public CommonAPI::InputStream { return (*this); } + template::value && + !std::is_same::value), int>::type = 0> + COMMONAPI_EXPORT InputStream &readValue(std::vector &_value, + const EmptyDeployment *_depl) { + bitAlign(); + + (void)_depl; + + uint32_t itsSize; + + _value.clear(); + + errorOccurred_ = _readBitValue(itsSize, 32, false); + + while (itsSize > 0) + { + size_t remainingBeforeRead = remaining_; + ElementType_ itsElement; + readValue(itsElement, static_cast(nullptr)); + if (hasError()) { + break; + } + + _value.push_back(std::move(itsElement)); + + itsSize -= uint32_t(remainingBeforeRead - remaining_); + } + + if (itsSize != 0) { + errorOccurred_ = true; + } + + return (*this); + } + template COMMONAPI_EXPORT InputStream &readValue(std::unordered_map &_value, diff --git a/include/CommonAPI/SomeIP/OutputStream.hpp b/include/CommonAPI/SomeIP/OutputStream.hpp index 35dd553..4f38166 100644 --- a/include/CommonAPI/SomeIP/OutputStream.hpp +++ b/include/CommonAPI/SomeIP/OutputStream.hpp @@ -306,6 +306,23 @@ class OutputStream: public CommonAPI::OutputStream { return (*this); } + template::value || + std::is_same::value), int>::type = 0> + COMMONAPI_EXPORT OutputStream &writeValue(const std::vector &_value, + const EmptyDeployment *_depl) { + bitAlign(); + + (void)_depl; + + _writeValue(uint32_t(_value.size()), 4); + if (!hasError() && _value.size()) { + _writeRaw(reinterpret_cast(&_value[0]), _value.size()); + } + + return (*this); + } + template::value && !std::is_same::value), int>::type = 0> @@ -355,6 +372,34 @@ class OutputStream: public CommonAPI::OutputStream { return (*this); } + template::value && + !std::is_same::value), int>::type = 0> + COMMONAPI_EXPORT OutputStream &writeValue(const std::vector &_value, + const EmptyDeployment *_depl) { + bitAlign(); + + (void)_depl; + + pushPosition(); + // Length field placeholder + _writeValue(static_cast(0), 4); + pushPosition(); // Start of vector data + + for (auto i : _value) { + writeValue(i, static_cast(nullptr)); + if (hasError()) { + break; + } + } + + // Write number of written bytes to placeholder position + uint32_t length = uint32_t(getPosition() - popPosition()); + _writeValueAt(length, popPosition()); + + return (*this); + } + template COMMONAPI_EXPORT OutputStream &writeValue(const std::unordered_map &_value, const Deployment_ *_depl) {