From af849fa314ad335e14c82a2018ee7d7bea91842a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 24 Apr 2023 10:04:33 -0700 Subject: Blob related changes throughout. --- src/stable/archivebase.cpp | 1 + src/stable/archivebase.h | 2 +- src/unstable/blob.cpp | 33 +++++++++++++++++++++++++++++++++ src/unstable/blob.h | 6 ++++++ src/unstable/settingsdriverini.cpp | 1 + src/unstable/settingsdrivertaf.cpp | 1 + 6 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/stable/archivebase.cpp b/src/stable/archivebase.cpp index d2d80a1..c1e886b 100644 --- a/src/stable/archivebase.cpp +++ b/src/stable/archivebase.cpp @@ -6,6 +6,7 @@ */ #include "bu/archivebase.h" +#include "bu/blob.h" Bu::ArchiveBase::ArchiveBase() { diff --git a/src/stable/archivebase.h b/src/stable/archivebase.h index d846c27..3fd5071 100644 --- a/src/stable/archivebase.h +++ b/src/stable/archivebase.h @@ -12,10 +12,10 @@ #include #include "bu/variant.h" -#include "bu/blob.h" namespace Bu { + class Blob; class ArchiveBase { public: diff --git a/src/unstable/blob.cpp b/src/unstable/blob.cpp index 23987f3..c4148e1 100644 --- a/src/unstable/blob.cpp +++ b/src/unstable/blob.cpp @@ -55,6 +55,14 @@ Bu::Blob::Blob( const void *pSrc, int32_t iSize ) : pData[iSize] = '\0'; } +Bu::Blob::Blob( int32_t iSize ) : + pData( 0 ), + iSize( iSize ) +{ + pData = new char[iSize+1]; + memset( pData, iSize+1, 1 ); +} + Bu::Blob::Blob( const Bu::Blob::const_iterator &iStart ) : pData( 0 ), iSize( 0 ) @@ -96,6 +104,14 @@ Bu::Blob::~Blob() iSize = 0; } +void Bu::Blob::setSize( int32_t iSize ) +{ + delete[] pData; + pData = new char[iSize+1]; + memset( pData, iSize, 1 ); + this->iSize = iSize; +} + int32_t Bu::Blob::getSize() const { return iSize; @@ -795,3 +811,20 @@ Bu::Formatter &Bu::operator<<( Bu::Formatter &rOut, const Bu::Blob &b ) return rOut; } +Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const Bu::Blob &b ) +{ + int32_t iSize = b.getSize(); + ar << iSize; + ar.write( b.getData(), iSize ); + return ar; +} + +Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, Bu::Blob &b ) +{ + int32_t iSize; + ar >> iSize; + b.setSize( iSize ); + ar.read( b.getData(), iSize ); + return ar; +} + diff --git a/src/unstable/blob.h b/src/unstable/blob.h index bda29d6..dfddb02 100644 --- a/src/unstable/blob.h +++ b/src/unstable/blob.h @@ -9,6 +9,7 @@ #define BU_BLOB_H #include "bu/config.h" +#include "bu/archivebase.h" namespace Bu { @@ -40,10 +41,12 @@ namespace Bu Blob( const class BlobBuilder &rSrc ); Blob( const char *pSrc ); Blob( const void *pSrc, int32_t iSize ); + Blob( int32_t iSize ); Blob( const const_iterator &iStart ); Blob( const const_iterator &iStart, const const_iterator &iEnd ); virtual ~Blob(); + void setSize( int32_t iSize ); int32_t getSize() const; char *getData() const; char *c_str() const; @@ -161,6 +164,9 @@ namespace Bu int32_t iSize; }; + ArchiveBase &operator<<( ArchiveBase &ar, const Blob &s ); + ArchiveBase &operator>>( ArchiveBase &ar, Blob &s ); + template uint32_t __calcHashCode( const T &k ); diff --git a/src/unstable/settingsdriverini.cpp b/src/unstable/settingsdriverini.cpp index 31bc146..751b63c 100644 --- a/src/unstable/settingsdriverini.cpp +++ b/src/unstable/settingsdriverini.cpp @@ -4,6 +4,7 @@ #include "bu/buffer.h" #include "bu/sio.h" +#include "bu/blob.h" #include diff --git a/src/unstable/settingsdrivertaf.cpp b/src/unstable/settingsdrivertaf.cpp index d99d0ba..b1077ec 100644 --- a/src/unstable/settingsdrivertaf.cpp +++ b/src/unstable/settingsdrivertaf.cpp @@ -2,6 +2,7 @@ #include "bu/file.h" #include "bu/taf.h" +#include "bu/blob.h" #include -- cgit v1.2.3