1 /*
2  * Copyright (c) 2021-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 OHOS_DATA_BUFFER_H
17 #define OHOS_DATA_BUFFER_H
18 
19 #include <map>
20 #include <string>
21 #include <cstddef>
22 #include <cstdint>
23 #include "ifeedable_data.h"
24 #include "dcamera_frame_info.h"
25 
26 namespace OHOS {
27 namespace DistributedHardware {
28 class DataBuffer : public IFeedableData {
29 public:
30     explicit DataBuffer(size_t capacity);
31 
32     size_t Size() const;
33     size_t Offset() const;
34     size_t Capacity() const;
35     uint8_t *Data() const;
36     int32_t SetRange(size_t offset, size_t size);
37 
38     void SetInt32(const std::string name, int32_t value);
39     void SetInt64(const std::string name, int64_t value);
40     void SetString(const std::string name, std::string value);
41     bool FindInt32(const std::string& name, int32_t& value);
42     bool FindInt64(const std::string& name, int64_t& value);
43     bool FindString(const std::string& name, std::string& value);
44     int64_t GetTimeStamp() override;
45     virtual ~DataBuffer();
46     DCameraFrameInfo frameInfo_;
47 
48 private:
49     size_t capacity_ = 0;
50     size_t rangeOffset_ = 0;
51     size_t rangeLength_ = 0;
52     uint8_t *data_ = nullptr;
53 
54     std::map<std::string, int32_t> int32Map_;
55     std::map<std::string, int64_t> int64Map_;
56     std::map<std::string, std::string> stringMap_;
57 
58     DataBuffer(const DataBuffer &) = delete;
59     DataBuffer &operator = (const DataBuffer &) = delete;
60 };
61 } // namespace DistributedHardware
62 } // namespace OHOS
63 #endif // OHOS_DATA_BUFFER_H
64