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