blob: ef3e3dfefe973bcd822983d5c00483425a9539f7 [file] [log] [blame]
#include "convert_proto.h"
#include "google/protobuf/timestamp.pb.h"
#include "daemon_context.h"
#include "safepower_agent.pb.h"
#include "absl/status/status.h"
#include "absl/time/time.h"
namespace safepower_agent {
absl::Time ConvertTime(const google::protobuf::Timestamp& timestamp) {
return absl::FromUnixSeconds(timestamp.seconds()) +
absl::Nanoseconds(timestamp.nanos());
}
void SetTimestamp(google::protobuf::Timestamp& timestamp, absl::Time time) {
auto ts = absl::ToTimespec(time);
timestamp.set_seconds(ts.tv_sec);
timestamp.set_nanos(ts.tv_nsec);
}
void SetTimestampToNow(google::protobuf::Timestamp& timestamp) {
SetTimestamp(timestamp, DaemonContext::Get().now());
}
void SetStatus(safepower_agent_proto::Status& status_proto,
const absl::Status& status) {
status_proto.set_code(static_cast<int>(status.code()));
status_proto.set_message(status.message());
}
} // namespace safepower_agent