18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci 168bf80f4bSopenharmony_ci#ifndef META_TEST_SERIALISATION_UTILS_HEADER 178bf80f4bSopenharmony_ci#define META_TEST_SERIALISATION_UTILS_HEADER 188bf80f4bSopenharmony_ci 198bf80f4bSopenharmony_ci#include <base/containers/vector.h> 208bf80f4bSopenharmony_ci#include <core/io/intf_file.h> 218bf80f4bSopenharmony_ci#include <core/log.h> 228bf80f4bSopenharmony_ci 238bf80f4bSopenharmony_ci#include <meta/interface/intf_object.h> 248bf80f4bSopenharmony_ci#include <meta/interface/serialization/intf_global_serialization_data.h> 258bf80f4bSopenharmony_ci 268bf80f4bSopenharmony_ciMETA_BEGIN_NAMESPACE() 278bf80f4bSopenharmony_ci 288bf80f4bSopenharmony_cistruct MemFile : public CORE_NS::IFile { 298bf80f4bSopenharmony_ci explicit MemFile(BASE_NS::vector<char> vec = {}); 308bf80f4bSopenharmony_ci 318bf80f4bSopenharmony_ci Mode GetMode() const override; 328bf80f4bSopenharmony_ci void Close() override; 338bf80f4bSopenharmony_ci uint64_t Read(void* buffer, uint64_t count) override; 348bf80f4bSopenharmony_ci uint64_t Write(const void* buffer, uint64_t count) override; 358bf80f4bSopenharmony_ci uint64_t GetLength() const override; 368bf80f4bSopenharmony_ci bool Seek(uint64_t offset) override; 378bf80f4bSopenharmony_ci uint64_t GetPosition() const override; 388bf80f4bSopenharmony_ci 398bf80f4bSopenharmony_ci BASE_NS::vector<char> Data() const; 408bf80f4bSopenharmony_ciprivate: 418bf80f4bSopenharmony_ci void Destroy() override; 428bf80f4bSopenharmony_ci BASE_NS::vector<char> data_; 438bf80f4bSopenharmony_ci size_t pos_ {}; 448bf80f4bSopenharmony_ci}; 458bf80f4bSopenharmony_ci 468bf80f4bSopenharmony_cistruct TestSerialiser { 478bf80f4bSopenharmony_ci explicit TestSerialiser(BASE_NS::vector<char> data = {}); 488bf80f4bSopenharmony_ci 498bf80f4bSopenharmony_ci bool Export(const IObject::Ptr& object); 508bf80f4bSopenharmony_ci IObject::Ptr Import(); 518bf80f4bSopenharmony_ci 528bf80f4bSopenharmony_ci template<typename Interface> 538bf80f4bSopenharmony_ci bool Export(const BASE_NS::shared_ptr<Interface>& p) 548bf80f4bSopenharmony_ci { 558bf80f4bSopenharmony_ci return Export(interface_pointer_cast<IObject>(p)); 568bf80f4bSopenharmony_ci } 578bf80f4bSopenharmony_ci 588bf80f4bSopenharmony_ci template<typename Interface> 598bf80f4bSopenharmony_ci typename Interface::Ptr Import() 608bf80f4bSopenharmony_ci { 618bf80f4bSopenharmony_ci return interface_pointer_cast<Interface>(Import()); 628bf80f4bSopenharmony_ci } 638bf80f4bSopenharmony_ci 648bf80f4bSopenharmony_ci bool LoadFile(BASE_NS::string_view path); 658bf80f4bSopenharmony_ci BASE_NS::string Get() const; 668bf80f4bSopenharmony_ci 678bf80f4bSopenharmony_ci void SetSerializationSettings(SerializationSettings s); 688bf80f4bSopenharmony_ci 698bf80f4bSopenharmony_ciprivate: 708bf80f4bSopenharmony_ci MemFile data_; 718bf80f4bSopenharmony_ci std::size_t writePos_ {}; 728bf80f4bSopenharmony_ci std::size_t readPos_ {}; 738bf80f4bSopenharmony_ci}; 748bf80f4bSopenharmony_ci 758bf80f4bSopenharmony_civoid WriteToFile(const BASE_NS::vector<char>&, BASE_NS::string_view file); 768bf80f4bSopenharmony_ci 778bf80f4bSopenharmony_ciMETA_END_NAMESPACE() 788bf80f4bSopenharmony_ci 798bf80f4bSopenharmony_ci#endif