• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 API_BASE_CONTAINERS_BYTE_ARRAY_H
17 #define API_BASE_CONTAINERS_BYTE_ARRAY_H
18 
19 #include <cstdint>
20 
21 #include <base/containers/array_view.h>
22 #include <base/containers/unique_ptr.h>
23 #include <base/namespace.h>
24 
BASE_BEGIN_NAMESPACE()25 BASE_BEGIN_NAMESPACE()
26 /** @ingroup group_containers_bytearray */
27 /** Byte Array */
28 class ByteArray {
29 public:
30     ByteArray(const size_t byteSize) : data_(make_unique<uint8_t[]>(byteSize)), byteSize_(byteSize) {}
31 
32     array_view<uint8_t> GetData()
33     {
34         return { data_.get(), byteSize_ };
35     }
36 
37     array_view<const uint8_t> GetData() const
38     {
39         return { data_.get(), byteSize_ };
40     }
41 
42 private:
43     unique_ptr<uint8_t[]> data_;
44     size_t byteSize_ { 0U };
45 };
46 BASE_END_NAMESPACE()
47 
48 #endif // API_BASE_CONTAINERS_BYTE_ARRAY_H
49