userver: /data/code/userver/libraries/proto-structs/src/proto-structs/io/userver/proto_structs/time_of_day_conv.cpp Source File
Loading...
Searching...
No Matches
time_of_day_conv.cpp
1#include <userver/proto-structs/io/userver/proto_structs/time_of_day_conv.hpp>
2
3#include <google/type/timeofday.pb.h>
4
5#include <userver/proto-structs/exceptions.hpp>
6#include <userver/proto-structs/io/context.hpp>
7#include <userver/utils/impl/internal_tag.hpp>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace proto_structs::io {
12
13TimeOfDay ReadProtoStruct(ReadContext& ctx, To<TimeOfDay>, const ::google::type::TimeOfDay& msg) {
14 try {
15 return TimeOfDay(utils::impl::InternalTag{}, msg.hours(), msg.minutes(), msg.seconds(), msg.nanos());
16 } catch (const ValueError& e) {
17 ctx.AddError(e.what());
18 return TimeOfDay{};
19 }
20}
21
22void WriteProtoStruct(WriteContext&, const TimeOfDay& obj, ::google::type::TimeOfDay& msg) {
23 msg.set_hours(static_cast<std::int32_t>(obj.Hours().count()));
24 msg.set_minutes(static_cast<std::int32_t>(obj.Minutes().count()));
25 msg.set_seconds(static_cast<std::int32_t>(obj.Seconds().count()));
26 msg.set_nanos(static_cast<std::int32_t>(obj.Nanos().count()));
27}
28
29} // namespace proto_structs::io
30
31USERVER_NAMESPACE_END