/src/gpowerd/convert_proto.cc
Line | Count | Source |
1 | | #include "convert_proto.h" |
2 | | |
3 | | #include "google/protobuf/timestamp.pb.h" |
4 | | #include "daemon_context.h" |
5 | | #include "action.pb.h" |
6 | | #include "safepower_agent.pb.h" |
7 | | #include "absl/status/status.h" |
8 | | #include "absl/time/time.h" |
9 | | |
10 | | namespace safepower_agent { |
11 | 23.1k | absl::Time ConvertTime(const google::protobuf::Timestamp& timestamp) { |
12 | 23.1k | return absl::FromUnixSeconds(timestamp.seconds()) + |
13 | 23.1k | absl::Nanoseconds(timestamp.nanos()); |
14 | 23.1k | } |
15 | | |
16 | 0 | void SetTimestamp(google::protobuf::Timestamp& timestamp, absl::Time time) { |
17 | 0 | auto ts = absl::ToTimespec(time); |
18 | 0 | timestamp.set_seconds(ts.tv_sec); |
19 | 0 | timestamp.set_nanos(ts.tv_nsec); |
20 | 0 | } |
21 | | |
22 | 0 | void SetTimestampToNow(google::protobuf::Timestamp& timestamp) { |
23 | 0 | SetTimestamp(timestamp, DaemonContext::Get().now()); |
24 | 0 | } |
25 | | |
26 | | void SetStatus(safepower_agent_proto::Status& status_proto, |
27 | 0 | const absl::Status& status) { |
28 | 0 | status_proto.set_code(static_cast<int>(status.code())); |
29 | 0 | status_proto.set_message(std::string(status.message())); |
30 | 0 | } |
31 | | |
32 | | |
33 | | } // namespace safepower_agent |