1//
2// MessageHeader.cpp
3//
4// Library: MongoDB
5// Package: MongoDB
6// Module: MessageHeader
7//
8// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/MongoDB/Message.h"
16#include "Poco/Exception.h"
17
18
19namespace Poco {
20namespace MongoDB {
21
22
23MessageHeader::MessageHeader(OpCode opCode):
24 _messageLength(0),
25 _requestID(0),
26 _responseTo(0),
27 _opCode(opCode)
28{
29}
30
31
32MessageHeader::~MessageHeader()
33{
34}
35
36
37void MessageHeader::read(BinaryReader& reader)
38{
39 reader >> _messageLength;
40 reader >> _requestID;
41 reader >> _responseTo;
42
43 Int32 opCode;
44 reader >> opCode;
45 _opCode = (OpCode) opCode;
46
47 if (!reader.good())
48 {
49 throw IOException("Failed to read from socket");
50 }
51}
52
53
54void MessageHeader::write(BinaryWriter& writer)
55{
56 writer << _messageLength;
57 writer << _requestID;
58 writer << _responseTo;
59 writer << (Int32) _opCode;
60}
61
62
63} } // namespace Poco::MongoDB
64