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 QUERY_SYNC_OBJECT_H 17 #define QUERY_SYNC_OBJECT_H 18 19 #include <string> 20 21 #include "query_object.h" 22 #include "parcel.h" 23 24 namespace DistributedDB { 25 const uint32_t QUERY_SYNC_OBJECT_VERSION_0 = 0; 26 const uint32_t QUERY_SYNC_OBJECT_VERSION_1 = 1; // Add tableName_ and keys_. 27 const uint32_t QUERY_SYNC_OBJECT_VERSION_CURRENT = QUERY_SYNC_OBJECT_VERSION_1; // always point the last. 28 29 struct ObjContext { 30 uint32_t version = QUERY_SYNC_OBJECT_VERSION_0; // serialized struct version 31 std::vector<uint8_t> prefixKey{}; 32 std::string suggestIndex{}; 33 std::list<QueryObjNode> queryObjNodes{}; 34 std::vector<Key> keys{}; 35 }; 36 37 class QuerySyncObject : public QueryObject { 38 public: 39 QuerySyncObject(); 40 QuerySyncObject(const std::list<QueryObjNode> &queryObjNodes, const std::vector<uint8_t> &prefixKey, 41 const std::set<Key> &keys); 42 explicit QuerySyncObject(const Query &query); 43 ~QuerySyncObject() override; 44 45 std::string GetIdentify() const; 46 47 int SerializeData(Parcel &parcel, uint32_t softWareVersion); 48 // should call Parcel.IsError() to Get result. 49 static int DeSerializeData(Parcel &parcel, QuerySyncObject &queryObj); 50 uint32_t CalculateParcelLen(uint32_t softWareVersion) const; 51 52 std::string GetRelationTableName() const; 53 54 private: 55 uint32_t CalculateLen() const; 56 int GetObjContext(ObjContext &objContext) const; 57 uint32_t GetVersion() const; 58 }; 59 } 60 #endif