userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
time_point_conv.cpp
1
#
include
<
userver
/
proto
-
structs
/
io
/
std
/
chrono
/
time_point_conv
.
hpp
>
2
3
#
include
<
google
/
protobuf
/
timestamp
.
pb
.
h
>
4
5
#
include
<
userver
/
proto
-
structs
/
exceptions
.
hpp
>
6
#
include
<
userver
/
proto
-
structs
/
io
/
context
.
hpp
>
7
#
include
<
userver
/
proto
-
structs
/
timestamp
.
hpp
>
8
#
include
<
userver
/
utils
/
impl
/
internal_tag
.
hpp
>
9
10
USERVER_NAMESPACE_BEGIN
11
12
namespace
proto_structs::
io
{
13
14
std::chrono::time_point<std::chrono::system_clock> ReadProtoStruct(
15
ReadContext& ctx,
16
To<std::chrono::time_point<std::chrono::system_clock>>,
17
const
::google::protobuf::Timestamp& msg
18
) {
19
try
{
20
return
Timestamp(utils::impl::InternalTag{}, msg.seconds(), msg.nanos()).ToTimePoint();
21
}
catch
(
const
ValueError& e) {
22
ctx.AddError(e.what());
23
return
std::chrono::time_point<std::chrono::system_clock>{};
24
}
25
}
26
27
void
WriteProtoStruct(
28
WriteContext& ctx,
29
const
std::chrono::time_point<std::chrono::system_clock>& obj,
30
::google::protobuf::Timestamp& msg
31
) {
32
try
{
33
Timestamp ts{obj};
34
msg.set_seconds(ts.Seconds().count());
35
msg.set_nanos(
static_cast
<std::int32_t>(ts.Nanos().count()));
36
}
catch
(
const
ValueError& e) {
37
ctx.AddError(e.what());
38
}
39
}
40
41
}
// namespace proto_structs::io
42
43
USERVER_NAMESPACE_END
proto-structs
src
proto-structs
io
std
chrono
time_point_conv.cpp
Generated on
for userver by
Doxygen
1.17.0