1 /* 2 * Copyright (c) 2021 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 PANDA_LIBPANDAFILE_PROTO_DATA_ACCESSOR_H_ 17 #define PANDA_LIBPANDAFILE_PROTO_DATA_ACCESSOR_H_ 18 19 #include "file.h" 20 #include "file_items.h" 21 22 namespace panda::panda_file { 23 24 // NOLINTNEXTLINE(cppcoreguidelines-special-member-functions, hicpp-special-member-functions) 25 class ProtoDataAccessor { 26 public: ProtoDataAccessor(const File & panda_file,File::EntityId proto_id)27 ProtoDataAccessor(const File &panda_file, File::EntityId proto_id) : panda_file_(panda_file), proto_id_(proto_id) {} 28 29 ~ProtoDataAccessor() = default; 30 GetPandaFile()31 const File &GetPandaFile() const 32 { 33 return panda_file_; 34 } 35 GetProtoId()36 File::EntityId GetProtoId() const 37 { 38 return proto_id_; 39 } 40 GetShorty()41 Span<const uint8_t> GetShorty() const 42 { 43 return panda_file_.GetSpanFromId(proto_id_); 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 GetSize()57 size_t GetSize() 58 { 59 if (size_ == 0) { 60 SkipShorty(); 61 } 62 63 return size_; 64 } 65 66 private: 67 void SkipShorty(); 68 69 Type GetType(size_t idx) const; 70 71 const File &panda_file_; 72 File::EntityId proto_id_; 73 74 size_t elem_num_ {0}; 75 Span<const uint8_t> ref_types_sp_ {nullptr, nullptr}; 76 77 size_t size_ {0}; 78 }; 79 80 } // namespace panda::panda_file 81 82 #endif // PANDA_LIBPANDAFILE_PROTO_DATA_ACCESSOR_H_ 83