File: Schema.hpp

package info (click to toggle)
reflect-cpp 0.21.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,128 kB
  • sloc: cpp: 50,336; python: 139; makefile: 30; sh: 3
file content (43 lines) | stat: -rw-r--r-- 984 bytes parent folder | download | duplicates (2)
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
#ifndef RFL_AVRO_SCHEMA_HPP_
#define RFL_AVRO_SCHEMA_HPP_

#include <type_traits>

#include "../Ref.hpp"
#include "SchemaImpl.hpp"

namespace rfl::avro {

template <class T>
class Schema {
 public:
  using Type = std::remove_cvref_t<T>;

  Schema(const std::string& _json_str)
      : impl_(Ref<SchemaImpl>::make(_json_str)) {}

  static Result<Schema<T>> from_json(const std::string& _json_str) noexcept {
    try {
      return Schema<T>(_json_str);
    } catch (std::exception& e) {
      return error(e.what());
    }
  }

  /// The JSON string used to create this schema.
  const std::string& json_str() const { return impl_->json_str(); }

  /// The JSON string used to create this schema.
  const std::string& str() const { return impl_->json_str(); }

  /// The interface used to create new values.
  avro_value_iface_t* iface() const { return impl_->iface(); };

 private:
  /// We are using the "pimpl"-pattern
  Ref<SchemaImpl> impl_;
};

}  // namespace rfl::avro

#endif