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