diff options
author | Per Åstrand <per.astrand@arm.com> | 2020-09-28 13:02:18 +0200 |
---|---|---|
committer | Per Åstrand <per.astrand@arm.com> | 2020-10-06 09:49:02 +0200 |
commit | dc28b13e8bf4e5e7a788f289739e6301494c43a1 (patch) | |
tree | e851afe5c12d79e8b36a718ceaa09fcff19b07aa /applications/message_process/include/message_process.hpp | |
parent | bbd9c8fcfdda36fa69a6b65f95efdb242cbff30a (diff) | |
download | ethos-u-core-software-dc28b13e8bf4e5e7a788f289739e6301494c43a1.tar.gz |
Refactor code to avoid typepunning tricks
Change-Id: Iecefa233561ddbef3e04f395f12fb56cd76ffd42
Diffstat (limited to 'applications/message_process/include/message_process.hpp')
-rw-r--r-- | applications/message_process/include/message_process.hpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/applications/message_process/include/message_process.hpp b/applications/message_process/include/message_process.hpp index 51f474d..e820b60 100644 --- a/applications/message_process/include/message_process.hpp +++ b/applications/message_process/include/message_process.hpp @@ -55,6 +55,7 @@ public: bool read(uint8_t *dst, uint32_t length); bool write(const Vec *vec, size_t length); bool write(const uint32_t type, const void *src = nullptr, uint32_t length = 0); + bool skip(uint32_t length); template <typename T> bool read(T &dst) { @@ -62,6 +63,15 @@ public: } template <typename T> + bool readOrSkip(T &dst, uint32_t expectedLength) { + if (expectedLength == sizeof(dst)) { + return read(reinterpret_cast<uint8_t *>(&dst), sizeof(dst)); + } else { + return skip(expectedLength); + } + } + + template <typename T> bool write(const uint32_t type, const T &src) { return write(type, reinterpret_cast<const void *>(&src), sizeof(src)); } |