8 struct tm time_struct {};
10 gmtime_r(&raw_time, &time_struct);
12 strftime(formatted, 22,
"%Y-%m-%dT%H:%M:%SZ", &time_struct);
17 if (rfc3339.length() != 20 || rfc3339[19] !=
'Z') {
23 bool TimeStamp::IsValid()
const {
return time_.length() != 0; }
25 bool TimeStamp::IsExpiredAt(
const TimeStamp &now)
const {
35 bool TimeStamp::operator<(
const TimeStamp &other)
const {
return IsValid() && other.IsValid() && time_ < other.time_; }
37 bool TimeStamp::operator>(
const TimeStamp &other)
const {
return (other < *
this); }
39 std::ostream &operator<<(std::ostream &os,
const TimeStamp &t) {
45 Json::Value Package::toJson() {
48 json[
"version"] = version;
52 Package Package::fromJson(
const std::string &json_str) {
55 reader.parse(json_str, json);
57 package.name = json[
"name"].asString();
58 package.version = json[
"version"].asString();
62 const std::map<data::ResultCode::Numeric, const char *> data::ResultCode::string_repr{
63 {ResultCode::Numeric::kOk,
"OK"},
64 {ResultCode::Numeric::kAlreadyProcessed,
"ALREADY_PROCESSED"},
65 {ResultCode::Numeric::kValidationFailed,
"VALIDATION_FAILED"},
66 {ResultCode::Numeric::kInstallFailed,
"INSTALL_FAILED"},
67 {ResultCode::Numeric::kInternalError,
"INTERNAL_ERROR"},
68 {ResultCode::Numeric::kGeneralError,
"GENERAL_ERROR"},
69 {ResultCode::Numeric::kNeedCompletion,
"NEED_COMPLETION"},
70 {ResultCode::Numeric::kCustomError,
"CUSTOM_ERROR"},
71 {ResultCode::Numeric::kUnknown,
"UNKNOWN"},
74 std::string data::ResultCode::toRepr()
const {
75 std::string s = toString();
77 return s +
":" + std::to_string(static_cast<int>(num_code));
80 ResultCode data::ResultCode::fromRepr(
const std::string &repr) {
81 size_t n = repr.find(
':');
82 std::string s = repr.substr(0, n);
84 if (n >= repr.size() - 1) {
88 int num = std::stoi(repr.substr(n + 1));
90 return ResultCode(static_cast<Numeric>(num), s);
93 Json::Value InstallationResult::toJson()
const {
95 json[
"success"] = success;
96 json[
"code"] = result_code.toString();
97 json[
"description"] = description;
101 std::ostream &operator<<(std::ostream &os,
const ResultCode &result_code) {
102 os << result_code.toRepr();
TimeStamp()
An invalid TimeStamp.