本文整理汇总了C++中span::data方法的典型用法代码示例。如果您正苦于以下问题:C++ span::data方法的具体用法?C++ span::data怎么用?C++ span::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类span
的用法示例。
在下文中一共展示了span::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
explicit
enumerated_value_range(span<const T> v)
noexcept
: _begin(v.data())
, _end(v.data()+v.size())
{
assert(_begin <= _end);
}
示例2: random_bytes
void random_bytes(span<char> buffer)
{
#if TORRENT_USE_CRYPTOAPI
HCRYPTPROV prov;
if (!CryptAcquireContext(&prov, NULL, NULL
, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
{
#ifndef BOOST_NO_EXCEPTIONS
throw system_error(error_code(GetLastError(), system_category()));
#else
std::terminate();
#endif
}
if (!CryptGenRandom(prov, int(buffer.size())
, reinterpret_cast<BYTE*>(buffer.data())))
{
CryptReleaseContext(prov, 0);
#ifndef BOOST_NO_EXCEPTIONS
throw system_error(error_code(GetLastError(), system_category()));
#else
std::terminate();
#endif
}
CryptReleaseContext(prov, 0);
#elif defined TORRENT_USE_LIBCRYPTO
#ifdef TORRENT_MACOS_DEPRECATED_LIBCRYPTO
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#endif
int r = RAND_bytes(reinterpret_cast<unsigned char*>(buffer.data())
, int(buffer.size()));
if (r != 1)
{
#ifndef BOOST_NO_EXCEPTIONS
throw system_error(error_code(int(::ERR_get_error()), system_category()));
#else
std::terminate();
#endif
}
#ifdef TORRENT_MACOS_DEPRECATED_LIBCRYPTO
#pragma clang diagnostic pop
#endif
#else
for (auto& b : buffer) b = char(random(0xff));
#endif
}
示例3: SendFrame
bool CommObject::SendFrame(span<const std::uint8_t> frame)
{
if (frame.size() > CommMaxFrameSize)
{
LOGF(LOG_LEVEL_ERROR, "Frame payload is too long. Allowed: %d, Requested: '%d'.", CommMaxFrameSize, frame.size());
return false;
}
uint8_t cmd[ComPrefferedBufferSize];
cmd[0] = TransmitterSendFrame;
memcpy(cmd + 1, frame.data(), frame.size());
uint8_t remainingBufferSize;
const bool status = (this->_low.WriteRead(CommTransmitter, //
span<const uint8_t>(cmd, 1 + frame.size()), //
span<uint8_t>(&remainingBufferSize, 1) //
) == I2CResult::OK);
if (!status)
{
LOG(LOG_LEVEL_ERROR, "[comm] Failed to send frame");
}
if (remainingBufferSize == 0xff)
{
LOG(LOG_LEVEL_ERROR, "[comm] Frame was not accepted by the transmitter.");
}
return status && remainingBufferSize != 0xff;
}
示例4: count_trailing_ones_hw
int count_trailing_ones_hw(span<std::uint32_t const> buf)
{
auto const num = int(buf.size());
std::uint32_t const* ptr = buf.data();
TORRENT_ASSERT(num >= 0);
TORRENT_ASSERT(ptr != nullptr);
for (int i = num - 1; i >= 0; i--)
{
if (ptr[i] == 0xffffffff) continue;
#if TORRENT_HAS_BUILTIN_CTZ
std::uint32_t const v = ~aux::network_to_host(ptr[i]);
return (num - i - 1) * 32 + __builtin_ctz(v);
#elif defined _MSC_VER
std::uint32_t const v = ~aux::network_to_host(ptr[i]);
DWORD pos;
_BitScanForward(&pos, v);
return (num - i - 1) * 32 + pos;
#else
TORRENT_ASSERT_FAIL();
return -1;
#endif
}
return num * 32;
}
示例5: random_bytes
void random_bytes(span<char> buffer)
{
#ifdef TORRENT_BUILD_SIMULATOR
// simulator
for (auto& b : buffer) b = char(random(0xff));
#elif TORRENT_USE_CRYPTOAPI
// windows
aux::crypt_gen_random(buffer);
#elif TORRENT_USE_DEV_RANDOM
// /dev/random
static dev_random dev;
dev.read(buffer);
#elif defined TORRENT_USE_LIBCRYPTO
// openssl
int r = RAND_bytes(reinterpret_cast<unsigned char*>(buffer.data())
, int(buffer.size()));
if (r != 1) aux::throw_ex<system_error>(errors::no_entropy);
#else
// fallback
for (auto& b : buffer) b = char(random(0xff));
#endif
}
示例6: update
void update(span<char const> data)
{
if (CryptHashData(m_hash, reinterpret_cast<BYTE const*>(data.data()), int(data.size()), 0) == false)
{
throw_ex<system_error>(error_code(GetLastError(), system_category()));
}
}
示例7: iterate_every_other_element
void iterate_every_other_element(span<int, dynamic_range> av)
{
// pick every other element
auto length = av.size() / 2;
#if _MSC_VER > 1800
auto bounds = strided_bounds<1>({ length }, { 2 });
#else
auto bounds = strided_bounds<1>(index<1>{ length }, index<1>{ 2 });
#endif
strided_span<int, 1> strided(&av.data()[1], av.size() - 1, bounds);
CHECK(strided.size() == length);
CHECK(strided.bounds().index_bounds()[0] == length);
for (auto i = 0; i < strided.size(); ++i)
{
CHECK(strided[i] == av[2 * i + 1]);
}
int idx = 0;
for (auto num : strided)
{
CHECK(num == av[2 * idx + 1]);
idx++;
}
}
示例8: on_announce_response
bool udp_tracker_connection::on_announce_response(span<char const> buf)
{
if (buf.size() < 20) return false;
buf = buf.subspan(8);
restart_read_timeout();
tracker_response resp;
resp.interval = aux::read_int32(buf);
resp.min_interval = 60;
resp.incomplete = aux::read_int32(buf);
resp.complete = aux::read_int32(buf);
int const num_peers = int(buf.size()) / 6;
if ((buf.size() % 6) != 0)
{
fail(error_code(errors::invalid_tracker_response_length));
return false;
}
boost::shared_ptr<request_callback> cb = requester();
#ifndef TORRENT_DISABLE_LOGGING
if (cb)
{
cb->debug_log("<== UDP_TRACKER_RESPONSE [ url: %s ]", tracker_req().url.c_str());
}
#endif
if (!cb)
{
close();
return true;
}
std::vector<peer_entry> peer_list;
resp.peers4.reserve(num_peers);
for (int i = 0; i < num_peers; ++i)
{
ipv4_peer_entry e;
memcpy(&e.ip[0], buf.data(), 4);
buf = buf.subspan(4);
e.port = aux::read_uint16(buf);
resp.peers4.push_back(e);
}
std::list<address> ip_list;
for (std::vector<tcp::endpoint>::const_iterator i = m_endpoints.begin()
, end(m_endpoints.end()); i != end; ++i)
{
ip_list.push_back(i->address());
}
cb->tracker_response(tracker_req(), m_target.address(), ip_list
, resp);
close();
return true;
}
示例9: crypt_gen_random
inline void crypt_gen_random(span<char> buffer)
{
static HCRYPTPROV provider = crypt_acquire_provider(PROV_RSA_FULL);
if (!CryptGenRandom(provider, int(buffer.size())
, reinterpret_cast<BYTE*>(buffer.data())))
{
throw_ex<system_error>(error_code(GetLastError(), system_category()));
}
}
示例10:
entry::entry(span<char const> v)
: m_type(undefined_t)
{
#if TORRENT_USE_ASSERTS
m_type_queried = true;
#endif
new(&data) string_type(v.data(), v.size());
m_type = string_t;
}
示例11: copy_buffer
allocation_slot stack_allocator::copy_buffer(span<char const> buf)
{
int const ret = int(m_storage.size());
int const size = int(buf.size());
if (size < 1) return {};
m_storage.resize(ret + size);
std::memcpy(&m_storage[ret], buf.data(), numeric_cast<std::size_t>(size));
return allocation_slot(ret);
}
示例12: buffer
// allocate an uninitialized buffer of the specified size
// and copy the initialization range into the start of the buffer
buffer(std::size_t const size, span<char const> initialize)
: buffer(size)
{
TORRENT_ASSERT(initialize.size() <= size);
if (!initialize.empty())
{
std::memcpy(m_begin, initialize.data(), (std::min)(initialize.size(), size));
}
}
示例13: upload
void GLVertexBuffer::upload(span<const byte> a_data)
{
assert(GLStateBuffer::isBegun());
assert(m_initialized);
if (!a_data.empty())
{
glBindBuffer(GLenum(m_bufferType), m_id);
glBufferData(GLenum(m_bufferType), a_data.length_bytes(), a_data.data(), GLenum(m_drawUsage));
}
}
示例14: assign
void item::assign(entry v, span<char const> salt
, sequence_number const seq
, public_key const& pk, signature const& sig)
{
m_pk = pk;
m_sig = sig;
m_salt.assign(salt.data(), salt.size());
m_seq = seq;
m_mutable = true;
m_value = std::move(v);
}
示例15: on_scrape_response
bool udp_tracker_connection::on_scrape_response(span<char const> buf)
{
using namespace libtorrent::aux;
restart_read_timeout();
int const action = aux::read_int32(buf);
std::uint32_t const transaction = read_uint32(buf);
if (transaction != m_transaction_id)
{
fail(error_code(errors::invalid_tracker_transaction_id));
return false;
}
if (action == action_error)
{
fail(error_code(errors::tracker_failure), -1
, std::string(buf.data(), buf.size()).c_str());
return true;
}
if (action != action_scrape)
{
fail(error_code(errors::invalid_tracker_action));
return true;
}
if (buf.size() < 12)
{
fail(error_code(errors::invalid_tracker_response_length));
return true;
}
int const complete = aux::read_int32(buf);
int const downloaded = aux::read_int32(buf);
int const incomplete = aux::read_int32(buf);
boost::shared_ptr<request_callback> cb = requester();
if (!cb)
{
close();
return true;
}
cb->tracker_scrape_response(tracker_req()
, complete, incomplete, downloaded, -1);
close();
return true;
}