aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/MongoDB/src/MessageHeader.cpp
blob: 222121243db72571d2d0b27acdacebdf7e9d9ea3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// MessageHeader.cpp
//
// Library: MongoDB
// Package: MongoDB
// Module:  MessageHeader
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:	BSL-1.0
//


#include "Poco/MongoDB/Message.h"
#include "Poco/Exception.h"


namespace Poco {
namespace MongoDB {


MessageHeader::MessageHeader(OpCode opCode): 
	_messageLength(0), 
	_requestID(0), 
	_responseTo(0), 
	_opCode(opCode)
{
}


MessageHeader::~MessageHeader()
{
}


void MessageHeader::read(BinaryReader& reader)
{
	reader >> _messageLength;
	reader >> _requestID;
	reader >> _responseTo;

	Int32 opCode;
	reader >> opCode;
	_opCode = (OpCode) opCode;

	if (!reader.good())
	{
		throw IOException("Failed to read from socket");
	}
}


void MessageHeader::write(BinaryWriter& writer)
{
	writer << _messageLength;
	writer << _requestID;
	writer << _responseTo;
	writer << (Int32) _opCode;
}


} } // namespace Poco::MongoDB