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 OHOS_AUDIO_DATA_H
17 #define OHOS_AUDIO_DATA_H
18 
19 #include <map>
20 #include <string>
21 
22 namespace OHOS {
23 namespace DistributedHardware {
24 using std::string;
25 using std::map;
26 
27 class AudioData {
28 public:
29     explicit AudioData(const size_t capacity);
30     ~AudioData();
31 
32     size_t Size() const;
33     size_t Capacity() const;
34     uint8_t *Data() const;
35     int32_t SetRange(size_t offset, size_t size);
36 
37     void SetInt64(const string name, int64_t value);
38     bool FindInt32(const string &name, int32_t &value);
39     bool FindInt64(const string &name, int64_t &value);
40     bool FindString(const string &name, string &value);
41 
42 private:
43     const uint32_t CAPACITY_MAX_SIZE = 2 * 4096;
44     size_t capacity_ = 0;
45     size_t rangeOffset_ = 0;
46     size_t rangeLength_ = 0;
47     uint8_t *data_ = nullptr;
48 
49     map<string, int32_t> int32Map_;
50     map<string, int64_t> int64Map_;
51     map<string, string> stringMap_;
52 
53     AudioData(const AudioData &) = delete;
54     AudioData &operator = (const AudioData &) = delete;
55 };
56 } // namespace DistributedHardware
57 } // namespace OHOS
58 #endif // OHOS_AUDIO_DATA_H
59