]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/hobject_fmt.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
6 * \file fmtlib formatters for some hobject.h classes
8 #include <fmt/format.h>
10 #include "common/hobject.h"
11 #include "include/types_fmt.h"
12 #include "msg/msg_fmt.h"
15 static inline void append_out_escaped(const std::string
& in
, std::string
* out
)
17 for (auto i
= in
.cbegin(); i
!= in
.cend(); ++i
) {
18 if (*i
== '%' || *i
== ':' || *i
== '/' || *i
< 32 || *i
>= 127) {
20 snprintf(buf
, sizeof(buf
), "%%%02x", (int)(unsigned char)*i
);
28 template <> struct fmt::formatter
<hobject_t
> {
30 constexpr auto parse(format_parse_context
& ctx
) { return ctx
.begin(); }
32 template <typename FormatContext
> auto format(const hobject_t
& ho
, FormatContext
& ctx
)
34 if (ho
== hobject_t
{}) {
35 return fmt::format_to(ctx
.out(), "MIN");
39 return fmt::format_to(ctx
.out(), "MAX");
43 append_out_escaped(ho
.nspace
, &v
);
45 append_out_escaped(ho
.get_key(), &v
);
47 append_out_escaped(ho
.oid
.name
, &v
);
49 return fmt::format_to(ctx
.out(), "{}:{:08x}:{}:{}", static_cast<uint64_t>(ho
.pool
),
50 ho
.get_bitwise_key_u32(), v
, ho
.snap
);