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,
19 To<formats::bson::Value>) {
20 return bson::ValueBuilder(duration.count()).ExtractValue();
21}
22
23} // namespace formats::serialize
24
25USERVER_NAMESPACE_END