本文整理汇总了C++中bytes函数的典型用法代码示例。如果您正苦于以下问题:C++ bytes函数的具体用法?C++ bytes怎么用?C++ bytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadPixel
uint32_t
ReadPixel(SharedSurface* src)
{
GLContext* gl = src->mGL;
uint32_t pixel;
ScopedReadbackFB a(src);
{
ScopedPackAlignment autoAlign(gl, 4);
UniquePtr<uint8_t[]> bytes(new uint8_t[4]);
gl->raw_fReadPixels(0, 0, 1, 1, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE,
bytes.get());
memcpy(&pixel, bytes.get(), 4);
}
return pixel;
}
示例2: Forwarding
Connection::Connection(CryptoIdentity& ci, Path path, ConnectionPool& cp, ConnectionHandler& ch)
: Forwarding(randint64())
, _ci(&ci)
, _cp(cp)
, _ch(ch)
, _naclsession( std::get<1>(path.at(path.size()-1))->enc_key() )
, _their_id( std::get<1>(path.at(path.size()-1))->id() )
, _route_id( bytes( id() ) )
, _authenticated(false)
, _request_packet(new std::string)
, _packet_queue(new std::vector<std::string>)
, _nonces(nullptr)
{
_request_packet->push_back('\1');
std::string nonce = _route_id + randomstring(8);
_request_packet->append(nonce);
nonce.resize(crypto_box_NONCEBYTES,'\0');
RoutingRequest rq;
rq.set_enc_algo(enumval(PkencAlgo::CURVE25519XSALSA20POLY1305));
rq.set_sender_pubkey(_naclsession.our_pk());
Hop hop;
{
hop.set_type(Hop::UP);
hop.set_nonce_algo(Hop::XTEA32);
rq.set_details(_naclsession.encrypt(hop.SerializeAsString(), nonce));
}
hop.Clear();
hop.set_type(Hop::SIMPLE);
hop.set_next(_their_id);
for (signed int i=path.size()-2; i>=0; --i) {
auto dev = std::get<1>(path[i]);
hop.set_details(rq.details());
rq.set_details( crypto_box( hop.SerializeAsString(), nonce,
dev->enc_key(), _naclsession.our_sk()) );
hop.set_next(dev->id());
}
rq.AppendToString(_request_packet.get());
}
示例3: CALLED
void
BottomlineWindow::HandleInputMethodEvent(BMessage* event, EventList& newEvents)
{
CALLED();
PostMessage(event, fTextView);
const char* string;
bool confirmed;
int32 opcode;
if (event->FindInt32("be:opcode", &opcode) != B_OK
|| opcode != B_INPUT_METHOD_CHANGED
|| event->FindBool("be:confirmed", &confirmed) != B_OK
|| !confirmed
|| event->FindString("be:string", &string) != B_OK)
return;
SERIAL_PRINT(("IME : %i, %s\n", opcode, string));
SERIAL_PRINT(("IME : confirmed\n"));
int32 length = strlen(string);
int32 offset = 0;
int32 nextOffset = 0;
while (offset < length) {
// this is supposed to go to the next UTF-8 character
for (++nextOffset; (string[nextOffset] & 0xC0) == 0x80; ++nextOffset)
;
BMessage *newEvent = new BMessage(B_KEY_DOWN);
if (newEvent != NULL) {
newEvent->AddInt32("key", 0);
newEvent->AddInt64("when", system_time());
BString bytes(string + offset, nextOffset - offset);
newEvent->AddString("bytes", bytes);
newEvent->AddInt32("raw_char", 0xa);
newEvents.AddItem(newEvent);
}
offset = nextOffset;
}
}
示例4: Bytes
Bytes PyValue::asBytes()
{
if (m_symbolGroup)
return Bytes();
ULONG64 address = 0;
if (FAILED(m_symbolGroup->GetSymbolOffset(m_index, &address)))
return Bytes();
ULONG size;
if (FAILED(m_symbolGroup->GetSymbolSize(m_index, &size)))
return Bytes();
Bytes bytes(size);
unsigned long received;
auto data = ExtensionCommandContext::instance()->dataSpaces();
if (FAILED(data->ReadVirtual(address, bytes.data(), size, &received)))
return Bytes();
bytes.resize(received);
return bytes;
}
示例5: bytes
void BitSourceTest::testSource() {
byte rawBytes[] = {(byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5};
ArrayRef<byte> bytes(rawBytes, 5);
BitSource source(bytes);
CPPUNIT_ASSERT_EQUAL(40, source.available());
CPPUNIT_ASSERT_EQUAL(0, source.readBits(1));
CPPUNIT_ASSERT_EQUAL(39, source.available());
CPPUNIT_ASSERT_EQUAL(0, source.readBits(6));
CPPUNIT_ASSERT_EQUAL(33, source.available());
CPPUNIT_ASSERT_EQUAL(1, source.readBits(1));
CPPUNIT_ASSERT_EQUAL(32, source.available());
CPPUNIT_ASSERT_EQUAL(2, source.readBits(8));
CPPUNIT_ASSERT_EQUAL(24, source.available());
CPPUNIT_ASSERT_EQUAL(12, source.readBits(10));
CPPUNIT_ASSERT_EQUAL(14, source.available());
CPPUNIT_ASSERT_EQUAL(16, source.readBits(8));
CPPUNIT_ASSERT_EQUAL(6, source.available());
CPPUNIT_ASSERT_EQUAL(5, source.readBits(6));
CPPUNIT_ASSERT_EQUAL(0, source.available());
}
示例6: tracef
//
// Free a block of memory.
//
void Heap::free(void* ptr) {
Print tracef(this->output());
if (this->tracing) {
tracef("Heap[%p]::free(%p)\n", this, ptr);
}
Alignment* optr = static_cast<Alignment*>(ptr);
if (0 != optr) {
size_t osize = *(--optr);
size_t nsize = bytes(words(osize));
this->current -= nsize;
delete [] optr;
++this->frees;
} else {
++this->nulls;
}
}
示例7: input
std::string HDSeed::Bip32Root(const std::string& fingerprint) const
{
// TODO: make fingerprint non-const
std::string input(fingerprint);
std::uint32_t notUsed = 0;
auto seed = Seed(input, notUsed);
if (!seed) { return ""; }
auto start = static_cast<const unsigned char*>(seed->getMemory());
const auto end = start + seed->getMemorySize();
std::vector<unsigned char> bytes(start, end);
std::ostringstream stream;
stream << std::hex << std::setfill('0');
for (int byte : bytes) { stream << std::setw(2) << byte; }
return stream.str();
}
示例8: bytes
/*!
Returns the binary representation of this QUuid. The byte array is in big
endian format, and formatted according to RFC 4122, section 4.1.2 -
"Layout and byte order".
The order is as follows:
\table
\header
\li Field #
\li Source
\row
\li 1
\li data1
\row
\li 2
\li data2
\row
\li 3
\li data3
\row
\li 4
\li data4[0] .. data4[7]
\endtable
\since 4.8
*/
QByteArray QUuid::toRfc4122() const
{
// we know how many bytes a UUID has, I hope :)
QByteArray bytes(16, Qt::Uninitialized);
uchar *data = reinterpret_cast<uchar*>(bytes.data());
qToBigEndian(data1, data);
data += sizeof(quint32);
qToBigEndian(data2, data);
data += sizeof(quint16);
qToBigEndian(data3, data);
data += sizeof(quint16);
for (int i = 0; i < 8; ++i) {
*(data) = data4[i];
data++;
}
return bytes;
}
示例9: answer
MethodLivenessResult MethodLiveness::BasicBlock::get_liveness_at(ciMethod* method, int bci) {
MethodLivenessResult answer(NEW_RESOURCE_ARRAY(size_t, _analyzer->bit_map_size_words()),
_analyzer->bit_map_size_bits());
answer.set_is_valid();
#ifndef ASSERT
if (bci == start_bci()) {
answer.set_from(_entry);
return answer;
}
#endif
#ifdef ASSERT
ResourceMark rm;
BitMap g(_gen.size()); g.set_from(_gen);
BitMap k(_kill.size()); k.set_from(_kill);
#endif
if (_last_bci != bci || trueInDebug) {
ciBytecodeStream bytes(method);
bytes.reset_to_bci(bci);
bytes.set_max_bci(limit_bci());
compute_gen_kill_range(&bytes);
assert(_last_bci != bci ||
(g.is_same(_gen) && k.is_same(_kill)), "cached computation is incorrect");
_last_bci = bci;
}
answer.clear();
answer.set_union(_normal_exit);
answer.set_difference(_kill);
answer.set_union(_gen);
answer.set_union(_exception_exit);
#ifdef ASSERT
if (bci == start_bci()) {
assert(answer.is_same(_entry), "optimized answer must be accurate");
}
#endif
return answer;
}
示例10: rand_int
I rand_int(size_t max_bits = ::test_max_bits)
{
std::vector<uint8_t> bytes((max_bits+7)/8);
assert(!bytes.empty());
static uint32_t rand_state = 0x123456;
auto R = [&]() {
rand_state = rand_state * 1664525 + 1013904223;
return static_cast<uint8_t>(uint64_t(rand_state)*255/(UINT64_C(1)<<32));
};
for (auto& b : bytes) {
b = R();
}
if (max_bits % 8) {
const auto first_max = (1<<max_bits%8)-1;
std::cout << "first_max = " << first_max << std::endl;
while (bytes[0] > first_max) bytes[0] = R();
}
return funtls::be_uint_from_bytes<I>(bytes);
}
示例11: bytes
void labPort::sendMsg( const char* msg, int numChars, bool inTime )
{
if( _closing )
{
return;
}
QByteArray bytes( msg, numChars );
_msgToSend.push_back( bytes );
if( !_sendTimer.isActive() )
{
timeToSendMsg();
_sendTimer.start( _writingPauseMs );
}
if( inTime )
{
_inTimeValueCounter++;
}
}
示例12: width
PassRefPtr<SharedBitmap> SharedBitmap::clipBitmap(const IntRect& rect, bool useAlpha)
{
int oldWidth = width();
int oldHeight = height();
int copyWidth = std::min<int>(rect.width(), oldWidth - rect.x());
int copyHeight = std::min<int>(rect.height(), oldHeight - rect.y());
if (!copyWidth || !copyHeight)
return 0;
RefPtr<SharedBitmap> newBmp = create(IntSize(copyWidth, copyHeight), useAlpha && is32bit() ? BitmapInfo::BitCount32 : BitmapInfo::BitCount16, false);
if (!newBmp || !newBmp->bytes())
return 0;
DCHolder dcNew(newBmp.get());
StretchDIBits(dcNew.get(), 0, 0, copyWidth, copyHeight, rect.x(), rect.y(), copyWidth, copyHeight,
bytes(), &bitmapInfo(), DIB_RGB_COLORS, SRCCOPY);
return newBmp;
}
示例13: nativeLlcpSocket_doReceive
/*******************************************************************************
**
** Function: nativeLlcpSocket_doReceive
**
** Description: Receive data from peer.
** e: JVM environment.
** o: Java object.
** origBuffer: Buffer to put received data.
**
** Returns: Number of bytes received.
**
*******************************************************************************/
static jint nativeLlcpSocket_doReceive(JNIEnv *e, jobject o, jbyteArray origBuffer)
{
ALOGD_IF ((appl_trace_level>=BT_TRACE_LEVEL_DEBUG), "%s: enter", __FUNCTION__);
ScopedByteArrayRW bytes(e, origBuffer);
PeerToPeer::tJNI_HANDLE jniHandle = (PeerToPeer::tJNI_HANDLE) nfc_jni_get_nfc_socket_handle(e, o);
uint16_t actualLen = 0;
bool stat = PeerToPeer::getInstance().receive(jniHandle, reinterpret_cast<UINT8*>(&bytes[0]), bytes.size(), actualLen);
jint retval = 0;
if (stat && (actualLen>0))
{
retval = actualLen;
}
else
retval = -1;
ALOGD_IF ((appl_trace_level>=BT_TRACE_LEVEL_DEBUG), "%s: exit; actual len=%d", __FUNCTION__, retval);
return retval;
}
示例14: switch
void SerialModule::serialDataReceived(const var & data)
{
inActivityTrigger->trigger();
switch (port->mode)
{
case SerialDevice::LINES:
processDataLine(data.toString());
break;
case SerialDevice::DATA255:
case SerialDevice::RAW:
case SerialDevice::COBS:
Array<uint8> bytes((const uint8_t *)data.getBinaryData()->getData(), (int)data.getBinaryData()->getSize());
processDataBytes(bytes);
break;
}
}
示例15: reverse
/*
* reverse -- display input in reverse order by line.
*
* There are six separate cases for this -- regular and non-regular
* files by bytes, lines or the whole file.
*
* BYTES display N bytes
* REG reverse scan and display the lines
* NOREG cyclically read characters into a wrap-around buffer
*
* LINES display N lines
* REG reverse scan and display the lines
* NOREG cyclically read lines into a wrap-around array of buffers
*
* FILE display the entire file
* REG reverse scan and display the lines
* NOREG cyclically read input into a linked list of buffers
*/
void
reverse(FILE *fp, enum STYLE style, off_t off, struct stat *sbp)
{
if (style != REVERSE && off == 0)
return;
if (!S_ISREG(sbp->st_mode) || r_reg(fp, style, off, sbp) != 0)
switch(style) {
case FBYTES:
case RBYTES:
(void)bytes(fp, off);
break;
case FLINES:
case RLINES:
(void)lines(fp, off);
break;
case REVERSE:
r_buf(fp);
break;
}
}