• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-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 LIBPANDAFILE_PROTO_DATA_ACCESSOR_H_
17 #define LIBPANDAFILE_PROTO_DATA_ACCESSOR_H_
18 
19 #include "file.h"
20 #include "file_items.h"
21 
22 namespace ark::panda_file {
23 
24 // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions, hicpp-special-member-functions)
25 class ProtoDataAccessor {
26 public:
ProtoDataAccessor(const File & pandaFile,File::EntityId protoId)27     ProtoDataAccessor(const File &pandaFile, File::EntityId protoId) : pandaFile_(pandaFile), protoId_(protoId) {}
28 
29     ~ProtoDataAccessor() = default;
30 
GetPandaFile()31     const File &GetPandaFile() const
32     {
33         return pandaFile_;
34     }
35 
GetProtoId()36     File::EntityId GetProtoId() const
37     {
38         return protoId_;
39     }
40 
GetShorty()41     Span<const uint8_t> GetShorty() const
42     {
43         return pandaFile_.GetSpanFromId(protoId_);
44     }
45 
46     template <class Callback>
47     void EnumerateTypes(const Callback &c);
48 
49     uint32_t GetNumArgs();
50 
51     Type GetArgType(size_t idx) const;
52 
53     Type GetReturnType() const;
54 
55     File::EntityId GetReferenceType(size_t i);
56 
57     Type GetType(size_t idx) const;
58 
59     uint32_t GetNumElements();
60 
GetRefNum()61     size_t GetRefNum()
62     {
63         if (refTypesSp_.data() == nullptr) {
64             SkipShorty();
65         }
66 
67         return refTypesNum_;
68     }
69 
GetSize()70     size_t GetSize()
71     {
72         if (size_ == 0) {
73             SkipShorty();
74         }
75 
76         return size_;
77     }
78 
79     bool IsEqual(ProtoDataAccessor *other);
80 
81 private:
82     void SkipShorty();
83 
84     const File &pandaFile_;
85     File::EntityId protoId_;
86 
87     size_t elemNum_ {0};
88     Span<const uint8_t> refTypesSp_ {nullptr, nullptr};
89     size_t refTypesNum_ {0};
90     size_t size_ {0};
91 };
92 
93 }  // namespace ark::panda_file
94 
95 #endif  // LIBPANDAFILE_PROTO_DATA_ACCESSOR_H_
96