Loading include/utils/Flattenable.h +9 −2 Original line number Diff line number Diff line Loading @@ -19,10 +19,13 @@ #include <stdint.h> #include <string.h> #include <sys/types.h> #include <utils/Errors.h> #include <utils/Debug.h> #include <type_traits> namespace android { Loading Loading @@ -60,14 +63,18 @@ public: // write a POD structure template<typename T> static void write(void*& buffer, size_t& size, const T& value) { *static_cast<T*>(buffer) = value; static_assert(std::is_trivially_copyable<T>::value, "Cannot flatten a non-trivially-copyable type"); memcpy(buffer, &value, sizeof(T)); advance(buffer, size, sizeof(T)); } // read a POD structure template<typename T> static void read(void const*& buffer, size_t& size, T& value) { value = *static_cast<T const*>(buffer); static_assert(std::is_trivially_copyable<T>::value, "Cannot unflatten a non-trivially-copyable type"); memcpy(&value, buffer, sizeof(T)); advance(buffer, size, sizeof(T)); } }; Loading Loading
include/utils/Flattenable.h +9 −2 Original line number Diff line number Diff line Loading @@ -19,10 +19,13 @@ #include <stdint.h> #include <string.h> #include <sys/types.h> #include <utils/Errors.h> #include <utils/Debug.h> #include <type_traits> namespace android { Loading Loading @@ -60,14 +63,18 @@ public: // write a POD structure template<typename T> static void write(void*& buffer, size_t& size, const T& value) { *static_cast<T*>(buffer) = value; static_assert(std::is_trivially_copyable<T>::value, "Cannot flatten a non-trivially-copyable type"); memcpy(buffer, &value, sizeof(T)); advance(buffer, size, sizeof(T)); } // read a POD structure template<typename T> static void read(void const*& buffer, size_t& size, T& value) { value = *static_cast<T const*>(buffer); static_assert(std::is_trivially_copyable<T>::value, "Cannot unflatten a non-trivially-copyable type"); memcpy(&value, buffer, sizeof(T)); advance(buffer, size, sizeof(T)); } }; Loading