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>
113 static void append(
Blob *dest,
const char *source,
int offset,
int length);
120 static void append(
Blob *dest,
const char *source,
int length);
164 static void insert(
Blob *dest,
int destOffset,
const Blob& source);
183 static void copy(
char *dstBuffer,
266 static bsl::ostream&
hexDump(bsl::ostream& stream,
const Blob& source);
274 static bsl::ostream&
hexDump(bsl::ostream& stream,
287 char fillChar =
'\0');
305 template <
class STREAM>
306 static STREAM&
read(STREAM& stream,
Blob *dest,
int numBytes);
310 template <
class STREAM>
311 static STREAM&
write(STREAM& stream,
const Blob& source);
318 template <
class STREAM>
319 static int write(STREAM& stream,
556 return append(dest, source, offset, length);
565 return append(dest, source, offset);
571 return append(dest, source);
593 bsl::memcpy(lastBuf.
buffer().
get() + offsetInBuf, source, length);
598 append(dest, source, 0, length);
611 source.
length() - sourceOffset);
630 BSLS_ASSERT(
static_cast<unsigned>(alignment) <= 64);
632 const int modMask = alignment - 1;
636 const int padLength = (alignment - (dest->
length() & modMask)) & modMask;
638 bsl::memset(padBuffer, fillChar, padLength);
640 append(dest, padBuffer, padLength);
643template <
class STREAM>
650 for (
int numBytesRemaining = numBytes, i = 0; 0 < numBytesRemaining; ++i) {
655 const int bytesToRead = numBytesRemaining < buffer.
size()
659 stream.getArrayInt8(buffer.
data(), bytesToRead);
661 numBytesRemaining -= bytesToRead;
667template <
class STREAM>
670 int numBytes = source.
length();
672 for (
int numBytesRemaining = numBytes, i = 0; 0 < numBytesRemaining; ++i) {
677 const int bytesToWrite = numBytesRemaining < buffer.
size()
681 stream.putArrayInt8(buffer.
data(), bytesToWrite);
683 numBytesRemaining -= bytesToWrite;
689template <
class STREAM>
698 if (sourcePosition + numBytes > source.
length()) {
702 if (sourcePosition == 0 && numBytes == 0) {
707 int bytesSkipped = 0;
708 while (bytesSkipped + source.
buffer(bufferIndex).
size() <=
710 bytesSkipped += source.
buffer(bufferIndex).
size();
714 int bytesRemaining = numBytes;
715 while (0 < bytesRemaining) {
718 const int startingIndex = 0 < bytesSkipped || 0 == bufferIndex
719 ? sourcePosition - bytesSkipped
722 const int bytesToCopy = bytesRemaining > buffer.
size() - startingIndex
723 ? buffer.
size() - startingIndex
726 stream.putArrayInt8(buffer.
data() + startingIndex, bytesToCopy);
731 bytesRemaining -= bytesToCopy;
780 const int TRIMMED_SIZE =
786 if ((dest->
totalSize() - TRIMMED_SIZE <= INT_MAX - lvalue.
size())
837 int bufferSize = lvalue.
size();
838 if ((dest->
totalSize() <= INT_MAX - bufferSize)
855, d_length(blob->length())
884 const BlobUtilAsciiDumper& rhs)
886 int offset = bsl::min(rhs.d_offset, rhs.d_blob_p->length());
887 int length = bsl::min(rhs.d_length, rhs.d_blob_p->length() - offset);
888 return BlobUtil::asciiDump(stream, *rhs.d_blob_p, offset, length);
902, d_length(blob->length())
929 const BlobUtilHexDumper& rhs)
931 int offset = bsl::min(rhs.d_offset, rhs.d_blob_p->length());
932 int length = bsl::min(rhs.d_length, rhs.d_blob_p->length() - offset);
933 return BlobUtil::hexDump(stream, *rhs.d_blob_p, offset, length);
Definition bdlbb_blob.h:616
Definition bdlbb_blob.h:455
bsl::shared_ptr< char > & buffer()
Definition bdlbb_blob.h:1094
char * data() const
Definition bdlbb_blob.h:1115
int size() const
Return the size of the buffer represented by this object.
Definition bdlbb_blob.h:1121
Definition bdlbb_blob.h:642
void prependDataBuffer(const BlobBuffer &buffer)
Definition bdlbb_blob.h:1171
int lastDataBufferLength() const
Definition bdlbb_blob.h:1214
int length() const
Return the length of this blob.
Definition bdlbb_blob.h:1220
int numDataBuffers() const
Return the number of blob buffers containing data in this blob.
Definition bdlbb_blob.h:1232
const BlobBuffer & buffer(int index) const
Definition bdlbb_blob.h:1199
void insertBuffer(int index, const BlobBuffer &buffer)
Definition bdlbb_blob.h:1164
int numBuffers() const
Return the number of blob buffers held by this blob.
Definition bdlbb_blob.h:1226
void appendDataBuffer(const BlobBuffer &buffer)
Definition bdlbb_blob.h:1157
void appendBuffer(const BlobBuffer &buffer)
Definition bdlbb_blob.h:1150
int totalSize() const
Definition bdlbb_blob.h:1238
void setLength(int length)
Definition bslstl_pair.h:1210
element_type * get() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_sharedptr.h:5574
Definition bslma_allocator.h:457
Definition bslmf_movableref.h:751
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlbb_blob.h:442
bsl::ostream & operator<<(bsl::ostream &stream, const BlobBuffer &buffer)
Definition bdlbb_blobutil.h:443
int d_offset
Definition bdlbb_blobutil.h:447
const Blob * d_blob_p
Definition bdlbb_blobutil.h:446
BlobUtilAsciiDumper(const Blob *blob)
Definition bdlbb_blobutil.h:852
int d_length
Definition bdlbb_blobutil.h:448
Definition bdlbb_blobutil.h:489
int d_length
Definition bdlbb_blobutil.h:494
BlobUtilHexDumper(const Blob *blob)
Definition bdlbb_blobutil.h:899
const Blob * d_blob_p
Definition bdlbb_blobutil.h:492
int d_offset
Definition bdlbb_blobutil.h:493
Definition bdlbb_blobutil.h:81
static int insertBufferIfValid(Blob *dest, int index, const BlobBuffer &buffer)
Definition bdlbb_blobutil.h:796
static char * getContiguousDataBuffer(Blob *blob, int addLength, BlobBufferFactory *factory)
static int appendBufferIfValid(Blob *dest, const BlobBuffer &buffer)
Definition bdlbb_blobutil.h:741
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:644
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:668
static int appendDataBufferIfValid(Blob *dest, const BlobBuffer &buffer)
Definition bdlbb_blobutil.h:763
static void padToAlignment(Blob *dest, int alignment, char fillChar='\0')
Definition bdlbb_blobutil.h:627
static bsl::ostream & hexDump(bsl::ostream &stream, const Blob &source)
Definition bdlbb_blobutil.h:621
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:824
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:1060