Safir SDK Core
Loading...
Searching...
No Matches
Serialization.h
Go to the documentation of this file.
1/******************************************************************************
2*
3* Copyright Saab AB, 2004-2015 (http://safirsdkcore.com)
4*
5* Created by: Joel Ottosson / joot
6*
7*******************************************************************************
8*
9* This file is part of Safir SDK Core.
10*
11* Safir SDK Core is free software: you can redistribute it and/or modify
12* it under the terms of version 3 of the GNU General Public License as
13* published by the Free Software Foundation.
14*
15* Safir SDK Core is distributed in the hope that it will be useful,
16* but WITHOUT ANY WARRANTY; without even the implied warranty of
17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18* GNU General Public License for more Internals.
19*
20* You should have received a copy of the GNU General Public License
21* along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22*
23******************************************************************************/
24#ifndef __DOTS_INTERNAL_SERIALIZATION_H__
25#define __DOTS_INTERNAL_SERIALIZATION_H__
26
27#include <string>
28#include <vector>
29#include <sstream>
31#include <Safir/Dob/Typesystem/ToolSupport/Internal/BasicTypeOperations.h>
32#include <Safir/Dob/Typesystem/ToolSupport/Internal/BlobToXmlSerializer.h>
33#include <Safir/Dob/Typesystem/ToolSupport/Internal/BlobToJsonSerializer.h>
34#include <Safir/Dob/Typesystem/ToolSupport/Internal/XmlToBlobSerializer.h>
35#include <Safir/Dob/Typesystem/ToolSupport/Internal/JsonToBlobSerializer.h>
36#include <Safir/Dob/Typesystem/ToolSupport/Internal/RepositoryToStringHelper.h>
37
38namespace Safir
39{
40namespace Dob
41{
42namespace Typesystem
43{
44namespace ToolSupport
45{
46 class TypeRepository;
47
56 inline void BinaryToBase64(const char* binary, size_t size, std::ostringstream& base64)
57 {
58 std::string bin(binary, size); //Improvement: fix implementation to accept 'const char*' and avoid this copying
59 base64<<Internal::SerializationUtils::ToBase64(bin,false);
60 }
61
69 inline void Base64ToBinary(const std::string& base64Str, std::vector<char>& binary)
70 {
71 std::string bin;
72 Internal::SerializationUtils::FromBase64(base64Str, bin); //Improvement: fix implementation to accept vector and avoid this copying
73 binary.insert(binary.begin(), bin.begin(), bin.end());
74 }
75
84 template <class RepositoryT>
85 void BinaryToXml(const RepositoryT* repository, const char* blob, std::ostringstream& xml)
86 {
87 (Internal::BlobToXmlSerializer<RepositoryT>(repository))(blob, xml);
88 }
89
98 template <class RepositoryT>
99 void XmlToBinary(const RepositoryT* repository, const char* xml, std::vector<char>& binary)
100 {
101 (Internal::XmlToBlobSerializer<RepositoryT>(repository))(xml, binary);
102 }
103
112 template <class RepositoryT>
113 void BinaryToJson(const RepositoryT* repository, const char* blob, std::ostringstream& json)
114 {
115 (Internal::BlobToJsonSerializer<RepositoryT>(repository))(blob, json);
116 }
117
126 template <class RepositoryT>
127 void JsonToBinary(const RepositoryT* repository, const char* json, std::vector<char>& binary)
128 {
129 (Internal::JsonToBlobSerializer<RepositoryT>(repository))(json, binary);
130 }
131
145 template <class RepositoryT>
146 void RepositoryToString(const RepositoryT* repository, bool includeCreateRoutines, std::ostream &os)
147 {
148 (Internal::ToStringHelper<RepositoryT>(repository, includeCreateRoutines)).RepositoryToString(os);
149 }
150
158 template <class RepositoryT>
159 void TypeToString(const RepositoryT* repository, DotsC_TypeId typeId, std::ostream &os)
160 {
161 (Internal::ToStringHelper<RepositoryT>(repository, false)).TypeInfoToString(typeId, os);
162 }
163}
164}
165}
166} //end namespace Safir::Dob::Typesystem::ToolSupport
167
168#endif
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
This namespace contains all functionality of the DOB (Components DOSE and DOTS).
Definition Connection.h:38
This namespace contains the DOB Typesystem functionality and definitions.
Definition ArrayContainer.h:37
Definition BlobReader.h:41
void Base64ToBinary(const std::string &base64Str, std::vector< char > &binary)
Decodes base64 data into binary data.
Definition Serialization.h:69
void RepositoryToString(const RepositoryT *repository, bool includeCreateRoutines, std::ostream &os)
Writes a complete text description of a type repository and all of its content.
Definition Serialization.h:146
void BinaryToJson(const RepositoryT *repository, const char *blob, std::ostringstream &json)
Serializes binary representation of an object to json.
Definition Serialization.h:113
void BinaryToBase64(const char *binary, size_t size, std::ostringstream &base64)
Encodes binary data to base64.
Definition Serialization.h:56
void XmlToBinary(const RepositoryT *repository, const char *xml, std::vector< char > &binary)
Converts a xml representation of an object to binary form.
Definition Serialization.h:99
void BinaryToXml(const RepositoryT *repository, const char *blob, std::ostringstream &xml)
Serializes binary representation of an object to xml.
Definition Serialization.h:85
void TypeToString(const RepositoryT *repository, DotsC_TypeId typeId, std::ostream &os)
Writes a complete text description of a type.
Definition Serialization.h:159
void JsonToBinary(const RepositoryT *repository, const char *json, std::vector< char > &binary)
Converts a json representation of an object to binary form.
Definition Serialization.h:127
The TypeRepository class is the baseclass of any TypeRepository implementation.
Definition TypeRepository.h:737