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
38//There is a bug in some oldish versions of doxygen that causes spurious warnings to be issued.
39//This renaming stops doxygen from thinking that Base64ToBinary in Typesystem::Utilities and the
40//one in this file are the same function. Which of course they're not...
41//This thing and related cmakery can probably be removed when we drop support for Ubuntu 20.04.
42#ifdef DOXYGEN_BUG_WORKAROUND
43#define Base64ToBinary Base64ToBinary_
44#endif
45
46namespace Safir
47{
48namespace Dob
49{
50namespace Typesystem
51{
52namespace ToolSupport
53{
54 class TypeRepository;
55
64 inline void BinaryToBase64(const char* binary, size_t size, std::ostringstream& base64)
65 {
66 std::string bin(binary, size); //Improvement: fix implementation to accept 'const char*' and avoid this copying
67 base64<<Internal::SerializationUtils::ToBase64(bin,false);
68 }
69
77 inline void Base64ToBinary(const std::string& base64Str, std::vector<char>& binary)
78 {
79 std::string bin;
80 Internal::SerializationUtils::FromBase64(base64Str, bin); //Improvement: fix implementation to accept vector and avoid this copying
81 binary.insert(binary.begin(), bin.begin(), bin.end());
82 }
83
92 template <class RepositoryT>
93 void BinaryToXml(const RepositoryT* repository, const char* blob, std::ostringstream& xml)
94 {
95 (Internal::BlobToXmlSerializer<RepositoryT>(repository))(blob, xml);
96 }
97
106 template <class RepositoryT>
107 void XmlToBinary(const RepositoryT* repository, const char* xml, std::vector<char>& binary)
108 {
109 (Internal::XmlToBlobSerializer<RepositoryT>(repository))(xml, binary);
110 }
111
120 template <class RepositoryT>
121 void BinaryToJson(const RepositoryT* repository, const char* blob, std::ostringstream& json)
122 {
123 (Internal::BlobToJsonSerializer<RepositoryT>(repository))(blob, json);
124 }
125
134 template <class RepositoryT>
135 void JsonToBinary(const RepositoryT* repository, const char* json, std::vector<char>& binary)
136 {
137 (Internal::JsonToBlobSerializer<RepositoryT>(repository))(json, binary);
138 }
139
153 template <class RepositoryT>
154 void RepositoryToString(const RepositoryT* repository, bool includeCreateRoutines, std::ostream &os)
155 {
156 (Internal::ToStringHelper<RepositoryT>(repository, includeCreateRoutines)).RepositoryToString(os);
157 }
158
166 template <class RepositoryT>
167 void TypeToString(const RepositoryT* repository, DotsC_TypeId typeId, std::ostream &os)
168 {
169 (Internal::ToStringHelper<RepositoryT>(repository, false)).TypeInfoToString(typeId, os);
170 }
171}
172}
173}
174} //end namespace Safir::Dob::Typesystem::ToolSupport
175
176#ifdef DOXYGEN_BUG_WORKAROUND
177#undefef Base64ToBinary
178#endif
179
180#endif
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
void Base64ToBinary(const std::string &base64Str, std::vector< char > &binary)
Decodes base64 data into binary data.
Definition Serialization.h:77
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:154
void BinaryToJson(const RepositoryT *repository, const char *blob, std::ostringstream &json)
Serializes binary representation of an object to json.
Definition Serialization.h:121
void BinaryToBase64(const char *binary, size_t size, std::ostringstream &base64)
Encodes binary data to base64.
Definition Serialization.h:64
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:107
void BinaryToXml(const RepositoryT *repository, const char *blob, std::ostringstream &xml)
Serializes binary representation of an object to xml.
Definition Serialization.h:93
void TypeToString(const RepositoryT *repository, DotsC_TypeId typeId, std::ostream &os)
Writes a complete text description of a type.
Definition Serialization.h:167
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:135