$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 
24 #include <string> // for string
25 
26 #include <cloe/core.hpp> // for Json
27 #include <cloe/utility/output_serializer.hpp> // for Serializer
28 
29 namespace cloe {
30 namespace utility {
31 
32 enum class MsgPackFileType {
33  MSGPACK_GZIP,
34  MSGPACK_ZIP,
35  MSGPACK,
36 };
37 
38 // clang-format off
39 ENUM_SERIALIZATION(MsgPackFileType, ({
40  {cloe::utility::MsgPackFileType::MSGPACK_GZIP , "msgpack.gz" },
41  {cloe::utility::MsgPackFileType::MSGPACK_ZIP , "msgpack.zip" },
42  {cloe::utility::MsgPackFileType::MSGPACK , "msgpack" },
43 }))
44 // clang-format on
45 
46 template <typename T, typename... TSerializerArgs>
47 class AbstractMsgPackSerializer : public Serializer<TSerializerArgs...> {
48  public:
49  using base = Serializer<TSerializerArgs...>;
50  using Serializer<TSerializerArgs...>::Serializer;
51  virtual ~AbstractMsgPackSerializer() = default;
52  std::string make_default_filename(const std::string& default_filename) override {
53  return default_filename + ".msg";
54  }
55  void start_array() override {}
56  void end_array() override { base::write(Json::to_msgpack(Json(data_))); }
57 
58  protected:
59  std::vector<T> data_;
60 };
61 
62 } // namespace utility
63 } // namespace cloe
Definition: output_serializer_msgpack.hpp:47
Definition: output_serializer.hpp:60
#define ENUM_SERIALIZATION(xType, xMap)
Definition: enum.hpp:51