1 /* 2 * Copyright (c) 2021 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 24 using std::string; 25 using std::map; 26 27 namespace OHOS { 28 namespace DistributedHardware { 29 class DataBuffer { 30 public: 31 explicit DataBuffer(size_t capacity); 32 33 size_t Size() const; 34 size_t Offset() const; 35 size_t Capacity() const; 36 uint8_t *Data() const; 37 int32_t SetRange(size_t offset, size_t size); 38 39 void SetInt32(const string name, int32_t value); 40 void SetInt64(const string name, int64_t value); 41 void SetString(const string name, string value); 42 bool FindInt32(const string& name, int32_t& value); 43 bool FindInt64(const string& name, int64_t& value); 44 bool FindString(const string& name, string& value); 45 46 virtual ~DataBuffer(); 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 map<string, int32_t> int32Map_; 55 map<string, int64_t> int64Map_; 56 map<string, 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