userver: /data/code/userver/libraries/proto-structs/src/proto-structs/io/userver/proto_structs/time_of_day.cpp Source File
Loading...
Searching...
No Matches
time_of_day.cpp
1#include <userver/proto-structs/io/userver/proto_structs/time_of_day.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
9namespace proto_structs::io {
10
11TimeOfDay ReadProtoStruct(ReadContext& ctx, To<TimeOfDay>, const ::google::type::TimeOfDay& msg) try {
12 return TimeOfDay(utils::impl::InternalTag{}, msg.hours(), msg.minutes(), msg.seconds(), msg.nanos());
13} catch (const ValueError& e) {
14 ctx.AddError(e.what());
15 return TimeOfDay{};
16}
17
18void WriteProtoStruct(WriteContext&, const TimeOfDay& obj, ::google::type::TimeOfDay& msg) {
19 msg.set_hours(static_cast<std::int32_t>(obj.Hours().count()));
20 msg.set_minutes(static_cast<std::int32_t>(obj.Minutes().count()));
21 msg.set_seconds(static_cast<std::int32_t>(obj.Seconds().count()));
22 msg.set_nanos(static_cast<std::int32_t>(obj.Nanos().count()));
23}
24
25} // namespace proto_structs::io