userver: userver/ugrpc/impl/deadline_timepoint.hpp Source File
Loading...
Searching...
No Matches
deadline_timepoint.hpp
1#pragma once
2
3#include <grpcpp/support/time.h>
4
5#include <userver/engine/deadline.hpp>
6
7USERVER_NAMESPACE_BEGIN
8
9namespace ugrpc::impl {
10
11// Converts a engine::Deadline::Duration to a gpr_timespec.
12::gpr_timespec ToGprTimePoint(engine::Deadline::Duration from) noexcept;
13
14// Converts gpr_timespec to a engine::Deadline::Duration
15// returning engine::Deadline::Duration::max() on unreachable deadline.
16engine::Deadline::Duration ExtractDeadlineDuration(::gpr_timespec deadline);
17
18} // namespace ugrpc::impl
19
20USERVER_NAMESPACE_END
21
22template <>
23class grpc::TimePoint<USERVER_NAMESPACE::engine::Deadline> {
24 public:
25 explicit TimePoint(USERVER_NAMESPACE::engine::Deadline time) noexcept
26 : time_(USERVER_NAMESPACE::ugrpc::impl::ToGprTimePoint(time.TimeLeft())) {
27 }
28
29 ::gpr_timespec raw_time() const noexcept { return time_; }
30
31 private:
32 ::gpr_timespec time_;
33};