/*
* Copyright (C) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef META_TEST_SERIALISATION_UTILS_HEADER
#define META_TEST_SERIALISATION_UTILS_HEADER
#include
#include
#include
#include
#include
META_BEGIN_NAMESPACE()
struct MemFile : public CORE_NS::IFile {
explicit MemFile(BASE_NS::vector vec = {});
Mode GetMode() const override;
void Close() override;
uint64_t Read(void* buffer, uint64_t count) override;
uint64_t Write(const void* buffer, uint64_t count) override;
uint64_t GetLength() const override;
bool Seek(uint64_t offset) override;
uint64_t GetPosition() const override;
BASE_NS::vector Data() const;
private:
void Destroy() override;
BASE_NS::vector data_;
size_t pos_ {};
};
struct TestSerialiser {
explicit TestSerialiser(BASE_NS::vector data = {});
bool Export(const IObject::Ptr& object);
IObject::Ptr Import();
template
bool Export(const BASE_NS::shared_ptr& p)
{
return Export(interface_pointer_cast(p));
}
template
typename Interface::Ptr Import()
{
return interface_pointer_cast(Import());
}
bool LoadFile(BASE_NS::string_view path);
BASE_NS::string Get() const;
void SetSerializationSettings(SerializationSettings s);
private:
MemFile data_;
std::size_t writePos_ {};
std::size_t readPos_ {};
};
void WriteToFile(const BASE_NS::vector&, BASE_NS::string_view file);
META_END_NAMESPACE()
#endif