/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef PREFERENCES_VALUE_PARCEL_H #define PREFERENCES_VALUE_PARCEL_H #include #include #include #include #include "preferences_value.h" namespace OHOS { namespace NativePreferences { class PreferencesValueParcel { public: static uint8_t GetTypeIndex(const PreferencesValue &value); static uint32_t CalSize(PreferencesValue value); static int MarshallingPreferenceValue(const PreferencesValue &value, std::vector &data); static std::pair UnmarshallingPreferenceValue(const std::vector &data); private: enum ParcelTypeIndex { MONO_TYPE = 0, INT_TYPE = 1, LONG_TYPE = 2, FLOAT_TYPE = 3, DOUBLE_TYPE = 4, BOOL_TYPE = 5, STRING_TYPE = 6, STRING_ARRAY_TYPE = 7, BOOL_ARRAY_TYPE = 8, DOUBLE_ARRAY_TYPE = 9, UINT8_ARRAY_TYPE = 10, OBJECT_TYPE = 11, BIG_INT_TYPE = 12 }; static int MarshallingBasicValue(const PreferencesValue &value, const uint8_t type, std::vector &data); static int MarshallingStringValue(const PreferencesValue &value, const uint8_t type, std::vector &data); static int MarshallingStringArrayValue(const PreferencesValue &value, const uint8_t type, std::vector &data); static int MarshallingVecUInt8AfterType(const PreferencesValue &value, uint8_t *startAddr); static int MarshallingVecBigIntAfterType(const PreferencesValue &value, uint8_t *startAddr); static int MarshallingVecDoubleAfterType(const PreferencesValue &value, uint8_t *startAddr); static int MarshallingVecBoolAfterType(const PreferencesValue &value, uint8_t *startAddr); static int MarshallingBasicArrayValue(const PreferencesValue &value, const uint8_t type, std::vector &data); static std::pair UnmarshallingBasicValue(const uint8_t type, const std::vector &data); static std::pair UnmarshallingStringValue(const uint8_t type, const std::vector &data); static std::pair UnmarshallingStringArrayValue(const uint8_t type, const std::vector &data); static std::pair UnmarshallingVecUInt8(const std::vector &data); static std::pair UnmarshallingVecDouble(const std::vector &data); static std::pair UnmarshallingVecBool(const std::vector &data); static std::pair UnmarshallingVecBigInt(const std::vector &data); static std::pair UnmarshallingBasicArrayValue(const uint8_t type, const std::vector &data); static int MarshallingBasicValueInner(const PreferencesValue &value, const uint8_t type, std::vector &data); }; } // namespace NativePreferences } // namespace OHOS #endif