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 PANDA_TOOLING_INSPECTOR_TYPES_REMOTE_OBJECT_TYPE_H 17 #define PANDA_TOOLING_INSPECTOR_TYPES_REMOTE_OBJECT_TYPE_H 18 19 #include "utils/json_builder.h" 20 #include "tooling/inspector/types/numeric_id.h" 21 #include "tooling/inspector/json_serialization/serializable.h" 22 23 #include <variant> 24 #include <optional> 25 26 namespace ark::tooling::inspector { 27 28 class RemoteObjectType final : public JsonSerializable { 29 public: 30 using NumberT = std::variant<int32_t, double>; 31 32 struct BigIntT { 33 int8_t sign; 34 uintmax_t value; 35 }; 36 37 struct SymbolT { 38 std::string description; 39 }; 40 41 struct ObjectT { 42 std::string className; 43 std::optional<RemoteObjectId> objectId; 44 std::optional<std::string> description; 45 }; 46 47 struct ArrayT { 48 std::string className; 49 std::optional<RemoteObjectId> objectId; 50 size_t length; 51 }; 52 53 struct FunctionT { 54 std::string className; 55 std::optional<RemoteObjectId> objectId; 56 std::string name; 57 size_t length; 58 }; 59 60 using TypeValue = std::variant<std::monostate, std::nullptr_t, bool, NumberT, BigIntT, std::string, SymbolT, 61 ObjectT, ArrayT, FunctionT>; 62 63 public: type_(type)64 explicit RemoteObjectType(const char *type, const char *subtype = nullptr) : type_(type), subtype_(subtype) {} 65 Accessor()66 static RemoteObjectType Accessor() 67 { 68 return RemoteObjectType("accessor"); 69 } 70 Serialize(JsonObjectBuilder & builder)71 void Serialize(JsonObjectBuilder &builder) const override 72 { 73 builder.AddProperty("type", type_); 74 75 if (subtype_ != nullptr) { 76 builder.AddProperty("subtype", subtype_); 77 } 78 } 79 80 private: 81 const char *type_ {nullptr}; 82 const char *subtype_ {nullptr}; 83 }; 84 85 } // namespace ark::tooling::inspector 86 87 #endif // PANDA_TOOLING_INSPECTOR_TYPES_REMOTE_OBJECT_TYPE_H 88