1 /* 2 * Copyright (c) 2022 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 NWEB_WEB_MESSAGE_H 17 #define NWEB_WEB_MESSAGE_H 18 19 #include <vector> 20 21 #include "nweb_export.h" 22 #include "nweb_value.h" 23 24 namespace OHOS::NWeb { 25 26 class OHOS_NWEB_EXPORT NWebMessage : public NWebValue { 27 public: NWebMessage(NWebValue::Type type)28 explicit NWebMessage(NWebValue::Type type) : NWebValue(type) {} 29 30 ~NWebMessage() = default; 31 SetBinary(std::vector<uint8_t> & binary_data)32 void SetBinary(std::vector<uint8_t>& binary_data) 33 { 34 binary_data_.reserve(binary_data.size()); 35 binary_data_ = binary_data; 36 } 37 GetBinary()38 std::vector<uint8_t> GetBinary() 39 { 40 return binary_data_; 41 } 42 GetErrName()43 std::string GetErrName() 44 { 45 return err_name_; 46 } 47 GetErrMsg()48 std::string GetErrMsg() 49 { 50 return err_msg_; 51 } 52 GetInt64()53 int64_t GetInt64() 54 { 55 return value_; 56 } 57 SetErrName(std::string name)58 void SetErrName(std::string name) 59 { 60 err_name_ = name; 61 } 62 SetErrMsg(std::string msg)63 void SetErrMsg(std::string msg) 64 { 65 err_msg_ = msg; 66 } 67 SetInt64(int64_t value)68 void SetInt64(int64_t value) 69 { 70 value_ = value; 71 } 72 GetStringArray()73 std::vector<std::string> GetStringArray() 74 { 75 return string_arr_; 76 } 77 SetStringArray(std::vector<std::string> string_arr)78 void SetStringArray(std::vector<std::string> string_arr) 79 { 80 string_arr_ = string_arr; 81 } 82 GetBooleanArray()83 std::vector<bool> GetBooleanArray() 84 { 85 return bool_arr_; 86 } 87 SetBooleanArray(std::vector<bool> bool_arr)88 void SetBooleanArray(std::vector<bool> bool_arr) 89 { 90 bool_arr_ = bool_arr; 91 } 92 GetDoubleArray()93 std::vector<double> GetDoubleArray() 94 { 95 return double_arr_; 96 } 97 SetDoubleArray(std::vector<double> double_arr)98 void SetDoubleArray(std::vector<double> double_arr) 99 { 100 double_arr_ = double_arr; 101 } 102 GetInt64Array()103 std::vector<int64_t> GetInt64Array() 104 { 105 return int64_arr_; 106 } 107 SetInt64Array(std::vector<int64_t> int64_arr)108 void SetInt64Array(std::vector<int64_t> int64_arr) 109 { 110 int64_arr_ = int64_arr; 111 } 112 113 private: 114 std::vector<uint8_t> binary_data_; 115 std::string err_name_; 116 std::string err_msg_; 117 int64_t value_ = -1; 118 std::vector<std::string> string_arr_; 119 std::vector<bool> bool_arr_; 120 std::vector<double> double_arr_; 121 std::vector<int64_t> int64_arr_; 122 }; 123 124 } // namespace OHOS::NWeb 125 126 #endif // NWEB_WEB_MESSAGE_H 127