• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ bytes函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了bytes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:MekliCZ,项目名称:positron,代码行数:19,代码来源:SharedSurface.cpp


示例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());
}
开发者ID:andreasots,项目名称:vindicat,代码行数:42,代码来源:Connection.cpp


示例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;
	}
}
开发者ID:mmanley,项目名称:Antares,代码行数:42,代码来源:BottomlineWindow.cpp


示例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;
}
开发者ID:qtproject,项目名称:qt-creator,代码行数:20,代码来源:pyvalue.cpp


示例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());
}
开发者ID:NAGAVENDRA,项目名称:GenieForiOS,代码行数:20,代码来源:BitSourceTest.cpp


示例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;
    }

}
开发者ID:coverclock,项目名称:com-diag-desperado,代码行数:23,代码来源:Heap.cpp


示例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();
}
开发者ID:Open-Transactions,项目名称:opentxs,代码行数:20,代码来源:HDSeed.cpp


示例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;
}
开发者ID:2gis,项目名称:2gisqt5android,代码行数:52,代码来源:quuid.cpp


示例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;
}
开发者ID:AllenWeb,项目名称:openjdk-1,代码行数:41,代码来源:methodLiveness.cpp


示例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);
}
开发者ID:mras0,项目名称:funtls,代码行数:21,代码来源:bigint_perf.cpp


示例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++;
    }
}
开发者ID:bchjoerni,项目名称:mlab,代码行数:21,代码来源:labport.cpp


示例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;
}
开发者ID:3163504123,项目名称:phantomjs,代码行数:21,代码来源:SharedBitmap.cpp


示例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;
}
开发者ID:Heart-travel,项目名称:platform_packages_apps_Nfc,代码行数:33,代码来源:NativeLlcpSocket.cpp


示例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;

	}
	
}
开发者ID:haskellstudio,项目名称:Chataigne,代码行数:21,代码来源:SerialModule.cpp


示例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;
		}
}
开发者ID:SylvestreG,项目名称:bitrig,代码行数:39,代码来源:reverse.c


示例16: _receive_msg

        /*
         * the main method
         * receives a Flow message and prints out its associated information
         * If the message belongs to another class, an exception is thrown.
         */
        virtual void _receive_msg(std::shared_ptr<const Msg>&& m, int /* index */)
        {
            if ( m->type() == MSG_ID(Flow) )
            {      
                auto flow = static_cast<const Flow *>(m.get());
                std::stringstream ss;
                const FlowKey& fk = flow->key();
                int duration = flow->end_time() - flow->start_time();
                ss<<"Flow of  "<< flow->packets() << " packets and "<<flow->bytes()<<" bytes begin at "<<flow->start_time()<<" end at "<<flow->end_time()<< "duration (ms.) "<<duration <<std::endl;
                ss<<"SRC IP "<<ip_to_string(fk.src_ip4)<<" SRC port "<<fk.src_port<<std::endl;
                ss<<"DST IP "<<ip_to_string(fk.dst_ip4)<<" DST port "<<fk.dst_port<<std::endl;
                ss<<"protocol "<<fk.proto<<std::endl;
                blocklog(ss.str(),log_info);


            }
                else
            {
                throw std::runtime_error("Flowprinter: wrong message type");
            }
        }
开发者ID:Aeronbroker,项目名称:blockmon,代码行数:26,代码来源:FlowPrinter.cpp


示例17: GetStringFromValue

static std::string& GetStringFromValue(KValueRef value)
{
    static std::string data;
    if (value->IsString())
    {
        data = value->ToString();
    }
    else
    {
        AutoPtr<Bytes> bytes(value->ToObject().cast<Bytes>());
        if (!bytes.isNull())
        {
            data = std::string(bytes->Pointer(), bytes->Length());
        }
        else
        {
            data = "";
        }
    }
    return data;
}
开发者ID:Defachko,项目名称:titanium_desktop,代码行数:21,代码来源:Codec.cpp


示例18: switch

/// Parses a string into a bytes quantity.
///
/// \param in_str The user-provided string to be converted.
///
/// \return The converted bytes quantity.
///
/// \throw std::runtime_error If the input string is empty or invalid.
units::bytes
units::bytes::parse(const std::string& in_str)
{
    if (in_str.empty())
        throw std::runtime_error("Bytes quantity cannot be empty");

    uint64_t multiplier;
    std::string str = in_str;
    {
        const char unit = str[str.length() - 1];
        switch (unit) {
        case 'T': case 't': multiplier = TB; break;
        case 'G': case 'g': multiplier = GB; break;
        case 'M': case 'm': multiplier = MB; break;
        case 'K': case 'k': multiplier = KB; break;
        default: multiplier = 1;
        }
        if (multiplier != 1)
            str.erase(str.length() - 1);
    }

    if (str.empty())
        throw std::runtime_error("Bytes quantity cannot be empty");
    if (str[0] == '.' || str[str.length() - 1] == '.') {
        // The standard parser for float values accepts things like ".3" and
        // "3.", which means that we would interpret ".3K" and "3.K" as valid
        // quantities.  I think this is ugly and should not be allowed, so
        // special-case this condition and just error out.
        throw std::runtime_error(F("Invalid bytes quantity '%s'") % in_str);
    }

    double count;
    try {
        count = text::to_type< double >(str);
    } catch (const text::value_error& e) {
        throw std::runtime_error(F("Invalid bytes quantity '%s'") % in_str);
    }

    return bytes(uint64_t(count * multiplier));
}
开发者ID:racktopsystems,项目名称:kyua,代码行数:47,代码来源:units.cpp


示例19: reserve

    void reserve()
    {
      BOOST_ASSERT( ptr_ == 0 );

      if( !count_ ) {

        return;
      }

      if( is_mapped() ) {

        boost::filesystem::path tmp( boost::filesystem::temp_directory_path() );
        filename_ = tmp.string() + "/mm_XXXXXX";

        char name[256];
        strcpy( name, filename_.c_str() );

        fd_ = mkstemp( name );
        filename_ = std::string( name );

        if( fd_ == -1 ) {

          std::cerr << "Unable to create map file: " << filename_ << std::endl;
          return;
        }

        off_t file_size( bytes() );
        ftruncate( fd_, file_size );

        void* mem = mmap( 0, file_size, PROT_READ | PROT_WRITE,
                                        MAP_SHARED | MAP_NORESERVE, fd_, 0 );

        BOOST_ASSERT( mem != MAP_FAILED );
        ptr_ = static_cast<num_type*>( mem );

      } else {

        ptr_ = new num_type[count_];
      }
    }
开发者ID:ajfazan,项目名称:opensource,代码行数:40,代码来源:mapped_memory.hpp


示例20: OpenRichDoc

/* decoded base64 stream to put on mysql row , file or network streams */
RichDoc OpenRichDoc( const QString datastream_base64   )
{
  RichDoc li;
	QByteArray xcode("");
	xcode.append(datastream_base64);
	quint32 magic, version;
	QByteArray bytes(QByteArray::fromBase64(xcode));   /* decoded base64 string to QByteArray */
	QBuffer buffer(&bytes);
	if (!buffer.open(QIODevice::ReadOnly)) {
		return li;
	}
	QDataStream ds(&buffer);
	/* place header */
	ds.setVersion(QDataStream::Qt_4_2);
	ds >> magic;
	if ( (quint32)RichDoc::MAGICNUMBER != magic ) {
  qWarning() << "######## RichDoc::MAGICNUMBER not ok  " << magic;
	buffer.close();
	return li;
	}
	ds >> version;
	if ( (quint32)RichDoc::VERSION != version ) {
	qWarning() << "######## RichDoc::VERSION not ok  " << version;
	buffer.close();
	return li;
	}
  QString s;
  QByteArray h;
  ds >> h;
  ds >> s;
  li.style = s;
  li.html = h;
  SPics appoint;
    while (!ds.atEnd()) {
         ds >> appoint;
         li.resource.insert(appoint.name,appoint);
    }
	buffer.close();
	return li;
}
开发者ID:SorinS,项目名称:fop-miniscribus,代码行数:41,代码来源:_Image_Page_Struct.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ c_im函数代码示例发布时间:2022-05-31
下一篇:
C++ builtin_decl_explicit函数代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap