fixed GH #2655: MongoDB Binary element to string - bug

This commit is contained in:
Günter Obiltschnig
2019-06-22 18:31:57 +02:00
parent 5ba6ec6885
commit 093568ecc7

View File

@@ -19,7 +19,7 @@ namespace Poco {
namespace MongoDB { namespace MongoDB {
Binary::Binary(): Binary::Binary():
_buffer(0), _buffer(0),
_subtype(0) _subtype(0)
{ {
@@ -27,14 +27,14 @@ Binary::Binary():
Binary::Binary(Poco::Int32 size, unsigned char subtype): Binary::Binary(Poco::Int32 size, unsigned char subtype):
_buffer(size), _buffer(size),
_subtype(subtype) _subtype(subtype)
{ {
} }
Binary::Binary(const UUID& uuid): Binary::Binary(const UUID& uuid):
_buffer(128 / 8), _buffer(128 / 8),
_subtype(0x04) _subtype(0x04)
{ {
unsigned char szUUID[16]; unsigned char szUUID[16];
@@ -44,14 +44,14 @@ Binary::Binary(const UUID& uuid):
Binary::Binary(const std::string& data, unsigned char subtype): Binary::Binary(const std::string& data, unsigned char subtype):
_buffer(reinterpret_cast<const unsigned char*>(data.data()), data.size()), _buffer(reinterpret_cast<const unsigned char*>(data.data()), data.size()),
_subtype(subtype) _subtype(subtype)
{ {
} }
Binary::Binary(const void* data, Poco::Int32 size, unsigned char subtype): Binary::Binary(const void* data, Poco::Int32 size, unsigned char subtype):
_buffer(reinterpret_cast<const unsigned char*>(data), size), _buffer(reinterpret_cast<const unsigned char*>(data), size),
_subtype(subtype) _subtype(subtype)
{ {
@@ -69,6 +69,7 @@ std::string Binary::toString(int indent) const
Base64Encoder encoder(oss); Base64Encoder encoder(oss);
MemoryInputStream mis((const char*) _buffer.begin(), _buffer.size()); MemoryInputStream mis((const char*) _buffer.begin(), _buffer.size());
StreamCopier::copyStream(mis, encoder); StreamCopier::copyStream(mis, encoder);
encoder.close();
return oss.str(); return oss.str();
} }