std::string MessagePrinter::serializeConnectionDetails(
    const folly::SocketAddress& from,
    const folly::SocketAddress& to,
    mc_protocol_t protocol) {
  std::string out;

  if (!from.empty()) {
    if (options_.script) {
      out.append(
          folly::sformat(",\n  \"from\": \"{}\"", describeAddress(from)));
    } else {
      out.append(describeAddress(from));
    }
  }
  if (!options_.script && (!from.empty() || !to.empty())) {
    out.append(" -> ");
  }
  if (!to.empty()) {
    if (options_.script) {
      out.append(folly::sformat(",\n  \"to\": \"{}\"", describeAddress(to)));
    } else {
      out.append(describeAddress(to));
    }
  }
  if ((!from.empty() || !to.empty()) && protocol != mc_unknown_protocol) {
    if (options_.script) {
      out.append(folly::sformat(
          ",\n  \"protocol\": \"{}\"", mc_protocol_to_string(protocol)));
    } else {
      out.append(folly::sformat(" ({})", mc_protocol_to_string(protocol)));
    }
  }

  return out;
}
std::string MessagePrinter::serializeConnectionDetails(
    const folly::SocketAddress& from,
    const folly::SocketAddress& to,
    mc_protocol_t protocol) {
  std::string out;

  if (!from.empty()) {
    out.append(from.describe());
  }
  if (!from.empty() || !to.empty()) {
    out.append(" -> ");
  }
  if (!to.empty()) {
    out.append(to.describe());
  }
  if ((!from.empty() || !to.empty()) && protocol != mc_unknown_protocol) {
    out.append(folly::sformat(" ({})", mc_protocol_to_string(protocol)));
  }

  return out;
}