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 MULTI_VER_VALUE_OBJECT_H 17 #define MULTI_VER_VALUE_OBJECT_H 18 19 #ifndef OMIT_MULTI_VER 20 #include <cstdint> 21 #include <vector> 22 23 #include "db_types.h" 24 25 namespace DistributedDB { 26 using ValueSliceHash = std::vector<uint8_t>; 27 using ValueSlice = std::vector<uint8_t>; 28 29 struct ValueObjectHead { 30 uint8_t flag = 0; 31 uint8_t reserved = 0; 32 uint16_t hashNum = 1; 33 uint32_t length = 0; 34 }; 35 36 class MultiVerValueObject { 37 public: 38 static const uint8_t HASH_FLAG = 0x01; 39 MultiVerValueObject()40 MultiVerValueObject() {} ~MultiVerValueObject()41 ~MultiVerValueObject() {} 42 43 int GetValueHash(std::vector<ValueSliceHash> &valueHashes) const; 44 int SetValueHash(const std::vector<ValueSliceHash> &valueHashes); 45 46 int GetSerialData(std::vector<uint8_t> &data) const; 47 int DeSerialData(const std::vector<uint8_t> &data); 48 49 uint32_t GetDataLength() const; 50 void SetDataLength(uint32_t); 51 52 int GetValue(Value &value) const; 53 int SetValue(const Value &value); 54 55 bool IsHash() const; 56 57 // 1:value has been Hash. 0:Origin value 58 void SetFlag(uint8_t flag); 59 60 private: 61 ValueObjectHead head_; 62 std::vector<uint8_t> valueHashVector_; 63 }; 64 } 65 66 #endif // MULTI_VER_VALUE_OBJECT_H 67 #endif