• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "json_exporter.h"
17 
18 #include <meta/api/util.h>
19 
20 #include "backend/json_output.h"
21 
22 META_BEGIN_NAMESPACE()
23 namespace Serialization {
24 
Export(CORE_NS::IFile & output,const IObject::ConstPtr & object)25 ReturnError JsonExporter::Export(CORE_NS::IFile& output, const IObject::ConstPtr& object)
26 {
27     auto tree = Export(object);
28     if (!tree) {
29         return GenericError::FAIL;
30     }
31     JsonOutput backend;
32     auto json = backend.Process(tree);
33     if (json.empty()) {
34         return GenericError::FAIL;
35     }
36     output.Write(json.c_str(), json.size());
37     return GenericError::SUCCESS;
38 }
Export(const IObject::ConstPtr & object)39 ISerNode::Ptr JsonExporter::Export(const IObject::ConstPtr& object)
40 {
41     return exp_.Export(object);
42 }
SetInstanceIdMapping(BASE_NS::unordered_map<InstanceId,InstanceId> map)43 void JsonExporter::SetInstanceIdMapping(BASE_NS::unordered_map<InstanceId, InstanceId> map)
44 {
45     exp_.SetInstanceIdMapping(BASE_NS::move(map));
46 }
SetResourceManager(CORE_NS::IResourceManager::Ptr p)47 void JsonExporter::SetResourceManager(CORE_NS::IResourceManager::Ptr p)
48 {
49     exp_.SetResourceManager(BASE_NS::move(p));
50 }
SetUserContext(IObject::Ptr p)51 void JsonExporter::SetUserContext(IObject::Ptr p)
52 {
53     exp_.SetUserContext(BASE_NS::move(p));
54 }
SetMetadata(SerMetadata m)55 void JsonExporter::SetMetadata(SerMetadata m)
56 {
57     exp_.SetMetadata(BASE_NS::move(m));
58 }
59 
60 } // namespace Serialization
61 META_END_NAMESPACE()
62