userver: /data/code/userver/libraries/proto-structs/src/proto-structs/io/userver/proto_structs/date.cpp Source File
Loading...
Searching...
No Matches
date.cpp
1#include <userver/proto-structs/io/userver/proto_structs/date.hpp>
2
3#include <google/type/date.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
11Date ReadProtoStruct(ReadContext& ctx, To<Date>, const ::google::type::Date& msg) try {
12 return Date(utils::impl::InternalTag{}, msg.year(), msg.month(), msg.day());
13} catch (const ValueError& e) {
14 ctx.AddError(e.what());
15 return Date{};
16}
17
18void WriteProtoStruct(WriteContext&, const Date& obj, ::google::type::Date& msg) {
19 msg.set_year(obj.YearNum());
20 msg.set_month(obj.MonthNum());
21 msg.set_day(obj.DayNum());
22}
23
24} // namespace proto_structs::io