本文整理汇总了C++中MessageHeader类的典型用法代码示例。如果您正苦于以下问题:C++ MessageHeader类的具体用法?C++ MessageHeader怎么用?C++ MessageHeader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MessageHeader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, const char* argv[])
{
char buffer[2048];
MessageHeader hdr;
Car car;
std::size_t encodeHdrLength = encodeHdr(hdr, car, buffer, 0, sizeof(buffer));
std::size_t encodeMsgLength = encodeCar(car, buffer, hdr.encodedLength(), sizeof(buffer));
cout << "Encoded Lengths are " << encodeHdrLength << " + " << encodeMsgLength << endl;
std::size_t decodeHdrLength = decodeHdr(hdr, buffer, 0, sizeof(buffer));
std::size_t decodeMsgLength = decodeCar(car, buffer, hdr.encodedLength(), hdr.blockLength(), hdr.version(), sizeof(buffer));
cout << "Decoded Lengths are " << decodeHdrLength << " + " << decodeMsgLength << endl;
if (encodeHdrLength != decodeHdrLength)
{
cerr << "Encode/Decode header lengths do not match\n";
return EXIT_FAILURE;
}
if (encodeMsgLength != decodeMsgLength)
{
cerr << "Encode/Decode message lengths do not match\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
示例2: session
void POP3ClientSessionTest::testRetrieveHeader()
{
DialogServer server;
server.addResponse("+OK POP3 Ready...");
server.addResponse("+OK USER");
server.addResponse("+OK PASS");
server.addResponse(
"+OK Here comes the message\r\n"
"From: [email protected]\r\n"
"To: [email protected]\r\n"
"Subject: test\r\n"
"\r\n"
"."
);
server.addResponse("+OK QUIT");
POP3ClientSession session("localhost", server.port());
session.login("user", "secret");
server.clearCommands();
MessageHeader header;
session.retrieveHeader(1, header);
std::string cmd = server.popCommand();
assert (cmd == "TOP 1 0");
assert (header.get("From") == "[email protected]");
assert (header.get("To") == "[email protected]");
assert (header.get("Subject") == "test");
session.close();
}
示例3: MCLog
MessageHeader * NNTPSession::fetchHeader(String *groupName, unsigned int index, ErrorCode * pError)
{
int r;
char * content;
size_t content_len;
MCLog("fetch header at index %u", index);
selectGroup(groupName, pError);
if (* pError != ErrorNone) {
return NULL;
}
r = newsnntp_head(mNNTP, index, &content, &content_len);
if (r != NEWSNNTP_NO_ERROR) {
* pError = ErrorFetchMessageList;
return NULL;
}
Data * data;
data = new Data(content, (unsigned int) content_len);
MessageHeader * result = new MessageHeader();
result->importHeadersData(data);
result->autorelease();
data->release();
newsnntp_head_free(content);
* pError = ErrorNone;
return result;
}
示例4: encodeHdrAndMsg
virtual std::uint64_t encodeHdrAndMsg()
{
MessageHeader hdr;
Msg msg;
hdr.wrap(m_buffer, 0, 0, sizeof(m_buffer))
.blockLength(Msg::sbeBlockLength())
.templateId(Msg::sbeTemplateId())
.schemaId(Msg::sbeSchemaId())
.version(Msg::sbeSchemaVersion());
msg.wrapForEncode(m_buffer, hdr.encodedLength(), sizeof(m_buffer));
msg.structure()
.enumOne(EnumOne::Value10)
.zeroth(42)
.setOne().clear().bit0(false).bit16(true).bit26(false);
msg.structure()
.inner()
.first(101)
.second(202);
return hdr.encodedLength() + msg.encodedLength();
}
示例5: s
void MultipartReaderTest::testReadOnePart()
{
std::string s("\r\n--MIME_boundary_01234567\r\nname1: value1\r\n\r\nthis is part 1\r\n--MIME_boundary_01234567--\r\n");
std::istringstream istr(s);
MultipartReader r(istr, "MIME_boundary_01234567");
assert (r.boundary() == "MIME_boundary_01234567");
assert (r.hasNextPart());
MessageHeader h;
r.nextPart(h);
assert (h.size() == 1);
assert (h["name1"] == "value1");
std::istream& i = r.stream();
int ch = i.get();
std::string part;
while (ch >= 0)
{
part += (char) ch;
ch = i.get();
}
assert (part == "this is part 1");
assert (!r.hasNextPart());
try
{
r.nextPart(h);
fail("no more parts - must throw");
}
catch (MultipartException&)
{
}
}
示例6: addRequest
void MessageRequestScheduler::addRequest (DisServiceDataReqMsg::FragmentRequest *pFragReq,
bool bSeq, bool bRel)
{
if (pFragReq == NULL) {
return;
}
MessageHeader *pMH = pFragReq->pMsgHeader;
if (pMH != NULL) {
// Create the proper FragReqWrapper
FragReqWrapper *pReq = NULL;
if (pMH->isChunk()) {
pReq = new ChunkFragReqWrapper (pFragReq, bSeq, bRel, _bDeleteDuplicateRequest);
}
else {
pReq = new MessageFragReqWrapper (pFragReq, bSeq, bRel, _bDeleteDuplicateRequest);
}
if (pReq == NULL) {
checkAndLogMsg ("MessageRequestScheduler::addRequest", memoryExhausted);
delete pFragReq;
}
else {
checkAndLogMsg ("MessageRequestScheduler::addRequest", Logger::L_HighDetailDebug,
"added request for %d fragments\n",
pFragReq->pRequestedRanges->getCount());
// Insert the FragReqWrapper
_requests.insert (pReq);
}
}
}
示例7: encodeHdrAndMsg
std::uint64_t encodeHdrAndMsg()
{
MessageHeader hdr;
TestMessage1 msg;
hdr.wrap(m_buffer, 0, 0, sizeof(m_buffer))
.blockLength(TestMessage1::sbeBlockLength())
.templateId(TestMessage1::sbeTemplateId())
.schemaId(TestMessage1::sbeSchemaId())
.version(TestMessage1::sbeSchemaVersion());
msg.wrapForEncode(m_buffer, hdr.encodedLength(), sizeof(m_buffer));
TestMessage1::Entries &entries = msg.entriesCount(2);
entries.next()
.tagGroup1(10)
.tagGroup2(20);
entries.next()
.tagGroup1(30)
.tagGroup2(40);
return hdr.encodedLength() + msg.encodedLength();
}
示例8: ar
bool JsAgent::dispatchAndReturn(JsValue& ret) {
ArchiveReader<Channel> ar(*m_channel);
while(true) {
Debug::println("Waiting for MessageHeader...");
MessageHeader mh;
if(!mh.serialize(ar))
return false;
switch(mh.getMessageType()) {
case MT_DefineFunction:
Debug::println("MT_DefineFunction");
MSG_DISPATCH(DefineFunctionMessage, onDefineFunction);
break;
case MT_InvokeFunction:
Debug::println("MT_InvokeFunction");
MSG_DISPATCH(InvokeFunctionMessage, onInvokeFunction);
break;
case MT_Return: {
Debug::println("MT_Return");
ReturnMessage msg;
msg.serialize(ar);
return onReturn(msg, ret);
}
case MT_Quit:
Debug::println("MT_Quit");
return true;
default:
Debug::println("Unknown message type!");
return false;
}
}
return false;
}
示例9: handleMessageHeader
void FifoReadCallback::handleMessageHeader(MessageHeader msgHeader) noexcept {
from_ = msgHeader.getLocalAddress();
to_ = msgHeader.getPeerAddress();
if (msgHeader.direction() == MessageDirection::Received) {
std::swap(from_, to_);
}
}
示例10: encodeHdrAndMsg
std::uint64_t encodeHdrAndMsg()
{
MessageHeader hdr;
MsgName msg;
hdr.wrap(m_buffer, 0, 0, sizeof(m_buffer))
.blockLength(MsgName::sbeBlockLength())
.templateId(MsgName::sbeTemplateId())
.schemaId(MsgName::sbeSchemaId())
.version(MsgName::sbeSchemaVersion());
msg.wrapForEncode(m_buffer, hdr.encodedLength(), sizeof(m_buffer));
msg.field1(187);
msg.field2().clear()
.choice1(true);
MsgName::GrName &grp = msg.grNameCount(2);
grp.next()
.grField1(10)
.grField2(20);
grp.next()
.grField1(30)
.grField2(40);
return hdr.encodedLength() + msg.encodedLength();
}
示例11: parseHeader
void MultipartReader::parseHeader(MessageHeader& messageHeader)
{
messageHeader.clear();
messageHeader.read(_istr);
int ch = _istr.get();
if (ch == '\r' && _istr.peek() == '\n') ch = _istr.get();
}
示例12: sendMessage
void AbstractProtocol::sendMessage(const AbstractMessage &message)
{
QByteArray totalData;
QByteArray messageData;
MessageHeader header;
static int nextSeq = 0;
nextSeq++;
message.serialize(&messageData);
header.data.size = messageData.size();
header.data.type = message.getType();
header.data.seqNum = nextSeq;
header.serialize(&totalData);
totalData.append(messageData);
qDebug() << "Sending Total size: " << totalData.size();
int written = 0;
int totalSize = totalData.size();
while (written < totalSize) {
int ret = socket->write(totalData.data() + written, totalSize - written);
if (ret == -1) {
qDebug() << "write error";
return;
}
written+=ret;
}
}
示例13: readPart
void MailMessage::readPart(std::istream& istr, const MessageHeader& header, PartHandler& handler)
{
std::string encoding;
if (header.has(HEADER_CONTENT_TRANSFER_ENCODING))
{
encoding = header.get(HEADER_CONTENT_TRANSFER_ENCODING);
// get rid of a parameter if one is set
std::string::size_type pos = encoding.find(';');
if (pos != std::string::npos)
encoding.resize(pos);
}
if (icompare(encoding, CTE_QUOTED_PRINTABLE) == 0)
{
QuotedPrintableDecoder decoder(istr);
handlePart(decoder, header, handler);
}
else if (icompare(encoding, CTE_BASE64) == 0)
{
Base64Decoder decoder(istr);
handlePart(decoder, header, handler);
}
else
{
handlePart(istr, header, handler);
}
}
示例14: s
void MessageHeaderTest::testRead3()
{
std::string s("name1: value1\r\n");
std::istringstream istr(s);
MessageHeader mh;
mh.read(istr);
assert (mh.size() == 1);
assert (mh["name1"] == "value1");
}
示例15: encodeHdr
static std::uint64_t encodeHdr(MessageHeader& hdr)
{
hdr.blockLength(Car::sbeBlockLength())
.templateId(Car::sbeTemplateId())
.schemaId(Car::sbeSchemaId())
.version(Car::sbeSchemaVersion());
return hdr.encodedLength();
}