Esempio n. 1
0
DecodeError HPACKDecodeBuffer::decodeLiteral(folly::fbstring& literal) {
  literal.clear();
  if (remainingBytes_ == 0) {
    LOG(ERROR) << "remainingBytes_ == 0";
    return DecodeError::BUFFER_UNDERFLOW;
  }
  auto byte = peek();
  bool huffman = byte & HPACK::LiteralEncoding::HUFFMAN;
  // extract the size
  uint32_t size;
  DecodeError result = decodeInteger(7, size);
  if (result != DecodeError::NONE) {
    LOG(ERROR) << "Could not decode literal size";
    return result;
  }
  if (size > remainingBytes_) {
    LOG(ERROR) << "size > remainingBytes_ decoding literal size="
               << size << " remainingBytes_=" << remainingBytes_;
    return DecodeError::BUFFER_UNDERFLOW;
  }
  if (size > maxLiteralSize_) {
    LOG(ERROR) << "Literal too large, size=" << size;
    return DecodeError::LITERAL_TOO_LARGE;
  }
  const uint8_t* data;
  unique_ptr<IOBuf> tmpbuf;
  // handle the case where the buffer spans multiple buffers
  if (cursor_.length() >= size) {
    data = cursor_.data();
    cursor_.skip(size);
  } else {
    // temporary buffer to pull the chunks together
    tmpbuf = IOBuf::create(size);
    // pull() will move the cursor
    cursor_.pull(tmpbuf->writableData(), size);
    data = tmpbuf->data();
  }
  if (huffman) {
    huffmanTree_.decode(data, size, literal);
  } else {
    literal.append((const char *)data, size);
  }
  remainingBytes_ -= size;
  return DecodeError::NONE;
}
Esempio n. 2
0
void
ZkClient::createEphemeral(
    const folly::fbstring& path,
    const folly::fbstring& data) {
    zhandle_t* zhandle = zHandle_.get();
    CHECK(nullptr != zhandle) << "zhandle is NULL";
    int code = zoo_create(
                   zhandle,
                   path.c_str(),
                   data.data(),
                   data.length(),
                   &ZOO_READ_ACL_UNSAFE,
                   ZOO_EPHEMERAL,
                   nullptr,
                   0
               );
    CHECK(ZOK == code)
            << "zoo_acreate() failed with error: "
            << zooErrorCodeToString(code);
}
Esempio n. 3
0
folly::fbstring
ZkClient::createEphemeralSequence(
    const folly::fbstring& path,
    const folly::fbstring& data) {
    zhandle_t* zhandle = zHandle_.get();
    CHECK(nullptr != zhandle) << "zhandle is NULL";
    folly::fbstring newPath;
    newPath.resize(path.size() * 3);
    int code = zoo_create(
                   zhandle,
                   path.c_str(),
                   data.data(),
                   data.length(),
                   &ZOO_READ_ACL_UNSAFE,
                   ZOO_EPHEMERAL | ZOO_SEQUENCE,
                   (char*) newPath.data(),
                   newPath.size()
               );
    CHECK(ZOK == code)
            << "zoo_acreate() failed with error: "
            << zooErrorCodeToString(code);
    return std::move(newPath);
}
Esempio n. 4
0
void
ZkClient::connect(const folly::fbstring& serverList) {
    zhandle_t* zhandle = zookeeper_init(
                             serverList.c_str(),
                             ZkClient::watcherCallback,
                             ZK_TIMEOUT,
                             nullptr,
                             this,
                             0
                         );
    CHECK(nullptr != zhandle) << "zookeeper_init() failed";
    LOG(INFO) << "zhandle created: " << zhandle;
    zHandle_.reset(zhandle);
}
Esempio n. 5
0
void
ZkClient::subscribeDataChanges(
    const folly::fbstring& path,
    DataChangeCallback dataChangeCallback) {
    {
        toft::Mutex::Locker locker(&dataChangeCallbackMapMutex_);
        dataChangeCallbackMap_[path] = std::move(dataChangeCallback);
    }
    DataChangeCallbackContext* context = new DataChangeCallbackContext();
    context->path = path;
    context->zkClient = this;
    zhandle_t* zhandle = zHandle_.get();
    CHECK(nullptr != zhandle) << "zhandle is NULL";
    int returnCode = zoo_aget(
                         zhandle,
                         path.c_str(),
                         1,
                         ZkClient::dataChangeCallback,
                         context
                     );
    CHECK(ZOK == returnCode)
            << "zoo_aget() failed with error: "
            << zooErrorCodeToString(returnCode);
}
Esempio n. 6
0
void HPACKCodec::onHeader(const folly::fbstring& name,
                          const folly::fbstring& value) {
  assert(streamingCb_ != nullptr);
  decodedSize_.uncompressed += name.size() + value.size() + 2;
  streamingCb_->onHeader(name, value);
}