userver: userver/formats/bson/serialize_duration.hpp Source File
Loading...
Searching...
No Matches
serialize_duration.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/formats/bson/serialize_duration.hpp
4/// @brief Serializers for std::chrono::duration types.
5/// @ingroup userver_universal userver_formats_serialize
6
7#include <chrono>
8
9#include <userver/formats/bson/value_builder.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace formats::serialize {
14
15// Declare Serialize() as static as multiple translation units might declare
16// different implementations of std::chrono::duration<> serializations.
17template <class Rep, class Period>
18static bson::Value Serialize(std::chrono::duration<Rep, Period> duration, To<formats::bson::Value>) {
19 return bson::ValueBuilder(duration.count()).ExtractValue();
20}
21
22} // namespace formats::serialize
23
24USERVER_NAMESPACE_END