Metall v0.30
A persistent memory allocator for data-centric analytics
 
Loading...
Searching...
No Matches
serialize.hpp
Go to the documentation of this file.
1// Copyright 2021 Lawrence Livermore National Security, LLC and other Metall
2// Project Developers. See the top-level COPYRIGHT file for details.
3//
4// SPDX-License-Identifier: (Apache-2.0 OR MIT)
5
6#ifndef METALL_JSON_SERIALIZE_HPP
7#define METALL_JSON_SERIALIZE_HPP
8
9#include <iostream>
10
13
14namespace metall::json {
15
16namespace {
17namespace mc = metall::container;
18namespace bj = boost::json;
19} // namespace
20
21template <typename allocator_type>
22std::string serialize(const value<allocator_type> &input) {
23 return bj::serialize(value_to<bj::value>(input));
24}
25
26template <typename allocator_type>
27std::string serialize(const object<allocator_type> &input) {
28 bj::object object;
29 for (const auto &elem : input) {
30 object[elem.key().data()] = value_to<bj::value>(elem.value());
31 }
32 return bj::serialize(object);
33}
34
35template <typename allocator_type>
36std::string serialize(const array<allocator_type> &input) {
37 bj::array array;
38 for (const auto &elem : input) {
39 array.emplace_back(value_to<bj::value>(elem));
40 }
41 return bj::serialize(array);
42}
43
44template <typename char_type, typename traits, typename allocator_type>
45std::string serialize(
47 return input.data();
48}
49
50template <typename allocator_type>
51std::ostream &operator<<(std::ostream &os, const value<allocator_type> &val) {
52 os << serialize(val);
53 return os;
54}
55
56template <typename allocator_type>
57std::ostream &operator<<(std::ostream &os, const object<allocator_type> &obj) {
58 os << serialize(obj);
59 return os;
60}
61
62template <typename allocator_type>
63std::ostream &operator<<(std::ostream &os, const array<allocator_type> &arr) {
64 os << serialize(arr);
65 return os;
66}
67
68} // namespace metall::json
69
70#endif // METALL_JSON_SERIALIZE_HPP
JSON array. An array is an ordered collection of values.
Definition array.hpp:43
JSON object. An object is a table key and value pairs. The order of key-value pairs depends on the im...
Definition object.hpp:22
JSON value. A container that holds a single bool, int64, uint64, double, JSON string,...
Definition value.hpp:82
Namespace for Metall container.
Namespace for Metall JSON container, which is in an experimental phase.
Definition array.hpp:17
std::ostream & operator<<(std::ostream &os, const value< allocator_type > &val)
Definition serialize.hpp:51
std::string serialize(const value< allocator_type > &input)
Definition serialize.hpp:22
metall::container::basic_string< char_t, traits, allocator_type > basic_string
JSON basic string type.
Definition json_fwd.hpp:44