-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathISerializeProto.h
More file actions
122 lines (99 loc) · 3.99 KB
/
ISerializeProto.h
File metadata and controls
122 lines (99 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* WISE_FBP_Module: ISerializeProto.h
* Copyright (C) 2023 WISE
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <optional>
#include <type_traits>
#include <stdexcept>
#include "FuelConfig.h"
#include "validation_object.h"
#ifndef _MANAGED
#include <google/protobuf/message.h>
#else
namespace google {
namespace protobuf {
class Message;
};
};
#endif
class FUELCOM_API SerializeProtoOptions {
public:
SerializeProtoOptions() : m_verboseOutput(false), m_clearDirty(false), m_zip(false), m_verboseFloat(false), m_fileVersion(-1) { }
public:
inline bool useVerboseOutput() const { return m_verboseOutput; }
void setVerboseOutput(bool value) { m_verboseOutput = value; }
inline bool clearDirty() const { return m_clearDirty; }
void setClearDirty(bool value) { m_clearDirty = value; }
inline bool zipOutput() const { return m_zip; }
void setZipOutput(bool value) { m_zip = value; }
inline bool useVerboseFloats() const { return m_verboseFloat; }
void setVerboseFloat(bool value) { m_verboseFloat = value; }
inline std::int32_t fileVersion() const { return m_fileVersion; }
void setFileVersion(std::int32_t value) { m_fileVersion = value; }
private:
bool m_verboseOutput;
bool m_clearDirty;
bool m_zip;
bool m_verboseFloat;
std::int32_t m_fileVersion;
};
class ISerializationData {
public:
virtual ~ISerializationData() { }
};
/**
* The interface that all classes that will be serialized using
* Google Protocol Buffers must inherit from.
*/
class ISerializeProto {
public:
class FUELCOM_API DeserializeError : public std::logic_error {
protected:
std::string msg_;
public:
explicit DeserializeError(const std::string& message);
explicit DeserializeError(const std::string& message, std::uint32_t hr_);
std::uint32_t hr = 0;
};
virtual std::int32_t serialVersionUid(const SerializeProtoOptions& options) const noexcept = 0;
/**
* Create, then serialize the class to its equivalent protobuf class. Return the protobuf class
*/
virtual google::protobuf::Message* serialize(const SerializeProtoOptions& options) = 0;
/**
* Create, then serialize the class to its equivalent protobuf class.
* @param options Serialization options.
* @param userData Internal user data needed for serialization.
* @returns The protobuf class.
*/
virtual google::protobuf::Message* serialize(const SerializeProtoOptions& options, ISerializationData* /*userData*/) { return serialize(options); }
/**
* Deserialize the class from its equivalent protobuf class.
* Returns the object that was just serialized, which may be itself or an object of a derived class.
*/
virtual ISerializeProto *deserialize(const google::protobuf::Message& proto, std::shared_ptr<validation::validation_object> valid, const std::string& name) = 0;
/**
* Deserialize the class from its equivalent protobuf class.
* @param userData Internal user data needed for serialization.
* @returns The object that was just serialized, which may be itself or an object of a derived class.
*/
virtual ISerializeProto *deserialize(const google::protobuf::Message& proto, std::shared_ptr<validation::validation_object> valid, const std::string& name, ISerializationData* /*userData*/) { return deserialize(proto, valid, name); }
/**
* Returns whether the object needs to be saved, or if it even cares or knows.
*/
virtual std::optional<bool> isdirty(void) const noexcept = 0;
};