当前位置: 首页>>代码示例>>C++>>正文


C++ folly::StringPiece类代码示例

本文整理汇总了C++中folly::StringPiece的典型用法代码示例。如果您正苦于以下问题:C++ StringPiece类的具体用法?C++ StringPiece怎么用?C++ StringPiece使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了StringPiece类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getMemcacheKeyHashValue

void McRequest::Keys::update(folly::StringPiece key) {
  keyWithoutRoute = key;
  if (!key.empty()) {
    if (*key.begin() == '/') {
      size_t pos = 1;
      for (int i = 0; i < 2; ++i) {
        pos = key.find('/', pos);
        if (pos == std::string::npos) {
          break;
        }
        ++pos;
      }
      if (pos != std::string::npos) {
        keyWithoutRoute.advance(pos);
        routingPrefix.reset(key.begin(), pos);
      }
    }
  }
  routingKey = keyWithoutRoute;
  size_t pos = keyWithoutRoute.find("|#|");
  if (pos != std::string::npos) {
    routingKey.reset(keyWithoutRoute.begin(), pos);
  }

  routingKeyHash = getMemcacheKeyHashValue(routingKey);
}
开发者ID:191919,项目名称:mcrouter,代码行数:26,代码来源:McRequest.cpp

示例2: serializeMessageHeader

std::string MessagePrinter::serializeMessageHeader(
    folly::StringPiece messageName,
    mc_res_t result,
    const std::string& key) {
  std::string out;

  if (options_.script) {
    out.append(folly::sformat("\"type\": \"{}\"", messageName.data()));
    if (result != mc_res_unknown) {
      out.append(
          folly::sformat(",\n  \"result\": \"{}\"", mc_res_to_string(result)));
    }
    if (!key.empty()) {
      out.append(
          folly::sformat(",\n  \"key\": \"{}\"", folly::backslashify(key)));
    }
  } else {
    out.append(messageName.data());
    if (result != mc_res_unknown) {
      out.push_back(' ');
      out.append(mc_res_to_string(result));
    }
    if (!key.empty()) {
      out.push_back(' ');
      out.append(folly::backslashify(key));
    }
  }

  return out;
}
开发者ID:hurricane1026,项目名称:mcrouter,代码行数:30,代码来源:MessagePrinter.cpp

示例3: update

void Keys::update(folly::StringPiece key) {
  keyWithoutRoute_ = key;
  if (!key.empty()) {
    if (*key.begin() == '/') {
      size_t pos = 1;
      for (int i = 0; i < 2; ++i) {
        pos = key.find('/', pos);
        if (pos == std::string::npos) {
          break;
        }
        ++pos;
      }
      if (pos != std::string::npos) {
        keyWithoutRoute_.advance(pos);
        routingPrefix_.reset(key.begin(), pos);
      }
    }
  }
  routingKey_ = keyWithoutRoute_;
  size_t pos = keyWithoutRoute_.find("|#|");
  if (pos != std::string::npos) {
    routingKey_.reset(keyWithoutRoute_.begin(), pos);
  }
  routingKeyHash_ = 0;
}
开发者ID:Fierralin,项目名称:mcrouter,代码行数:25,代码来源:Keys.cpp

示例4: skipPadding

// Skip over padding until sp.data() - start is a multiple of alignment
void skipPadding(folly::StringPiece& sp, const char* start, size_t alignment) {
  size_t remainder = (sp.data() - start) % alignment;
  if (remainder) {
    FOLLY_SAFE_CHECK(alignment - remainder <= sp.size(), "invalid padding");
    sp.advance(alignment - remainder);
  }
}
开发者ID:peter-fy,项目名称:folly,代码行数:8,代码来源:Dwarf.cpp

示例5: checkLogic

size_t WeightedCh3HashFunc::operator()(folly::StringPiece key) const {
  auto n = weights_.size();
  checkLogic(n && n <= furc_maximum_pool_size(), "Invalid pool size: {}", n);
  size_t salt = 0;
  size_t index = 0;
  std::string saltedKey;
  auto originalKey = key;
  for (size_t i = 0; i < kNumTries; ++i) {
    index = furc_hash(key.data(), key.size(), n);

    /* Use 32-bit hash, but store in 64-bit ints so that
       we don't have to deal with overflows */
    uint64_t p = folly::hash::SpookyHashV2::Hash32(key.data(), key.size(),
                                                   kHashSeed);
    assert(0 <= weights_[index] && weights_[index] <= 1.0);
    uint64_t w = weights_[index] * std::numeric_limits<uint32_t>::max();

    /* Rehash only if p is out of range */
    if (LIKELY(p < w)) {
      return index;
    }

    /* Change the key to rehash */
    auto s = salt++;
    saltedKey = originalKey.str();
    do {
      saltedKey.push_back(char(s % 10) + '0');
      s /= 10;
    } while (s > 0);

    key = saltedKey;
  }

  return index;
}
开发者ID:0xd3adsh3ll,项目名称:mcrouter,代码行数:35,代码来源:WeightedCh3HashFunc.cpp

示例6: loadCertificateFromBufferPEM

void SSLContext::loadCertificateFromBufferPEM(folly::StringPiece cert) {
  if (cert.data() == nullptr) {
    throw std::invalid_argument("loadCertificate: <cert> is nullptr");
  }

  ssl::BioUniquePtr bio(BIO_new(BIO_s_mem()));
  if (bio == nullptr) {
    throw std::runtime_error("BIO_new: " + getErrors());
  }

  int written = BIO_write(bio.get(), cert.data(), cert.size());
  if (written <= 0 || static_cast<unsigned>(written) != cert.size()) {
    throw std::runtime_error("BIO_write: " + getErrors());
  }

  ssl::X509UniquePtr x509(
      PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr));
  if (x509 == nullptr) {
    throw std::runtime_error("PEM_read_bio_X509: " + getErrors());
  }

  if (SSL_CTX_use_certificate(ctx_, x509.get()) == 0) {
    throw std::runtime_error("SSL_CTX_use_certificate: " + getErrors());
  }
}
开发者ID:1Hgm,项目名称:folly,代码行数:25,代码来源:SSLContext.cpp

示例7: loadPrivateKeyFromBufferPEM

void SSLContext::loadPrivateKeyFromBufferPEM(folly::StringPiece pkey) {
  if (pkey.data() == nullptr) {
    throw std::invalid_argument("loadPrivateKey: <pkey> is nullptr");
  }

  ssl::BioUniquePtr bio(BIO_new(BIO_s_mem()));
  if (bio == nullptr) {
    throw std::runtime_error("BIO_new: " + getErrors());
  }

  int written = BIO_write(bio.get(), pkey.data(), pkey.size());
  if (written <= 0 || static_cast<unsigned>(written) != pkey.size()) {
    throw std::runtime_error("BIO_write: " + getErrors());
  }

  ssl::EvpPkeyUniquePtr key(
      PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr));
  if (key == nullptr) {
    throw std::runtime_error("PEM_read_bio_PrivateKey: " + getErrors());
  }

  if (SSL_CTX_use_PrivateKey(ctx_, key.get()) == 0) {
    throw std::runtime_error("SSL_CTX_use_PrivateKey: " + getErrors());
  }
}
开发者ID:1Hgm,项目名称:folly,代码行数:25,代码来源:SSLContext.cpp

示例8: asynclog_delete

/** Adds an asynchronous request to the event log. */
void asynclog_delete(proxy_t* proxy,
                     const ProxyClientCommon& pclient,
                     folly::StringPiece key,
                     folly::StringPiece poolName) {
  dynamic json = {};
  const auto& host = pclient.ap->getHost();
  const auto& port = pclient.ap->getPort();

  if (proxy->opts.use_asynclog_version2) {
    json = dynamic::object;
    json["f"] = proxy->opts.flavor_name;
    json["h"] = folly::sformat("[{}]:{}", host, port);
    json["p"] = poolName.str();
    json["k"] = key.str();
  } else {
    /* ["host", port, escaped_command] */
    json.push_back(host);
    json.push_back(port);
    json.push_back(folly::sformat("delete {}\r\n", key));
  }

  auto fd = asynclog_open(proxy);
  if (!fd) {
    logFailure(proxy->router, memcache::failure::Category::kSystemError,
               "asynclog_open() failed (key {}, pool {})",
               key, poolName);
    return;
  }

  // ["AS1.0", 1289416829.836, "C", ["10.0.0.1", 11302, "delete foo\r\n"]]
  // OR ["AS2.0", 1289416829.836, "C", {"f":"flavor","h":"[10.0.0.1]:11302",
  //                                    "p":"pool_name","k":"foo\r\n"}]
  dynamic jsonOut = {};
  if (proxy->opts.use_asynclog_version2) {
    jsonOut.push_back(ASYNCLOG_MAGIC2);
  } else {
    jsonOut.push_back(ASYNCLOG_MAGIC);
  }

  struct timeval timestamp;
  CHECK(gettimeofday(&timestamp, nullptr) == 0);

  auto timestamp_ms =
    facebook::memcache::to<std::chrono::milliseconds>(timestamp).count();

  jsonOut.push_back(1e-3 * timestamp_ms);
  jsonOut.push_back(std::string("C"));

  jsonOut.push_back(json);

  auto jstr = folly::toJson(jsonOut) + "\n";

  ssize_t size = folly::writeFull(fd->fd(), jstr.data(), jstr.size());
  if (size == -1 || size_t(size) < jstr.size()) {
    logFailure(proxy->router, memcache::failure::Category::kSystemError,
               "Error fully writing asynclog request (key {}, pool {})",
               key, poolName);
  }
}
开发者ID:MahaKoala,项目名称:mcrouter,代码行数:60,代码来源:async.cpp

示例9: read

typename std::enable_if<std::is_pod<T>::value, T>::type
read(folly::StringPiece& sp) {
  FOLLY_SAFE_CHECK(sp.size() >= sizeof(T), "underflow");
  T x;
  memcpy(&x, sp.data(), sizeof(T));
  sp.advance(sizeof(T));
  return x;
}
开发者ID:peter-fy,项目名称:folly,代码行数:8,代码来源:Dwarf.cpp

示例10: readNullTerminated

// Read a null-terminated string
folly::StringPiece readNullTerminated(folly::StringPiece& sp) {
  const char* p = static_cast<const char*>(
      memchr(sp.data(), 0, sp.size()));
  FOLLY_SAFE_CHECK(p, "invalid null-terminated string");
  folly::StringPiece ret(sp.data(), p);
  sp.assign(p + 1, sp.end());
  return ret;
}
开发者ID:peter-fy,项目名称:folly,代码行数:9,代码来源:Dwarf.cpp

示例11: operator

 void operator ()(
   T const &,
   T const &,
   folly::StringPiece path,
   folly::StringPiece
 ) const {
   out_.emplace_back(path.data(), path.size());
 }
开发者ID:ConfusedReality,项目名称:pkg_serialization_fbthrift,代码行数:8,代码来源:fatal_debug_test.cpp

示例12: exists

bool HTTPHeaders::exists(folly::StringPiece name) const {
  const HTTPHeaderCode code = HTTPCommonHeaders::hash(name.data(),
                                                      name.size());
  if (code != HTTP_HEADER_OTHER) {
    return exists(code);
  } else {
    ITERATE_OVER_STRINGS(name, { return true; });
    return false;
  }
开发者ID:1514louluo,项目名称:proxygen,代码行数:9,代码来源:HTTPHeaders.cpp

示例13: TEST

TEST(FixedStringConversionTest, ConversionToFollyRange) {
  // The following declaraction is static for compilers that haven't implemented
  // the resolution of:
  // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1454
  static constexpr folly::FixedString<16> tmp{"This is a string"};
  constexpr folly::StringPiece piece = tmp;
  static_assert(tmp.begin() == piece.begin(), "");
  static_assert(tmp.end() == piece.end(), "");
}
开发者ID:Orvid,项目名称:folly,代码行数:9,代码来源:FixedStringTest.cpp

示例14: initThread

void SwSwitch::initThread(folly::StringPiece name) {
  // We need a null-terminated string to pass to folly::setThreadName().
  // The pthread name can be at most 15 bytes long, so truncate it if necessary
  // when creating the string.
  size_t pthreadLength = std::min(name.size(), (size_t)15);
  char pthreadName[pthreadLength + 1];
  memcpy(pthreadName, name.begin(), pthreadLength);
  pthreadName[pthreadLength] = '\0';
  folly::setThreadName(pthreadName);
}
开发者ID:opennetworklinux,项目名称:fboss,代码行数:10,代码来源:SwSwitch.cpp

示例15: validateScheme

// Helper function to check if URL has valid scheme.
// http_parser only support full form scheme with double slash,
// and the scheme must be all alphabetic charecter.
static bool validateScheme(folly::StringPiece url) {
  auto schemeEnd = url.find("://");
  if (schemeEnd == std::string::npos || schemeEnd == 0) {
    return false;
  }

  auto scheme = url.subpiece(0, schemeEnd);
  return std::all_of(scheme.begin(), scheme.end(), [](auto _) {
      return std::isalpha(_);
  });
}
开发者ID:facebook,项目名称:proxygen,代码行数:14,代码来源:ParseURL.cpp


注:本文中的folly::StringPiece类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。