8#ifndef INCLUDED_BDLBB_BLOBUTIL
9#define INCLUDED_BDLBB_BLOBUTIL
57#include <bdlscm_version.h>
67#include <bsl_algorithm.h>
68#include <bsl_cstring.h>
69#include <bsl_iosfwd.h>
70#include <bsl_utility.h>
118 static void append(
Blob *dest,
const char *source,
int offset,
int length);
126 static void append(
Blob *dest,
const char *source,
int length);
173 static void insert(
Blob *dest,
int destOffset,
const Blob& source);
194 static void copy(
char *dstBuffer,
282 static bsl::ostream&
hexDump(bsl::ostream& stream,
const Blob& source);
291 static bsl::ostream&
hexDump(bsl::ostream& stream,
305 char fillChar =
'\0');
324 template <
class STREAM>
325 static STREAM&
read(STREAM& stream,
Blob *dest,
int numBytes);
329 template <
class STREAM>
330 static STREAM&
write(STREAM& stream,
const Blob& source);
338 template <
class STREAM>
339 static int write(STREAM& stream,
584 return append(dest, source, offset, length);
593 return append(dest, source, offset);
599 return append(dest, source);
621 bsl::memcpy(lastBuf.
buffer().
get() + offsetInBuf, source, length);
626 append(dest, source, 0, length);
639 source.
length() - sourceOffset);
658 BSLS_ASSERT(
static_cast<unsigned>(alignment) <= 64);
660 const int modMask = alignment - 1;
664 const int padLength = (alignment - (dest->
length() & modMask)) & modMask;
666 bsl::memset(padBuffer, fillChar, padLength);
668 append(dest, padBuffer, padLength);
671template <
class STREAM>
678 for (
int numBytesRemaining = numBytes, i = 0; 0 < numBytesRemaining; ++i) {
683 const int bytesToRead = numBytesRemaining < buffer.
size()
687 stream.getArrayInt8(buffer.
data(), bytesToRead);
689 numBytesRemaining -= bytesToRead;
695template <
class STREAM>
698 int numBytes = source.
length();
700 for (
int numBytesRemaining = numBytes, i = 0; 0 < numBytesRemaining; ++i) {
705 const int bytesToWrite = numBytesRemaining < buffer.
size()
709 stream.putArrayInt8(buffer.
data(), bytesToWrite);
711 numBytesRemaining -= bytesToWrite;
717template <
class STREAM>
726 if (sourcePosition + numBytes > source.
length()) {
730 if (sourcePosition == 0 && numBytes == 0) {
735 int bytesSkipped = 0;
736 while (bytesSkipped + source.
buffer(bufferIndex).
size() <=
738 bytesSkipped += source.
buffer(bufferIndex).
size();
742 int bytesRemaining = numBytes;
743 while (0 < bytesRemaining) {
746 const int startingIndex = 0 < bytesSkipped || 0 == bufferIndex
747 ? sourcePosition - bytesSkipped
750 const int bytesToCopy = bytesRemaining > buffer.
size() - startingIndex
751 ? buffer.
size() - startingIndex
754 stream.putArrayInt8(buffer.
data() + startingIndex, bytesToCopy);
759 bytesRemaining -= bytesToCopy;
808 const int TRIMMED_SIZE =
814 if ((dest->
totalSize() - TRIMMED_SIZE <= INT_MAX - lvalue.
size())
865 int bufferSize = lvalue.
size();
866 if ((dest->
totalSize() <= INT_MAX - bufferSize)
883, d_length(blob->length())
912 const BlobUtilAsciiDumper& rhs)
914 int offset = bsl::min(rhs.d_offset, rhs.d_blob_p->length());
915 int length = bsl::min(rhs.d_length, rhs.d_blob_p->length() - offset);
916 return BlobUtil::asciiDump(stream, *rhs.d_blob_p, offset, length);
930, d_length(blob->length())
957 const BlobUtilHexDumper& rhs)
959 int offset = bsl::min(rhs.d_offset, rhs.d_blob_p->length());
960 int length = bsl::min(rhs.d_length, rhs.d_blob_p->length() - offset);
961 return BlobUtil::hexDump(stream, *rhs.d_blob_p, offset, length);
Definition bdlbb_blob.h:619
Definition bdlbb_blob.h:450
bsl::shared_ptr< char > & buffer()
Definition bdlbb_blob.h:1127
char * data() const
Definition bdlbb_blob.h:1148
int size() const
Return the size of the buffer represented by this object.
Definition bdlbb_blob.h:1154
Definition bdlbb_blob.h:645
void prependDataBuffer(const BlobBuffer &buffer)
Definition bdlbb_blob.h:1204
int lastDataBufferLength() const
Definition bdlbb_blob.h:1247
int length() const
Return the length of this blob.
Definition bdlbb_blob.h:1253
int numDataBuffers() const
Return the number of blob buffers containing data in this blob.
Definition bdlbb_blob.h:1265
const BlobBuffer & buffer(int index) const
Definition bdlbb_blob.h:1232
void insertBuffer(int index, const BlobBuffer &buffer)
Definition bdlbb_blob.h:1197
int numBuffers() const
Return the number of blob buffers held by this blob.
Definition bdlbb_blob.h:1259
void appendDataBuffer(const BlobBuffer &buffer)
Definition bdlbb_blob.h:1190
void appendBuffer(const BlobBuffer &buffer)
Definition bdlbb_blob.h:1183
int totalSize() const
Definition bdlbb_blob.h:1271
void setLength(int length)
Definition bslstl_pair.h:1280
element_type * get() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_sharedptr.h:5665
Definition bslma_allocator.h:545
Definition bslmf_movableref.h:752
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlbb_blob.h:437
bsl::ostream & operator<<(bsl::ostream &stream, const BlobBuffer &buffer)
Definition bdlbb_blobutil.h:465
int d_offset
Definition bdlbb_blobutil.h:469
const Blob * d_blob_p
Definition bdlbb_blobutil.h:468
BlobUtilAsciiDumper(const Blob *blob)
Definition bdlbb_blobutil.h:880
int d_length
Definition bdlbb_blobutil.h:470
Definition bdlbb_blobutil.h:515
int d_length
Definition bdlbb_blobutil.h:520
BlobUtilHexDumper(const Blob *blob)
Definition bdlbb_blobutil.h:927
const Blob * d_blob_p
Definition bdlbb_blobutil.h:518
int d_offset
Definition bdlbb_blobutil.h:519
Definition bdlbb_blobutil.h:83
static int insertBufferIfValid(Blob *dest, int index, const BlobBuffer &buffer)
Definition bdlbb_blobutil.h:824
static char * getContiguousDataBuffer(Blob *blob, int addLength, BlobBufferFactory *factory)
static int appendBufferIfValid(Blob *dest, const BlobBuffer &buffer)
Definition bdlbb_blobutil.h:769
static void copy(Blob *dst, int dstOffset, const char *src, int length)
static void append(Blob *dest, const Blob &source, int offset, int length)
static bsl::ostream & hexDump(bsl::ostream &stream, const Blob &source, int offset, int length)
static void append(Blob *dest, const char *source, int offset, int length)
static char * getContiguousRangeOrCopy(char *dstBuffer, const Blob &srcBlob, int position, int length, int alignment=1)
static int compare(const Blob &a, const Blob &b)
static STREAM & read(STREAM &stream, Blob *dest, int numBytes)
Definition bdlbb_blobutil.h:672
static bsl::ostream & asciiDump(bsl::ostream &stream, const Blob &source, int offset, int length)
static void copy(Blob *dst, int dstOffset, const Blob &src, int srcOffset, int length)
static STREAM & write(STREAM &stream, const Blob &source)
Definition bdlbb_blobutil.h:696
static int appendDataBufferIfValid(Blob *dest, const BlobBuffer &buffer)
Definition bdlbb_blobutil.h:791
static void padToAlignment(Blob *dest, int alignment, char fillChar='\0')
Definition bdlbb_blobutil.h:655
static bsl::ostream & hexDump(bsl::ostream &stream, const Blob &source)
Definition bdlbb_blobutil.h:649
static void erase(Blob *blob, int offset, int length)
static bsl::ostream & asciiDump(bsl::ostream &stream, const Blob &source)
static void appendWithCapacityBuffer(Blob *dest, BlobBuffer *buffer, const char *source, int length)
static void insert(Blob *dest, int destOffset, const Blob &source, int sourceOffset, int sourceLength)
static int prependDataBufferIfValid(Blob *dest, const BlobBuffer &buffer)
Definition bdlbb_blobutil.h:852
static bsl::pair< int, int > findBufferIndexAndOffset(const Blob &blob, int position)
static void append(Blob *dest, int length, char fill)
static void prependWithCapacityBuffer(Blob *dest, BlobBuffer *buffer, const char *source, int length)
static void copy(char *dstBuffer, const Blob &srcBlob, int position, int length)
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1067