153c3577eSopenharmony_ci/* 253c3577eSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 353c3577eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 453c3577eSopenharmony_ci * you may not use this file except in compliance with the License. 553c3577eSopenharmony_ci * You may obtain a copy of the License at 653c3577eSopenharmony_ci * 753c3577eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 853c3577eSopenharmony_ci * 953c3577eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1053c3577eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1153c3577eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1253c3577eSopenharmony_ci * See the License for the specific language governing permissions and 1353c3577eSopenharmony_ci * limitations under the License. 1453c3577eSopenharmony_ci */ 1553c3577eSopenharmony_ci 1653c3577eSopenharmony_ci#ifndef OHOS_DISTRIBUTED_DATA_SERVICES_EXTENSION_EXTENSION_UTIL_H 1753c3577eSopenharmony_ci#define OHOS_DISTRIBUTED_DATA_SERVICES_EXTENSION_EXTENSION_UTIL_H 1853c3577eSopenharmony_ci 1953c3577eSopenharmony_ci#include "basic_rust_types.h" 2053c3577eSopenharmony_ci#include "cloud_ext_types.h" 2153c3577eSopenharmony_ci#include "cloud_extension.h" 2253c3577eSopenharmony_ci#include "cloud/cloud_info.h" 2353c3577eSopenharmony_ci#include "cloud/schema_meta.h" 2453c3577eSopenharmony_ci#include "error.h" 2553c3577eSopenharmony_ci#include "error/general_error.h" 2653c3577eSopenharmony_ci#include "store/general_value.h" 2753c3577eSopenharmony_ci 2853c3577eSopenharmony_cinamespace OHOS::CloudData { 2953c3577eSopenharmony_ciusing DBMeta = DistributedData::Database; 3053c3577eSopenharmony_ciusing DBTable = DistributedData::Table; 3153c3577eSopenharmony_ciusing DBErr = DistributedData::GeneralError; 3253c3577eSopenharmony_ciusing DBValue = DistributedData::Value; 3353c3577eSopenharmony_ciusing DBBytes = DistributedData::Bytes; 3453c3577eSopenharmony_ciusing DBAsset = DistributedData::Asset; 3553c3577eSopenharmony_ciusing DBAssets = DistributedData::Assets; 3653c3577eSopenharmony_ciusing DBAssetStatus = DBAsset::Status; 3753c3577eSopenharmony_ciusing DBInfo = DistributedData::CloudInfo::AppInfo; 3853c3577eSopenharmony_ciusing DBVBucket = DistributedData::VBucket; 3953c3577eSopenharmony_ciusing DBVBuckets = DistributedData::VBuckets; 4053c3577eSopenharmony_ciclass ExtensionUtil final { 4153c3577eSopenharmony_cipublic: 4253c3577eSopenharmony_ci template<class T> 4353c3577eSopenharmony_ci inline static constexpr auto TYPE_INDEX = DistributedData::TYPE_INDEX<T>; 4453c3577eSopenharmony_ci static DBVBuckets ConvertBuckets(OhCloudExtVector *values); 4553c3577eSopenharmony_ci static DBVBucket ConvertBucket(OhCloudExtHashMap *value); 4653c3577eSopenharmony_ci static DBInfo ConvertAppInfo(OhCloudExtAppInfo *appInfo); 4753c3577eSopenharmony_ci static DBAsset ConvertAsset(OhCloudExtCloudAsset *asset); 4853c3577eSopenharmony_ci static DBValue ConvertValue(OhCloudExtValue *value); 4953c3577eSopenharmony_ci static DBValue ConvertValues(OhCloudExtValueBucket *bucket, const std::string &key); 5053c3577eSopenharmony_ci static DBErr ConvertStatus(int status); 5153c3577eSopenharmony_ci static DBAssets ConvertAssets(OhCloudExtVector *values); 5253c3577eSopenharmony_ci 5353c3577eSopenharmony_ci static std::pair<OhCloudExtHashMap *, size_t> Convert(const DBVBucket &bucket); 5453c3577eSopenharmony_ci static std::pair<OhCloudExtVector *, size_t> Convert(DBVBuckets &&buckets); 5553c3577eSopenharmony_ci static std::pair<OhCloudExtDatabase *, size_t> Convert(const DBMeta &dbMeta); 5653c3577eSopenharmony_ci static std::pair<OhCloudExtValue *, size_t> Convert(const DBValue &dbValue); 5753c3577eSopenharmony_ci static std::pair<OhCloudExtCloudAsset *, size_t> Convert(const DBAsset &dbAsset); 5853c3577eSopenharmony_ci static std::pair<OhCloudExtVector *, size_t> Convert(const DBAssets &dbAssets); 5953c3577eSopenharmony_ci static std::pair<OhCloudExtVector *, size_t> Convert(const DBTable &dbTable); 6053c3577eSopenharmony_ci static OhCloudExtAssetStatus ConvertAssetStatus(DBAssetStatus status); 6153c3577eSopenharmony_ci 6253c3577eSopenharmony_ciprivate: 6353c3577eSopenharmony_ci static void ConvertAssetLeft(OhCloudExtCloudAsset *asset, DBAsset &dbAsset); 6453c3577eSopenharmony_ci static void DoConvertValue(void *content, unsigned int ctLen, OhCloudExtValueType type, DBValue &dbvalue); 6553c3577eSopenharmony_ci}; 6653c3577eSopenharmony_ci} // namespace OHOS::CloudData 6753c3577eSopenharmony_ci#endif // OHOS_DISTRIBUTED_DATA_SERVICES_EXTENSION_EXTENSION_UTIL_H 68