-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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 _SERIALIZER_HPP
-#define _SERIALIZER_HPP
+#pragma once
-#include <ostream>
-#include <memory>
-#include <string>
+#include "serializer_flatbuffers.hpp"
-#include "include/flatbuffers/flatbuffers.h"
-#include "include/fb_generated.h"
-
-#include "storage_backend_xml.hpp"
-#include "policy_containers.hpp"
-
-namespace ldp_serializer
-{
- enum class SetType : uint8_t {
- OWN,
- SEND,
- RECEIVE,
- ACCESS
- };
-
- template <typename T>
- using FbOff = flatbuffers::Offset<T>;
-
- class Serializer {
- private:
- template <typename T>
- struct type_helper;
-
- const ldp_xml::StorageBackendXML *m_db;
- flatbuffers::FlatBufferBuilder m_builder;
-
- template <typename T>
- auto get_create_set() -> decltype(type_helper<T>::create_set);
- template <typename T>
- auto get_create_policy() -> decltype(type_helper<T>::create_policy);
- template <typename T>
- auto get_create_policy_pair() -> decltype(type_helper<T>::create_policy_pair);
- template <typename T>
- auto get_create_item() -> decltype(type_helper<T>::create_item);
-
- FbOff<FB::PolicyOwn> serialize_tree(const ldp_xml_parser::OwnershipTree &tree);
- FbOff<FB::PolicyOwnNode> serialize_tree(const std::shared_ptr<ldp_xml_parser::TreeNode> &node);
- FbOff<FB::DecisionItem> serialize_decision(const ldp_xml_parser::DecisionItem &item);
-
- template <typename T, typename P>
- auto serialize_item(const P &item) -> FbOff<typename type_helper<T>::item>;
-
- template <typename T>
- auto serialize_policy(const T &policy) -> FbOff<typename type_helper<T>::policy>;
-
- template <typename T>
- auto serialize_policy(const std::vector<FbOff<typename type_helper<T>::item>> items)
- -> FbOff<typename type_helper<T>::policy>;
-
- template <typename T, typename P>
- auto serialize_pair(const long int id, const P policy)
- -> FbOff<typename type_helper<T>::pair>;
-
- template <typename TP>
- auto serialize_set() -> FbOff<typename type_helper<TP>::set>;
-
- template <typename TP, typename TFP>
- auto serialize_set(FbOff<TFP> context_default,
- FbOff<TFP> context_mandatory)
- -> FbOff<typename type_helper<TP>::set>;
- public:
- Serializer() : m_db(nullptr) {}
- const uint8_t *serialize(const ldp_xml::StorageBackendXML &db, size_t &size);
- const uint8_t *serialize(const std::string config_path, size_t &size);
- const uint8_t *serialize(const std::string config_path, std::ostream &output);
- friend class SerializerTests;
- };
+namespace ldp_serializer {
+using Serializer = SerializerFlatbuffers;
}
-
-
-#endif
};
template <>
-struct Serializer::type_helper<PolicyOwn> {
+struct SerializerFlatbuffers::type_helper<PolicyOwn> {
typedef struct FB::OwnSet set;
typedef struct FB::OwnSetBuilder builder;
typedef struct FB::PolicyOwn policy;
};
template <>
-struct Serializer::type_helper<PolicySend> {
+struct SerializerFlatbuffers::type_helper<PolicySend> {
typedef struct FB::SendSet set;
typedef struct FB::SendSetBuilder builder;
typedef struct FB::PolicySend policy;
};
template <>
-struct Serializer::type_helper<PolicyReceive> {
+struct SerializerFlatbuffers::type_helper<PolicyReceive> {
typedef struct FB::ReceiveSet set;
typedef struct FB::ReceiveSetBuilder builder;
typedef struct FB::PolicyReceive policy;
};
template <>
-struct Serializer::type_helper<PolicyAccess> {
+struct SerializerFlatbuffers::type_helper<PolicyAccess> {
typedef struct FB::AccessSet set;
typedef struct FB::AccessSetBuilder builder;
typedef struct FB::PolicyAccess policy;
static constexpr auto create_item = &FB::CreateItemAccess;
};
-const uint8_t* Serializer::serialize(const ldp_xml::StorageBackendXML &db, size_t &size) {
+const uint8_t* SerializerFlatbuffers::serialize(const ldp_xml::StorageBackendXML &db, size_t &size) {
m_db = &db;
auto own_set = serialize_set<PolicyOwn>();
return buf;
}
-const uint8_t* Serializer::serialize(const std::string config_path, size_t &size) {
+const uint8_t* SerializerFlatbuffers::serialize(const std::string config_path, size_t &size) {
tslog::init(tslog::ldp_log_level::DEFAULT);
ldp_xml::StorageBackendXML xmlStorage;
return serialize(xmlStorage, size);
}
-const uint8_t *Serializer::serialize(const std::string config_path, std::ostream &output) {
+const uint8_t *SerializerFlatbuffers::serialize(const std::string config_path, std::ostream &output) {
size_t size = 0;
auto buf = serialize(config_path, size);
}
template <typename T>
-auto Serializer::get_create_set() -> decltype(type_helper<T>::create_set) {
+auto SerializerFlatbuffers::get_create_set() -> decltype(type_helper<T>::create_set) {
return type_helper<T>::create_set;
}
template <typename T>
-auto Serializer::get_create_policy() -> decltype(type_helper<T>::create_policy) {
+auto SerializerFlatbuffers::get_create_policy() -> decltype(type_helper<T>::create_policy) {
return type_helper<T>::create_policy;
}
template <typename T>
-auto Serializer::get_create_policy_pair() -> decltype(type_helper<T>::create_policy_pair) {
+auto SerializerFlatbuffers::get_create_policy_pair() -> decltype(type_helper<T>::create_policy_pair) {
return type_helper<T>::create_policy_pair;
}
template <typename T>
-auto Serializer::get_create_item() -> decltype(type_helper<T>::create_item) {
+auto SerializerFlatbuffers::get_create_item() -> decltype(type_helper<T>::create_item) {
return type_helper<T>::create_item;
}
-FbOff<FB::PolicyOwn> Serializer::serialize_tree(const OwnershipTree &tree) {
+FbOff<FB::PolicyOwn> SerializerFlatbuffers::serialize_tree(const OwnershipTree &tree) {
auto tree_item = serialize_tree(tree.getRoot());
auto policy = FB::CreatePolicyOwn(m_builder, tree_item);
return policy;
}
-FbOff<FB::PolicyOwnNode> Serializer::serialize_tree(const std::shared_ptr<TreeNode> &node) {
+FbOff<FB::PolicyOwnNode> SerializerFlatbuffers::serialize_tree(const std::shared_ptr<TreeNode> &node) {
auto prefix_decision_item = serialize_decision(node->getOwnPrefixDecisionItem());
auto decision_item = serialize_decision(node->getOwnDecisionItem());
return policy_own;
}
-FbOff<FB::DecisionItem> Serializer::serialize_decision(const DecisionItem &item) {
+FbOff<FB::DecisionItem> SerializerFlatbuffers::serialize_decision(const DecisionItem &item) {
return FB::CreateDecisionItem(m_builder,
decisions_map[item.getDecision()],
m_builder.CreateString(item.getPrivilege()));
}
template <>
-auto Serializer::serialize_item<PolicyAccess>(const ItemAccess &item) -> FbOff<FB::ItemAccess> {
+auto SerializerFlatbuffers::serialize_item<PolicyAccess>(const ItemAccess &item) -> FbOff<FB::ItemAccess> {
auto create_item = get_create_item<PolicyAccess>();
return create_item(m_builder,
}
template <typename T, typename P>
-auto Serializer::serialize_item(const P &item) -> FbOff<typename type_helper<T>::item> {
+auto SerializerFlatbuffers::serialize_item(const P &item) -> FbOff<typename type_helper<T>::item> {
auto create_item = get_create_item<T>();
return create_item(m_builder,
serialize_decision(item.getDecision()),
}
template <typename T>
-auto Serializer::serialize_policy(const std::vector<FbOff<typename type_helper<T>::item>> items)
+auto SerializerFlatbuffers::serialize_policy(const std::vector<FbOff<typename type_helper<T>::item>> items)
-> FbOff<typename type_helper<T>::policy> {
auto create_policy = get_create_policy<T>();
return create_policy(m_builder, m_builder.CreateVector(items));
}
template <>
-auto Serializer::serialize_policy(const PolicyOwn &policy)
+auto SerializerFlatbuffers::serialize_policy(const PolicyOwn &policy)
-> FbOff<FB::PolicyOwn> {
return serialize_tree(policy.getTree());
}
template <>
-auto Serializer::serialize_policy(const PolicySend &policy)
+auto SerializerFlatbuffers::serialize_policy(const PolicySend &policy)
-> FbOff<FB::PolicySend> {
std::vector<FbOff<FB::ItemSend>> items;
}
template <typename T>
-auto Serializer::serialize_policy(const T &policy) -> FbOff<typename type_helper<T>::policy> {
+auto SerializerFlatbuffers::serialize_policy(const T &policy) -> FbOff<typename type_helper<T>::policy> {
std::vector<FbOff<typename type_helper<T>::item>> items;
for (const auto &item : policy.getItems()) {
}
template <typename T, typename P>
-auto Serializer::serialize_pair(const long int id, const P policy)
+auto SerializerFlatbuffers::serialize_pair(const long int id, const P policy)
-> FbOff<typename type_helper<T>::pair> {
auto create_policy_pair = get_create_policy_pair<T>();
return create_policy_pair(m_builder, id, serialize_policy(policy));
}
template <typename TP>
-auto Serializer::serialize_set() -> FbOff<typename type_helper<TP>::set> {
+auto SerializerFlatbuffers::serialize_set() -> FbOff<typename type_helper<TP>::set> {
auto context_default = serialize_policy<TP>(m_db->getPolicyContextDefault<TP>());
auto context_mandatory = serialize_policy<TP>(m_db->getPolicyContextMandatory<TP>());
}
template <>
-auto Serializer::serialize_set<PolicyAccess>(FbOff<FB::PolicyAccess> context_default,
+auto SerializerFlatbuffers::serialize_set<PolicyAccess>(FbOff<FB::PolicyAccess> context_default,
FbOff<FB::PolicyAccess> context_mandatory)
-> FbOff<typename type_helper<PolicyAccess>::set>
{
}
template <typename TP, typename TFP>
-auto Serializer::serialize_set(FbOff<TFP> context_default,
+auto SerializerFlatbuffers::serialize_set(FbOff<TFP> context_default,
FbOff<TFP> context_mandatory)
-> FbOff<typename type_helper<TP>::set>
{
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 _SERIALIZER_HPP
+#define _SERIALIZER_HPP
+
+#include <ostream>
+#include <memory>
+#include <string>
+
+#include "include/flatbuffers/flatbuffers.h"
+#include "include/fb_generated.h"
+
+#include "storage_backend_xml.hpp"
+#include "policy_containers.hpp"
+
+namespace ldp_serializer
+{
+ enum class SetType : uint8_t {
+ OWN,
+ SEND,
+ RECEIVE,
+ ACCESS
+ };
+
+ template <typename T>
+ using FbOff = flatbuffers::Offset<T>;
+
+ class SerializerFlatbuffers {
+ private:
+ template <typename T>
+ struct type_helper;
+
+ const ldp_xml::StorageBackendXML *m_db;
+ flatbuffers::FlatBufferBuilder m_builder;
+
+ template <typename T>
+ auto get_create_set() -> decltype(type_helper<T>::create_set);
+ template <typename T>
+ auto get_create_policy() -> decltype(type_helper<T>::create_policy);
+ template <typename T>
+ auto get_create_policy_pair() -> decltype(type_helper<T>::create_policy_pair);
+ template <typename T>
+ auto get_create_item() -> decltype(type_helper<T>::create_item);
+
+ FbOff<FB::PolicyOwn> serialize_tree(const ldp_xml_parser::OwnershipTree &tree);
+ FbOff<FB::PolicyOwnNode> serialize_tree(const std::shared_ptr<ldp_xml_parser::TreeNode> &node);
+ FbOff<FB::DecisionItem> serialize_decision(const ldp_xml_parser::DecisionItem &item);
+
+ template <typename T, typename P>
+ auto serialize_item(const P &item) -> FbOff<typename type_helper<T>::item>;
+
+ template <typename T>
+ auto serialize_policy(const T &policy) -> FbOff<typename type_helper<T>::policy>;
+
+ template <typename T>
+ auto serialize_policy(const std::vector<FbOff<typename type_helper<T>::item>> items)
+ -> FbOff<typename type_helper<T>::policy>;
+
+ template <typename T, typename P>
+ auto serialize_pair(const long int id, const P policy)
+ -> FbOff<typename type_helper<T>::pair>;
+
+ template <typename TP>
+ auto serialize_set() -> FbOff<typename type_helper<TP>::set>;
+
+ template <typename TP, typename TFP>
+ auto serialize_set(FbOff<TFP> context_default,
+ FbOff<TFP> context_mandatory)
+ -> FbOff<typename type_helper<TP>::set>;
+ public:
+ SerializerFlatbuffers() : m_db(nullptr) {}
+ const uint8_t *serialize(const ldp_xml::StorageBackendXML &db, size_t &size);
+ const uint8_t *serialize(const std::string config_path, size_t &size);
+ const uint8_t *serialize(const std::string config_path, std::ostream &output);
+ friend class SerializerTests;
+ };
+}
+
+
+#endif