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