1fc223305Sopenharmony_ci/* 2fc223305Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3fc223305Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fc223305Sopenharmony_ci * you may not use this file except in compliance with the License. 5fc223305Sopenharmony_ci * You may obtain a copy of the License at 6fc223305Sopenharmony_ci * 7fc223305Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fc223305Sopenharmony_ci * 9fc223305Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fc223305Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fc223305Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fc223305Sopenharmony_ci * See the License for the specific language governing permissions and 13fc223305Sopenharmony_ci * limitations under the License. 14fc223305Sopenharmony_ci */ 15fc223305Sopenharmony_ci 16fc223305Sopenharmony_ci#ifndef PREFERENCES_VALUE_PARCEL_H 17fc223305Sopenharmony_ci#define PREFERENCES_VALUE_PARCEL_H 18fc223305Sopenharmony_ci 19fc223305Sopenharmony_ci#include <vector> 20fc223305Sopenharmony_ci#include <cstdint> 21fc223305Sopenharmony_ci#include <string> 22fc223305Sopenharmony_ci#include <type_traits> 23fc223305Sopenharmony_ci 24fc223305Sopenharmony_ci#include "preferences_value.h" 25fc223305Sopenharmony_cinamespace OHOS { 26fc223305Sopenharmony_cinamespace NativePreferences { 27fc223305Sopenharmony_ci 28fc223305Sopenharmony_ciclass PreferencesValueParcel { 29fc223305Sopenharmony_cipublic: 30fc223305Sopenharmony_ci static uint8_t GetTypeIndex(const PreferencesValue &value); 31fc223305Sopenharmony_ci static uint32_t CalSize(PreferencesValue value); 32fc223305Sopenharmony_ci static int MarshallingPreferenceValue(const PreferencesValue &value, std::vector<uint8_t> &data); 33fc223305Sopenharmony_ci static std::pair<int, PreferencesValue> UnmarshallingPreferenceValue(const std::vector<uint8_t> &data); 34fc223305Sopenharmony_ci 35fc223305Sopenharmony_ciprivate: 36fc223305Sopenharmony_ci enum ParcelTypeIndex { 37fc223305Sopenharmony_ci MONO_TYPE = 0, 38fc223305Sopenharmony_ci INT_TYPE = 1, 39fc223305Sopenharmony_ci LONG_TYPE = 2, 40fc223305Sopenharmony_ci FLOAT_TYPE = 3, 41fc223305Sopenharmony_ci DOUBLE_TYPE = 4, 42fc223305Sopenharmony_ci BOOL_TYPE = 5, 43fc223305Sopenharmony_ci STRING_TYPE = 6, 44fc223305Sopenharmony_ci STRING_ARRAY_TYPE = 7, 45fc223305Sopenharmony_ci BOOL_ARRAY_TYPE = 8, 46fc223305Sopenharmony_ci DOUBLE_ARRAY_TYPE = 9, 47fc223305Sopenharmony_ci UINT8_ARRAY_TYPE = 10, 48fc223305Sopenharmony_ci OBJECT_TYPE = 11, 49fc223305Sopenharmony_ci BIG_INT_TYPE = 12 50fc223305Sopenharmony_ci }; 51fc223305Sopenharmony_ci static int MarshallingBasicValue(const PreferencesValue &value, const uint8_t type, std::vector<uint8_t> &data); 52fc223305Sopenharmony_ci static int MarshallingStringValue(const PreferencesValue &value, const uint8_t type, std::vector<uint8_t> &data); 53fc223305Sopenharmony_ci static int MarshallingStringArrayValue(const PreferencesValue &value, const uint8_t type, 54fc223305Sopenharmony_ci std::vector<uint8_t> &data); 55fc223305Sopenharmony_ci static int MarshallingVecUInt8AfterType(const PreferencesValue &value, uint8_t *startAddr); 56fc223305Sopenharmony_ci static int MarshallingVecBigIntAfterType(const PreferencesValue &value, uint8_t *startAddr); 57fc223305Sopenharmony_ci static int MarshallingVecDoubleAfterType(const PreferencesValue &value, uint8_t *startAddr); 58fc223305Sopenharmony_ci static int MarshallingVecBoolAfterType(const PreferencesValue &value, uint8_t *startAddr); 59fc223305Sopenharmony_ci static int MarshallingBasicArrayValue(const PreferencesValue &value, const uint8_t type, 60fc223305Sopenharmony_ci std::vector<uint8_t> &data); 61fc223305Sopenharmony_ci static std::pair<int, PreferencesValue> UnmarshallingBasicValue(const uint8_t type, 62fc223305Sopenharmony_ci const std::vector<uint8_t> &data); 63fc223305Sopenharmony_ci static std::pair<int, PreferencesValue> UnmarshallingStringValue(const uint8_t type, 64fc223305Sopenharmony_ci const std::vector<uint8_t> &data); 65fc223305Sopenharmony_ci static std::pair<int, PreferencesValue> UnmarshallingStringArrayValue(const uint8_t type, 66fc223305Sopenharmony_ci const std::vector<uint8_t> &data); 67fc223305Sopenharmony_ci static std::pair<int, PreferencesValue> UnmarshallingVecUInt8(const std::vector<uint8_t> &data); 68fc223305Sopenharmony_ci static std::pair<int, PreferencesValue> UnmarshallingVecDouble(const std::vector<uint8_t> &data); 69fc223305Sopenharmony_ci static std::pair<int, PreferencesValue> UnmarshallingVecBool(const std::vector<uint8_t> &data); 70fc223305Sopenharmony_ci static std::pair<int, PreferencesValue> UnmarshallingVecBigInt(const std::vector<uint8_t> &data); 71fc223305Sopenharmony_ci static std::pair<int, PreferencesValue> UnmarshallingBasicArrayValue(const uint8_t type, 72fc223305Sopenharmony_ci const std::vector<uint8_t> &data); 73fc223305Sopenharmony_ci static int MarshallingBasicValueInner(const PreferencesValue &value, const uint8_t type, 74fc223305Sopenharmony_ci std::vector<uint8_t> &data); 75fc223305Sopenharmony_ci}; 76fc223305Sopenharmony_ci} // namespace NativePreferences 77fc223305Sopenharmony_ci} // namespace OHOS 78fc223305Sopenharmony_ci#endif