Skip to content

Commit

Permalink
#120: rmb tool display flag names instead of hex value
Browse files Browse the repository at this point in the history
flag values are now resolved.
  • Loading branch information
jrse committed Feb 26, 2018
1 parent 5a79b5a commit 7fe1975
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/librmb/rados-mail-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ std::string RadosMailObject::to_string(const string &padding) {
if (flags.length() > 0) {
uint8_t flags_;
if (RadosUtils::string_to_flags(flags, &flags_)) {
ss << padding << " " << static_cast<char>(RBOX_METADATA_OLDV1_FLAGS) << "(flags): 0x" << std::hex
<< +flags_ << std::endl;
std::string resolved_flags;
RadosUtils::resolve_flags(flags_, &resolved_flags);
// ss << padding << " " << static_cast<char>(RBOX_METADATA_OLDV1_FLAGS) << "(flags): 0x" << std::hex
// << +flags_ << std::endl;
ss << padding << " " << static_cast<char>(RBOX_METADATA_OLDV1_FLAGS) << "(flags): " << resolved_flags
<< std::endl;
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/librmb/rados-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "rados-util.h"
#include <string>
#include <limits.h>
#include <iostream>
#include <sstream>

namespace librmb {
Expand Down Expand Up @@ -101,4 +102,29 @@ int RadosUtils::get_all_keys_and_values(const librados::IoCtx *io_ctx, const std
return io_ctx->omap_get_vals_by_keys(oid, extended_keys, kv_map);
}

void RadosUtils::resolve_flags(const uint8_t &flags, std::string *flat) {
std::stringbuf buf;
std::ostream os(&buf);

if ((flags & 0x01) != 0) {
os << "\\Answered ";
}
if ((flags & 0x02) != 0) {
os << "\\Flagged ";
}
if ((flags & 0x04) != 0) {
os << "\\Deleted ";
}
if ((flags & 0x08) != 0) {
os << "\\Seen ";
}
if ((flags & 0x10) != 0) {
os << "\\Draft ";
}
if ((flags & 0x20) != 0) {
os << "\\Recent ";
}
*flat = buf.str();
}

} // namespace librmb
3 changes: 2 additions & 1 deletion src/librmb/rados-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class RadosUtils {

static int get_all_keys_and_values(const librados::IoCtx *io_ctx, const std::string &oid,
std::map<std::string, librados::bufferlist> *kv_map);
};
static void resolve_flags(const uint8_t &flags, std::string *flat);
};

} // namespace librmb

Expand Down

0 comments on commit 7fe1975

Please sign in to comment.