本文整理汇总了C++中Header::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ Header::begin方法的具体用法?C++ Header::begin怎么用?C++ Header::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Header
的用法示例。
在下文中一共展示了Header::begin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: appendHeaderWithEmulation
void appendHeaderWithEmulation(Header& h)
{
Header::iterator s = h.begin();
Header::iterator e;
uint8_t zeros[] = {0, 0};
uint8_t emulation[] = {0, 0, 3};
do {
e = std::search(s, h.end(), zeros, zeros + N_ELEMENTS(zeros));
m_headers.insert(m_headers.end(), s, e);
if (e == h.end())
break;
s = e + N_ELEMENTS(zeros);
/* only when bitstream contains 0x000000/0x000001/0x000002/0x000003
need to insert emulation prevention byte 0x03 */
if (*s <= 3)
m_headers.insert(m_headers.end(), emulation, emulation + N_ELEMENTS(emulation));
else
m_headers.insert(m_headers.end(), zeros, zeros + N_ELEMENTS(zeros));
} while (1);
}
示例2: process
int Control::process(Header &header) {
size_ = header.payload_size() + 2;
Utilities::Utf8::Byte utf8;
uint8_t mask_offset = 0;
uint8_t *buffer = &(*buffer_.get())[0];
buffer[0] = header.begin()[0];
buffer[1] = header.begin()[1];
Utilities::Print::hex(&buffer[0],header.payload_size()+2); std::cout << std::endl;
if( (buffer[0] & 0x0F) == 0x08) {
if(header.payload_size() >= 2) {
Utilities::Websocket::applyMask(&buffer[2]
, 2
, &header.mask(), mask_offset
, false
, utf8);
Utilities::Websocket::applyMask(&buffer[4]
, header.payload_size() -2
, &header.mask(), mask_offset
, true
, utf8);
if(!utf8.complete()) {
std::cout << "invalid utf in control" << std::endl;
return 1007;
}
}
state_ = ControlState::KILL;
std::cout << "control kill" << std::endl;
buffer[1] &= 0x7F;
uint16_t code = buffer[2] << 8 | buffer[3] << 0;
if( code < 1000
||(code < 3000
&& code != 1000 && code != 1001 && code != 1002 && code != 1003
&& code != 1007 && code != 1008 && code != 1009 && code != 1010
&& code != 1011)
|| code > 4999
) {
buffer[2] = 0x03;
buffer[3] = 0xEA;
}
} else if ( (buffer[0] & 0x0F) == 0x09 ) {
Utilities::Websocket::applyMask(&buffer[2]
, header.payload_size()
, &header.mask(), mask_offset
, false
, utf8);
if(!utf8.complete()) {
std::cout << "invalid utf in control" << std::endl;
return 1007;
}
state_ = ControlState::PING;
buffer[0] = ( buffer[0] & 0xF0 ) | 0x0A;
buffer[1] &= 0x7F;
std::cout << "control pong"; Utilities::Print::hex(&buffer[0],2);std::cout <<std::endl;
} else if ( (buffer[0] & 0x0F) == 0x0A ) {
state_ = ControlState::PONG;
std::cout << "pong recieved" << std::endl;
} else {
state_ = ControlState::INVALID;
}
return 0;
}