+/*
+ * Field formatters for libfmt.
+ *
+ * Due to a bug in g++ < 7.1, this specialization must be enclosed in the fmt namespace,
+ * see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480.
+ */
+namespace fmt {
+template <>
+struct formatter<lttng::sessiond::trace::field_location> : formatter<std::string> {
+ template <typename FormatCtx>
+ typename FormatCtx::iterator format(
+ const lttng::sessiond::trace::field_location& location, FormatCtx& ctx)
+ {
+ std::string location_str{"["};
+
+ switch (location.root_) {
+ case lttng::sessiond::trace::field_location::root::PACKET_HEADER:
+ location_str += "\"packet-header\"";
+ break;
+ case lttng::sessiond::trace::field_location::root::PACKET_CONTEXT:
+ location_str += "\"packet-context\"";
+ break;
+ case lttng::sessiond::trace::field_location::root::EVENT_RECORD_HEADER:
+ location_str += "\"event-record-header\"";
+ break;
+ case lttng::sessiond::trace::field_location::root::EVENT_RECORD_COMMON_CONTEXT:
+ location_str += "\"event-record-common-context\"";
+ break;
+ case lttng::sessiond::trace::field_location::root::EVENT_RECORD_SPECIFIC_CONTEXT:
+ location_str += "\"event-record-specific-context\"";
+ break;
+ case lttng::sessiond::trace::field_location::root::EVENT_RECORD_PAYLOAD:
+ location_str += "\"event-record-payload\"";
+ break;
+ }
+
+ for (const auto &name : location.elements_) {
+ location_str += ", \"" + name + "\"";
+ }
+
+ location_str += "]";
+ return format_to(ctx.out(), location_str);
+ }
+};
+
+namespace details {
+template <typename MappingIntegerType>
+::std::string format_mapping_range(typename lttng::sessiond::trace::typed_enumeration_type<
+ MappingIntegerType>::mapping::range_t range)
+{
+ if (range.begin == range.end) {
+ return ::fmt::format("[{}]", range.begin);
+ } else {
+ return ::fmt::format("[{}, {}]", range.begin, range.end);
+ }
+}
+} /* namespace details */
+
+template <>
+struct formatter<typename lttng::sessiond::trace::signed_enumeration_type::mapping::range_t>
+ : formatter<std::string> {
+ template <typename FormatCtx>
+ typename FormatCtx::iterator
+ format(typename lttng::sessiond::trace::signed_enumeration_type::mapping::range_t range,
+ FormatCtx& ctx)
+ {
+ return format_to(ctx.out(),
+ details::format_mapping_range<
+ lttng::sessiond::trace::signed_enumeration_type::
+ mapping::range_t::range_integer_t>(
+ range));
+ }
+};
+
+template <>
+struct formatter<typename lttng::sessiond::trace::unsigned_enumeration_type::mapping::range_t>
+ : formatter<std::string> {
+ template <typename FormatCtx>
+ typename FormatCtx::iterator
+ format(typename lttng::sessiond::trace::unsigned_enumeration_type::mapping::range_t range,
+ FormatCtx& ctx)
+ {
+ return format_to(ctx.out(),
+ details::format_mapping_range<
+ lttng::sessiond::trace::unsigned_enumeration_type::
+ mapping::range_t::range_integer_t>(
+ range));
+ }
+};
+
+} /* namespace fmt */
+