• 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 #ifndef META_SRC_SERIALIZATION_BACKEND_JSON_INPUT_H
17 #define META_SRC_SERIALIZATION_BACKEND_JSON_INPUT_H
18 
19 #include <core/json/json.h>
20 
21 #include <meta/base/namespace.h>
22 #include <meta/interface/builtin_objects.h>
23 #include <meta/interface/serialization/intf_ser_input.h>
24 
25 #include "base_object.h"
26 
META_BEGIN_NAMESPACE()27 META_BEGIN_NAMESPACE()
28 
29 namespace Serialization {
30 
31 namespace json = CORE_NS::json;
32 using json_value = CORE_NS::json::standalone_value;
33 
34 class JsonInput : public IntroduceInterfaces<BaseObject, ISerInput> {
35     META_OBJECT(JsonInput, ClassId::JsonInput, IntroduceInterfaces)
36 public:
37     const char* ClassNameName = "$className";
38     const char* NameName = "$name";
39     const char* ObjectIdName = "$classId";
40     const char* InstanceIdName = "$instanceId";
41     BASE_NS::string (*RewriteReservedName)(
42         const BASE_NS::string_view& name) = [](auto name) { return BASE_NS::string(name); };
43 
44     ISerNode::Ptr Process(BASE_NS::string_view data) override;
45 
46     ISerNode::Ptr ImportRef(const json::value& ref);
47     ISerNode::Ptr ImportObject(const json::value& value);
48     ISerNode::Ptr ImportArray(const json::value::array& arr);
49     ISerNode::Ptr Import(const json::value& value);
50     bool ReadMetadata(const json::value& value);
51     ISerNode::Ptr ImportRootObject(const json::value& value);
52 
53     Version GetVersion() const
54     {
55         return metaVersion_;
56     }
57 
58 private:
59     void SetMetaV1Compatibility();
60 
61 private:
62     Version metaVersion_;
63     SerMetadata metadata_;
64 };
65 
66 } // namespace Serialization
67 
68 META_END_NAMESPACE()
69 
70 #endif
71