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