Libraries/ConfigDB/src/include/ConfigDB/Json/Format.h
Go to the documentation of this file.
1 
20 #pragma once
21 
22 #include "../Format.h"
23 
24 namespace ConfigDB::Json
25 {
29 class Format : public ConfigDB::Format
30 {
31 public:
32  DEFINE_FSTR_LOCAL(fileExtension, ".json")
33 
34  std::unique_ptr<ExportStream> createExportStream(Database& db) const override;
35  std::unique_ptr<ExportStream> createExportStream(StoreRef store, const Object& object) const override;
36  size_t exportToStream(const Object& object, Print& output) const override;
37  size_t exportToStream(Database& database, Print& output) const override;
38  std::unique_ptr<ImportStream> createImportStream(Database& db) const override;
39  std::unique_ptr<ImportStream> createImportStream(StoreUpdateRef& store, Object& object) const override;
40  Status importFromStream(Object& object, Stream& source) const override;
41  Status importFromStream(Database& database, Stream& source) const override;
42 
43  String getFileExtension() const override
44  {
45  return fileExtension;
46  }
47 
48  MimeType getMimeType() const override
49  {
50  return MimeType::JSON;
51  }
52 
53  void setPretty(bool pretty)
54  {
55  this->pretty = pretty;
56  }
57 
58 private:
59  bool pretty{false};
60 };
61 
62 extern Format format;
63 
64 } // namespace ConfigDB::Json
Definition: Database.h:30
Definition: Libraries/ConfigDB/src/include/ConfigDB/Format.h:39
Abstract base class wrapping support for a specific storage format, such as JSON.
Definition: Libraries/ConfigDB/src/include/ConfigDB/Format.h:48
Definition: Libraries/ConfigDB/src/include/ConfigDB/Format.h:33
MimeType getMimeType() const override
Get the MIME type for this reader format.
Definition: Libraries/ConfigDB/src/include/ConfigDB/Json/Format.h:48
String getFileExtension() const override
Get the standard file extension for the reader implementation.
Definition: Libraries/ConfigDB/src/include/ConfigDB/Json/Format.h:43
std::unique_ptr< ExportStream > createExportStream(Database &db) const override
Create a stream to serialize the entire database This is used for streaming asychronously to a web cl...
size_t exportToStream(const Object &object, Print &output) const override
Print object.
std::unique_ptr< ImportStream > createImportStream(Database &db) const override
Create a stream for de-serialising (writing) into the database Used when updating a database from a r...
void setPretty(bool pretty)
Definition: Libraries/ConfigDB/src/include/ConfigDB/Json/Format.h:53
Status importFromStream(Object &object, Stream &source) const override
De-serialise content from stream into object (RAM)
An object can contain other objects, properties and arrays.
Definition: Libraries/ConfigDB/src/include/ConfigDB/Object.h:37
Definition: StoreRef.h:29
Definition: StoreRef.h:46
Provides formatted output to stream.
Definition: Print.h:37
Base Stream class.
Definition: Wiring/Stream.h:33
The String class.
Definition: WString.h:133
#define DEFINE_FSTR_LOCAL(name, str)
Like DEFINE_FSTR except reference is declared static constexpr.
Definition: String.hpp:84
MimeType
Definition: WebConstants.h:53
Definition: Libraries/ConfigDB/src/include/ConfigDB/Json/Format.h:25
Definition: Formatter.h:20
Definition: Status.h:54