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