Implement an object backed IStorage backing

This is more convinient and efficient to use when passing structured data out of applets
This commit is contained in:
Billy Laws 2022-04-15 13:25:11 +01:00 committed by PixelyIon
parent d115ce3c05
commit df5d1256c2

View File

@ -0,0 +1,27 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/)
#pragma once
#include <services/serviceman.h>
#include "IStorage.h"
namespace skyline::service::am {
/**
* @brief ObjIStorage is an IStorage backed by a trivially copyable object
*/
template<typename T> requires std::is_trivially_copyable_v<T>
class ObjIStorage : public IStorage {
private:
T obj;
public:
ObjIStorage(const DeviceState &state, ServiceManager &manager, T &&obj) : IStorage(state, manager, true), obj(obj) {}
~ObjIStorage() override = default;
span<u8> GetSpan() override {
return {reinterpret_cast<u8 *>(&obj), sizeof(T)};
};
};
}