commit
52ec1840f5
|
@ -5,6 +5,8 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <utility>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include "common/alignment.h"
|
#include "common/alignment.h"
|
||||||
#include "common/math_util.h"
|
#include "common/math_util.h"
|
||||||
|
@ -43,7 +45,9 @@ public:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T Read() {
|
T Read() {
|
||||||
|
static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable.");
|
||||||
ASSERT(read_index + sizeof(T) <= buffer.size());
|
ASSERT(read_index + sizeof(T) <= buffer.size());
|
||||||
|
|
||||||
T val;
|
T val;
|
||||||
std::memcpy(&val, buffer.data() + read_index, sizeof(T));
|
std::memcpy(&val, buffer.data() + read_index, sizeof(T));
|
||||||
read_index += sizeof(T);
|
read_index += sizeof(T);
|
||||||
|
@ -53,7 +57,9 @@ public:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T ReadUnaligned() {
|
T ReadUnaligned() {
|
||||||
|
static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable.");
|
||||||
ASSERT(read_index + sizeof(T) <= buffer.size());
|
ASSERT(read_index + sizeof(T) <= buffer.size());
|
||||||
|
|
||||||
T val;
|
T val;
|
||||||
std::memcpy(&val, buffer.data() + read_index, sizeof(T));
|
std::memcpy(&val, buffer.data() + read_index, sizeof(T));
|
||||||
read_index += sizeof(T);
|
read_index += sizeof(T);
|
||||||
|
@ -87,8 +93,12 @@ public:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Write(const T& val) {
|
void Write(const T& val) {
|
||||||
if (buffer.size() < write_index + sizeof(T))
|
static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable.");
|
||||||
|
|
||||||
|
if (buffer.size() < write_index + sizeof(T)) {
|
||||||
buffer.resize(buffer.size() + sizeof(T) + DefaultBufferSize);
|
buffer.resize(buffer.size() + sizeof(T) + DefaultBufferSize);
|
||||||
|
}
|
||||||
|
|
||||||
std::memcpy(buffer.data() + write_index, &val, sizeof(T));
|
std::memcpy(buffer.data() + write_index, &val, sizeof(T));
|
||||||
write_index += sizeof(T);
|
write_index += sizeof(T);
|
||||||
write_index = Common::AlignUp(write_index, 4);
|
write_index = Common::AlignUp(write_index, 4);
|
||||||
|
@ -96,7 +106,9 @@ public:
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void WriteObject(const T& val) {
|
void WriteObject(const T& val) {
|
||||||
u32_le size = static_cast<u32>(sizeof(val));
|
static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable.");
|
||||||
|
|
||||||
|
const u32_le size = static_cast<u32>(sizeof(val));
|
||||||
Write(size);
|
Write(size);
|
||||||
// TODO(Subv): Support file descriptors.
|
// TODO(Subv): Support file descriptors.
|
||||||
Write<u32_le>(0); // Fd count.
|
Write<u32_le>(0); // Fd count.
|
||||||
|
@ -176,7 +188,7 @@ private:
|
||||||
|
|
||||||
class IGBPConnectRequestParcel : public Parcel {
|
class IGBPConnectRequestParcel : public Parcel {
|
||||||
public:
|
public:
|
||||||
explicit IGBPConnectRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
|
explicit IGBPConnectRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) {
|
||||||
Deserialize();
|
Deserialize();
|
||||||
}
|
}
|
||||||
~IGBPConnectRequestParcel() override = default;
|
~IGBPConnectRequestParcel() override = default;
|
||||||
|
@ -223,8 +235,8 @@ private:
|
||||||
|
|
||||||
class IGBPSetPreallocatedBufferRequestParcel : public Parcel {
|
class IGBPSetPreallocatedBufferRequestParcel : public Parcel {
|
||||||
public:
|
public:
|
||||||
explicit IGBPSetPreallocatedBufferRequestParcel(const std::vector<u8>& buffer)
|
explicit IGBPSetPreallocatedBufferRequestParcel(std::vector<u8> buffer)
|
||||||
: Parcel(buffer) {
|
: Parcel(std::move(buffer)) {
|
||||||
Deserialize();
|
Deserialize();
|
||||||
}
|
}
|
||||||
~IGBPSetPreallocatedBufferRequestParcel() override = default;
|
~IGBPSetPreallocatedBufferRequestParcel() override = default;
|
||||||
|
@ -256,7 +268,7 @@ protected:
|
||||||
|
|
||||||
class IGBPDequeueBufferRequestParcel : public Parcel {
|
class IGBPDequeueBufferRequestParcel : public Parcel {
|
||||||
public:
|
public:
|
||||||
explicit IGBPDequeueBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
|
explicit IGBPDequeueBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) {
|
||||||
Deserialize();
|
Deserialize();
|
||||||
}
|
}
|
||||||
~IGBPDequeueBufferRequestParcel() override = default;
|
~IGBPDequeueBufferRequestParcel() override = default;
|
||||||
|
@ -307,7 +319,7 @@ protected:
|
||||||
|
|
||||||
class IGBPRequestBufferRequestParcel : public Parcel {
|
class IGBPRequestBufferRequestParcel : public Parcel {
|
||||||
public:
|
public:
|
||||||
explicit IGBPRequestBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
|
explicit IGBPRequestBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) {
|
||||||
Deserialize();
|
Deserialize();
|
||||||
}
|
}
|
||||||
~IGBPRequestBufferRequestParcel() override = default;
|
~IGBPRequestBufferRequestParcel() override = default;
|
||||||
|
@ -322,8 +334,7 @@ public:
|
||||||
|
|
||||||
class IGBPRequestBufferResponseParcel : public Parcel {
|
class IGBPRequestBufferResponseParcel : public Parcel {
|
||||||
public:
|
public:
|
||||||
explicit IGBPRequestBufferResponseParcel(NVFlinger::IGBPBuffer buffer)
|
explicit IGBPRequestBufferResponseParcel(NVFlinger::IGBPBuffer buffer) : buffer(buffer) {}
|
||||||
: Parcel(), buffer(buffer) {}
|
|
||||||
~IGBPRequestBufferResponseParcel() override = default;
|
~IGBPRequestBufferResponseParcel() override = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -340,7 +351,7 @@ protected:
|
||||||
|
|
||||||
class IGBPQueueBufferRequestParcel : public Parcel {
|
class IGBPQueueBufferRequestParcel : public Parcel {
|
||||||
public:
|
public:
|
||||||
explicit IGBPQueueBufferRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
|
explicit IGBPQueueBufferRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) {
|
||||||
Deserialize();
|
Deserialize();
|
||||||
}
|
}
|
||||||
~IGBPQueueBufferRequestParcel() override = default;
|
~IGBPQueueBufferRequestParcel() override = default;
|
||||||
|
@ -409,7 +420,7 @@ private:
|
||||||
|
|
||||||
class IGBPQueryRequestParcel : public Parcel {
|
class IGBPQueryRequestParcel : public Parcel {
|
||||||
public:
|
public:
|
||||||
explicit IGBPQueryRequestParcel(const std::vector<u8>& buffer) : Parcel(buffer) {
|
explicit IGBPQueryRequestParcel(std::vector<u8> buffer) : Parcel(std::move(buffer)) {
|
||||||
Deserialize();
|
Deserialize();
|
||||||
}
|
}
|
||||||
~IGBPQueryRequestParcel() override = default;
|
~IGBPQueryRequestParcel() override = default;
|
||||||
|
|
Loading…
Reference in New Issue