1 /**
2 * @file serialization_type.h
3 *
4 * @section LICENSE
5 *
6 * The MIT License
7 *
8 * @copyright Copyright (c) 2017-2021 TileDB, Inc.
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 * THE SOFTWARE.
27 *
28 * @section DESCRIPTION
29 *
30 * This defines the TileDB SerializationType enum that maps to
31 * tiledb_serialization_type_t C-API enum.
32 */
33
34 #ifndef TILEDB_SERIALIZATION_TYPE_H
35 #define TILEDB_SERIALIZATION_TYPE_H
36
37 #include <cassert>
38 #include "tiledb/common/status.h"
39 #include "tiledb/sm/misc/constants.h"
40
41 namespace tiledb {
42 namespace sm {
43
44 /** Defines the query type. */
45 enum class SerializationType : uint8_t {
46 #define TILEDB_SERIALIZATION_TYPE_ENUM(id) id
47 #include "tiledb/sm/c_api/tiledb_enum.h"
48 #undef TILEDB_SERIALIZATION_TYPE_ENUM
49 };
50
51 /** Returns the string representation of the input serialization type. */
serialization_type_str(SerializationType serialization_type)52 inline const std::string& serialization_type_str(
53 SerializationType serialization_type) {
54 switch (serialization_type) {
55 case SerializationType::JSON:
56 return constants::serialization_type_json_str;
57 case SerializationType::CAPNP:
58 return constants::serialization_type_capnp_str;
59 default:
60 return constants::empty_str;
61 }
62 }
63
64 /** Returns the serialization type given a string representation. */
serialization_type_enum(const std::string & serialization_type_str,SerializationType * serialization_type)65 inline Status serialization_type_enum(
66 const std::string& serialization_type_str,
67 SerializationType* serialization_type) {
68 if (serialization_type_str == constants::serialization_type_json_str)
69 *serialization_type = SerializationType::JSON;
70 else if (serialization_type_str == constants::serialization_type_capnp_str)
71 *serialization_type = SerializationType::CAPNP;
72 else {
73 return Status::Error("Invalid SerializationType " + serialization_type_str);
74 }
75 return Status::Ok();
76 }
77
78 } // namespace sm
79 } // namespace tiledb
80
81 #endif // TILEDB_SERIALIZATION_TYPE_H
82