$darkmode
output_serializer_msgpack.hpp
1 /*
2  * Copyright 2021 Robert Bosch GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  */
22 #pragma once
23 #ifndef CLOE_UTILITY_OUTPUT_SERIALIZER_MSGPACK_HPP_
24 #define CLOE_UTILITY_OUTPUT_SERIALIZER_MSGPACK_HPP_
25 
26 #include <string> // for string
27 
28 #include <cloe/core.hpp> // for Json
29 #include <cloe/utility/output_serializer.hpp> // for Serializer
30 
31 namespace cloe {
32 namespace utility {
33 
34 enum class MsgPackFileType {
35  MSGPACK_GZIP,
36  MSGPACK_ZIP,
37  MSGPACK,
38 };
39 
40 // clang-format off
41 ENUM_SERIALIZATION(MsgPackFileType, ({
42  {cloe::utility::MsgPackFileType::MSGPACK_GZIP , "msgpack.gz" },
43  {cloe::utility::MsgPackFileType::MSGPACK_ZIP , "msgpack.zip" },
44  {cloe::utility::MsgPackFileType::MSGPACK , "msgpack" },
45 }))
46 // clang-format on
47 
48 template <typename T, typename... TSerializerArgs>
49 class AbstractMsgPackSerializer : public Serializer<TSerializerArgs...> {
50  public:
51  using base = Serializer<TSerializerArgs...>;
52  using Serializer<TSerializerArgs...>::Serializer;
53  virtual ~AbstractMsgPackSerializer() = default;
54  std::string make_default_filename(const std::string& default_filename) override {
55  return default_filename + ".msg";
56  }
57  void start_array() override {}
58  void end_array() override { base::write(Json::to_msgpack(Json(data_))); }
59 
60  protected:
61  std::vector<T> data_;
62 };
63 
64 } // namespace utility
65 } // namespace cloe
66 
67 #endif // CLOE_UTILITY_OUTPUT_SERIALIZER_MSGPACK_HPP_
Definition: coordinator.hpp:36
#define ENUM_SERIALIZATION(xType, xMap)
Definition: enum.hpp:52
Definition: output_serializer_msgpack.hpp:49
Definition: output_serializer.hpp:62