Molassembler  1.2.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Serialization.h
Go to the documentation of this file.
1 
8 #ifndef INCLUDE_MOLASSEMBLER_SERIALIZATION_H
9 #define INCLUDE_MOLASSEMBLER_SERIALIZATION_H
10 
11 #include <vector>
12 #include <string>
13 #include <memory>
14 
15 #include "Molassembler/Export.h"
16 
17 namespace Scine {
18 namespace Molassembler {
19 
20 // Forward-declarations
21 class Molecule;
22 
77 class MASM_EXPORT JsonSerialization {
78 public:
82  using BinaryType = std::vector<std::uint8_t>;
83 
85  enum class BinaryFormat {
86  CBOR,
87  BSON,
88  MsgPack,
89  UBJSON
90  };
92 
95  static std::string base64Encode(const BinaryType& binary);
96  static BinaryType base64Decode(const std::string& base64String);
101  static bool base64EqualMolecules(const std::string& stringA, const std::string& stringB,
102  BinaryFormat binaryFormat = BinaryFormat::CBOR);
110  static bool equalDecisionLists(const std::string& listStringA, const std::string& listStringB);
112 
115  JsonSerialization(JsonSerialization&& other) noexcept;
116  JsonSerialization& operator = (JsonSerialization&& other) noexcept;
117  JsonSerialization(const JsonSerialization& other);
118  JsonSerialization& operator = (const JsonSerialization& other);
121 
124  JsonSerialization() = delete;
126  explicit JsonSerialization(const std::string& jsonString);
128  explicit JsonSerialization(const Molecule& molecule);
130  JsonSerialization(const BinaryType& binary, BinaryFormat format);
132 
136  operator std::string() const;
138  operator Molecule() const;
140  BinaryType toBinary(BinaryFormat format) const;
142 
145 
163  JsonSerialization& standardize();
165 
166 private:
167  struct Impl;
168  std::unique_ptr<Impl> pImpl_;
169  static std::vector<std::tuple<int, int, int, int> > unpackDecisionListString(const std::string& listString);
170  static std::tuple<int, int, int, int> canonicalizeDecisionListElement(const std::tuple<int, int, int, int>& decisionListElement);
171  static bool equalVersions(const std::vector<unsigned> versionA, const std::vector<unsigned> versionB);
172  static std::vector<std::string> splitBase64StringIntoMoleculeStrings(std::string base64String);
173 };
174 
175 } // namespace Molassembler
176 } // namespace Scine
177 
178 #endif
Models a molecule as a graph (connectivity of atoms) and a list of stereopermutators.
Definition: Molecule.h:77
BinaryFormat
Binary formats that JSON can be encoded into and decoded from.
Definition: Serialization.h:85
Class representing a compact JSON serialization of a molecule.
Definition: Serialization.h:77
std::vector< std::uint8_t > BinaryType
Type used to represent binary JSON formats.
Definition: Serialization.h:82