2 * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #ifndef _SERIALIZER_HPP
17 #define _SERIALIZER_HPP
23 #include "include/flatbuffers/flatbuffers.h"
24 #include "include/fb_generated.h"
26 #include "storage_backend_xml.hpp"
27 #include "policy_containers.hpp"
29 namespace ldp_serializer
32 using FbOff = flatbuffers::Offset<T>;
34 class SerializerFlatbuffers {
39 const ldp_xml::StorageBackendXML *m_db;
40 flatbuffers::FlatBufferBuilder m_builder;
43 auto get_create_set() -> decltype(type_helper<T>::create_set);
45 auto get_create_policy() -> decltype(type_helper<T>::create_policy);
47 auto get_create_policy_pair() -> decltype(type_helper<T>::create_policy_pair);
49 auto get_create_item() -> decltype(type_helper<T>::create_item);
51 FbOff<FB::PolicyOwn> serialize_tree(const ldp_xml_parser::OwnershipTree &tree);
52 FbOff<FB::PolicyOwnNode> serialize_tree(const std::shared_ptr<ldp_xml_parser::TreeNode> &node);
53 FbOff<FB::DecisionItem> serialize_decision(const ldp_xml_parser::DecisionItem &item);
55 template <typename T, typename P>
56 auto serialize_item(const P &item) -> FbOff<typename type_helper<T>::item>;
59 auto serialize_policy(const T &policy) -> FbOff<typename type_helper<T>::policy>;
62 auto serialize_policy(const std::vector<FbOff<typename type_helper<T>::item>> items)
63 -> FbOff<typename type_helper<T>::policy>;
65 template <typename T, typename P>
66 auto serialize_pair(const long int id, const P policy)
67 -> FbOff<typename type_helper<T>::pair>;
69 template <typename TP>
70 auto serialize_set() -> FbOff<typename type_helper<TP>::set>;
72 template <typename TP, typename TFP>
73 auto serialize_set(FbOff<TFP> context_default,
74 FbOff<TFP> context_mandatory)
75 -> FbOff<typename type_helper<TP>::set>;
77 SerializerFlatbuffers() : m_db(nullptr) {}
78 const uint8_t *serialize(const ldp_xml::StorageBackendXML &db, size_t &size);
79 friend class SerializerTests;