• 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 OHOS_IDL_METADATASERIALIZER_H
17 #define OHOS_IDL_METADATASERIALIZER_H
18 
19 #include <cstddef>
20 #include <cstdint>
21 
22 #include "metadata/meta_component.h"
23 #include "metadata/meta_interface.h"
24 #include "metadata/meta_method.h"
25 #include "metadata/meta_namespace.h"
26 #include "metadata/meta_patameter.h"
27 #include "metadata/meta_rawdata.h"
28 #include "metadata/meta_sequenceable.h"
29 #include "metadata/meta_type.h"
30 
31 
32 namespace OHOS {
33 namespace Idl {
34 class MetadataSerializer {
35 public:
MetadataSerializer(MetaComponent * mc)36     explicit MetadataSerializer(MetaComponent* mc)
37         : metaComponent_(mc),
38           baseAddr_(reinterpret_cast<uintptr_t>(mc))
39     {}
40 
MetadataSerializer(uintptr_t addr)41     explicit MetadataSerializer(uintptr_t addr)
42         : metaComponent_(reinterpret_cast<MetaComponent*>(addr)),
43           baseAddr_(addr)
44     {}
45 
46     ~MetadataSerializer() = default;
47 
48     void Serialize();
49 
50     void Deserialize();
51 
GetData()52     uintptr_t GetData() const
53     {
54         return baseAddr_;
55     }
56 
GetDataSize()57     int GetDataSize() const
58     {
59         return metaComponent_->size_;
60     }
61 
62 private:
63     void SerializeMetaComponent(MetaComponent* mc);
64 
65     void SerializeMetaNamespace(MetaNamespace* mn);
66 
67     void SerializeMetaSequenceable(MetaSequenceable* mp);
68 
69     void SerializeMetaRawData(MetaRawData* mp);
70 
71     void SerializeMetaInterface(MetaInterface* mi);
72 
73     void SerializeMetaMethod(MetaMethod* mm);
74 
75     void SerializeMetaParameter(MetaParameter* mp);
76 
77     void SerializeMetaType(MetaType* mt);
78 
79     ptrdiff_t SerializeAdjust(const void* addr);
80 
81     void DeserializeMetaComponent(MetaComponent* mc);
82 
83     void DeserializeMetaNamespace(MetaNamespace* mn);
84 
85     void DeserializeMetaSequenceable(MetaSequenceable* mp);
86 
87     void DeserializeMetaRawData(MetaRawData* mp);
88 
89     void DeserializeMetaInterface(MetaInterface* mi);
90 
91     void DeserializeMetaMethod(MetaMethod* mm);
92 
93     void DeserializeMetaParameter(MetaParameter* mp);
94 
95     void DeserializeMetaType(MetaType* mt);
96 
97     uintptr_t DeserializeAdjust(const void* addr);
98 
99     MetaComponent* metaComponent_;
100     uintptr_t baseAddr_;
101 };
102 } // namespace Idl
103 } // namespace OHOS
104 #endif // OHOS_IDL_METADATASERIALIZER_H
105