BloombergLP::bdlbb::BlobUtil::getContiguousRangeOrCopy

Return a contiguous view of blob data, copying into a buffer if needed.

Synopsis

Declared in <bdlbb_blobutil.h>

static
char*
getContiguousRangeOrCopy(
    char* dstBuffer,
    Blob const& srcBlob,
    int position,
    int length,
    int alignment = 1);

Description

Return the address of the byte at the specified position in the specified srcBlob, if that address is aligned to the optionally specified alignment and the specified length bytes are stored contiguously; otherwise, copy length bytes to the specified buffer dstBuffer, and return dstBuffer. If alignment is not specified, none is enforced. (An address is aligned to A if, when converted to an integral value a, a & (A - 1) is 0.) The behavior of this function is undefined unless 0 < length, 0 <= position, alignment is a power of two, dstBuffer is aligned as required, dstBuffer has room for length bytes, and position <= srcBlob.totalSize() - length.

Return Value

address of the contiguous range in srcBlob, or dstBuffer if a copy was required

Parameters

NameDescription
dstBufferfallback contiguous buffer used when a copy is needed
srcBlobsource blob
positionstarting byte offset in srcBlob
lengthnumber of bytes required contiguously
alignmentrequired alignment of the returned address