1//
2// RequestMessage.cpp
3//
4// Library: MongoDB
5// Package: MongoDB
6// Module: RequestMessage
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/RequestMessage.h"
16#include "Poco/Net/SocketStream.h"
17#include "Poco/StreamCopier.h"
18
19
20namespace Poco {
21namespace MongoDB {
22
23
24RequestMessage::RequestMessage(MessageHeader::OpCode opcode):
25 Message(opcode)
26{
27}
28
29
30RequestMessage::~RequestMessage()
31{
32}
33
34
35void RequestMessage::send(std::ostream& ostr)
36{
37 std::stringstream ss;
38 BinaryWriter requestWriter(ss);
39 buildRequest(requestWriter);
40 requestWriter.flush();
41
42 messageLength(static_cast<Poco::Int32>(ss.tellp()));
43
44 BinaryWriter socketWriter(ostr, BinaryWriter::LITTLE_ENDIAN_BYTE_ORDER);
45 _header.write(socketWriter);
46 StreamCopier::copyStream(ss, ostr);
47 ostr.flush();
48}
49
50
51} } // namespace Poco::MongoDB
52