Poco::MongoDB

class Binary

Library: MongoDB
Package: MongoDB
Header: Poco/MongoDB/Binary.h

Description

Implements BSON Binary.

A Binary stores its data in a Poco::Buffer<unsigned char>.

Member Summary

Member Functions: buffer, subtype, toRawString, toString, uuid

Types Aliases

Ptr

using Ptr = SharedPtr < Binary >;

BSON Binary subtypes

Enumerations

Subtype

SUBTYPE_GENERIC = 0x00

Generic binary data

SUBTYPE_FUNCTION = 0x01

Function

SUBTYPE_BINARY_OLD = 0x02

Binary (Old)

SUBTYPE_UUID_OLD = 0x03

UUID (Old)

SUBTYPE_UUID = 0x04

SUBTYPE_MD5 = 0x05

MD5

SUBTYPE_ENCRYPTED = 0x06

Encrypted BSON value

SUBTYPE_USER_DEFINED = 0x80

User defined (start of range)

Constructors

Binary

Binary();

Creates an empty Binary with subtype 0.

Binary

Binary(
    const UUID & uuid
);

Creates a Binary containing an UUID.

Binary

Binary(
    Poco::Int32 size,
    unsigned char subtype
);

Creates a Binary with a buffer of the given size and the given subtype.

Binary

Binary(
    const char * data,
    unsigned char subtype = 0
);

Creates a Binary with the contents of the given C-string and the given subtype.

Binary

Binary(
    const std::string & data,
    unsigned char subtype = 0
);

Creates a Binary with the contents of the given string and the given subtype.

Binary

Binary(
    const void * data,
    Poco::Int32 size,
    unsigned char subtype
);

Creates a Binary with the contents of the given buffer and the given subtype.

Destructor

~Binary virtual

virtual ~Binary();

Destroys the Binary.

Member Functions

buffer inline

const Buffer < unsigned char > & buffer() const;

Returns a reference to the internal buffer

buffer

Buffer < unsigned char > & buffer();

Returns a reference to the internal buffer

subtype inline

[[nodiscard]]
unsigned char subtype() const;

Returns the subtype.

subtype

void subtype(
    unsigned char type
);

Sets the subtype.

toRawString inline

[[nodiscard]]
std::string toRawString() const;

Returns the raw content of the Binary as a string.

toString

[[nodiscard]]
std::string toString(
    int indent = 0
) const;

Returns the contents of the Binary as a string. For UUID subtype (SUBTYPE_UUID), returns a formatted UUID string wrapped in UUID() (e.g., UUID("550e8400-e29b-41d4-a716-446655440000")). For other subtypes, returns Base64-encoded data.

uuid

[[nodiscard]]
UUID uuid() const;

Returns the UUID when the binary subtype is 0x04. Otherwise, throws a Poco::BadCastException.