From 15e7ff10d3d6fe3570335a5abec5ff683c07e2e6 Mon Sep 17 00:00:00 2001 From: David Steele Date: Thu, 23 Sep 2021 08:31:32 -0400 Subject: [PATCH] Add Pack pseudo-type. Rather than working directly with Buffer types, define a new Pack pseudo-type that represents a Buffer containing a pack. This makes it clearer that a pack is being stored and allows stronger typing. --- src/build/help/render.c | 4 +- src/command/backup/pageChecksum.c | 30 ++++---- src/command/backup/pageChecksum.h | 2 +- src/common/compress/bz2/compress.c | 6 +- src/common/compress/gz/compress.c | 6 +- src/common/compress/helper.c | 10 +-- src/common/compress/helper.h | 2 +- src/common/compress/lz4/compress.c | 6 +- src/common/compress/zst/compress.c | 6 +- src/common/crypto/cipherBlock.c | 12 ++-- src/common/crypto/cipherBlock.h | 2 +- src/common/crypto/hash.c | 24 ++++--- src/common/crypto/hash.h | 2 +- src/common/io/filter/filter.c | 6 +- src/common/io/filter/filter.h | 5 +- src/common/io/filter/filter.intern.h | 10 +-- src/common/io/filter/group.c | 68 ++++++++++--------- src/common/io/filter/group.h | 9 +-- src/common/io/filter/size.c | 14 ++-- src/common/io/write.intern.h | 1 + src/common/type/pack.c | 98 ++++++++++++--------------- src/common/type/pack.h | 81 +++++++++++++++------- src/info/info.c | 4 +- src/protocol/client.c | 4 +- src/protocol/client.h | 2 +- src/protocol/command.c | 2 +- src/protocol/server.c | 8 +-- src/protocol/server.h | 2 +- src/storage/gcs/write.c | 2 +- src/storage/remote/protocol.c | 14 ++-- src/storage/remote/read.c | 2 +- src/storage/remote/write.c | 4 +- test/src/common/harnessInfo.c | 2 +- test/src/common/harnessPack.c | 14 ++-- test/src/common/harnessPack.h | 8 +-- test/src/module/build/helpTest.c | 2 +- test/src/module/command/backupTest.c | 2 +- test/src/module/common/compressTest.c | 4 +- test/src/module/common/cryptoTest.c | 14 ++-- test/src/module/common/ioTest.c | 42 +++++------- test/src/module/common/typePackTest.c | 22 +++--- test/src/module/storage/remoteTest.c | 10 +-- 42 files changed, 304 insertions(+), 264 deletions(-) diff --git a/src/build/help/render.c b/src/build/help/render.c index 671e7a5b2..1a148b645 100644 --- a/src/build/help/render.c +++ b/src/build/help/render.c @@ -123,7 +123,7 @@ Render help to a pack static PackWrite * bldHlpRenderHelpAutoCPack(const BldCfg bldCfg, const BldHlp bldHlp) { - PackWrite *const pack = pckWriteNewBuf(bufNew(65 * 1024)); + PackWrite *const pack = pckWriteNewP(.size = 65 * 1024); // Command help // ----------------------------------------------------------------------------------------------------------------------------- @@ -257,7 +257,7 @@ static Buffer * bldHlpRenderHelpAutoCCmp(const BldCfg bldCfg, const BldHlp bldHlp) { // Get pack buffer - const Buffer *const packBuf = pckWriteBuf(bldHlpRenderHelpAutoCPack(bldCfg, bldHlp)); + const Buffer *const packBuf = pckToBuf(pckWriteResult(bldHlpRenderHelpAutoCPack(bldCfg, bldHlp))); Buffer *const result = bufNew(bufSize(packBuf)); // Open source/destination diff --git a/src/command/backup/pageChecksum.c b/src/command/backup/pageChecksum.c index d1ab1ed1b..2d72cce50 100644 --- a/src/command/backup/pageChecksum.c +++ b/src/command/backup/pageChecksum.c @@ -146,7 +146,7 @@ pageChecksumProcess(THIS_VOID, const Buffer *input) /*********************************************************************************************************************************** Return filter result ***********************************************************************************************************************************/ -static Buffer * +static Pack * pageChecksumResult(THIS_VOID) { THIS(PageChecksum); @@ -157,7 +157,7 @@ pageChecksumResult(THIS_VOID) ASSERT(this != NULL); - Buffer *result = NULL; + Pack *result = NULL; MEM_CONTEXT_TEMP_BEGIN() { @@ -221,17 +221,16 @@ pageChecksumResult(THIS_VOID) kvPut(error, VARSTRDEF("valid"), VARBOOL(this->valid)); kvPut(error, VARSTRDEF("align"), VARBOOL(this->align)); - result = bufNew(PACK_EXTRA_MIN); - PackWrite *const write = pckWriteNewBuf(result); + PackWrite *const packWrite = pckWriteNewP(); - pckWriteStrP(write, jsonFromKv(error)); - pckWriteEndP(write); + pckWriteStrP(packWrite, jsonFromKv(error)); + pckWriteEndP(packWrite); - bufMove(result, memContextPrior()); + result = pckMove(pckWriteResult(packWrite), memContextPrior()); } MEM_CONTEXT_TEMP_END(); - FUNCTION_LOG_RETURN(BUFFER, result); + FUNCTION_LOG_RETURN(PACK, result); } /**********************************************************************************************************************************/ @@ -261,21 +260,22 @@ pageChecksumNew(unsigned int segmentNo, unsigned int segmentPageTotal, uint64_t }; // Create param list - Buffer *const paramList = bufNew(PACK_EXTRA_MIN); + Pack *paramList = NULL; MEM_CONTEXT_TEMP_BEGIN() { - PackWrite *const packWrite = pckWriteNewBuf(paramList); + PackWrite *const packWrite = pckWriteNewP(); pckWriteU32P(packWrite, segmentNo); pckWriteU32P(packWrite, segmentPageTotal); pckWriteU64P(packWrite, lsnLimit); pckWriteEndP(packWrite); + + paramList = pckMove(pckWriteResult(packWrite), memContextPrior()); } MEM_CONTEXT_TEMP_END(); - this = ioFilterNewP( - PAGE_CHECKSUM_FILTER_TYPE, driver, paramList, .in = pageChecksumProcess, .result = pageChecksumResult); + this = ioFilterNewP(PAGE_CHECKSUM_FILTER_TYPE, driver, paramList, .in = pageChecksumProcess, .result = pageChecksumResult); } OBJ_NEW_END(); @@ -283,18 +283,18 @@ pageChecksumNew(unsigned int segmentNo, unsigned int segmentPageTotal, uint64_t } IoFilter * -pageChecksumNewPack(const Buffer *const paramList) +pageChecksumNewPack(const Pack *const paramList) { IoFilter *result = NULL; MEM_CONTEXT_TEMP_BEGIN() { - PackRead *const paramListPack = pckReadNewBuf(paramList); + PackRead *const paramListPack = pckReadNew(paramList); const unsigned int segmentNo = pckReadU32P(paramListPack); const unsigned int segmentPageTotal = pckReadU32P(paramListPack); const uint64_t lsnLimit = pckReadU64P(paramListPack); - result = objMoveContext(pageChecksumNew(segmentNo, segmentPageTotal, lsnLimit), memContextPrior()); + result = ioFilterMove(pageChecksumNew(segmentNo, segmentPageTotal, lsnLimit), memContextPrior()); } MEM_CONTEXT_TEMP_END(); diff --git a/src/command/backup/pageChecksum.h b/src/command/backup/pageChecksum.h index 9291855a9..811bd0917 100644 --- a/src/command/backup/pageChecksum.h +++ b/src/command/backup/pageChecksum.h @@ -17,6 +17,6 @@ Filter type constant Constructors ***********************************************************************************************************************************/ IoFilter *pageChecksumNew(unsigned int segmentNo, unsigned int segmentPageTotal, uint64_t lsnLimit); -IoFilter *pageChecksumNewPack(const Buffer *paramList); +IoFilter *pageChecksumNewPack(const Pack *paramList); #endif diff --git a/src/common/compress/bz2/compress.c b/src/common/compress/bz2/compress.c index fb5da36ba..ee76e545a 100644 --- a/src/common/compress/bz2/compress.c +++ b/src/common/compress/bz2/compress.c @@ -183,14 +183,16 @@ bz2CompressNew(int level) memContextCallbackSet(objMemContext(driver), bz2CompressFreeResource, driver); // Create param list - Buffer *const paramList = bufNew(PACK_EXTRA_MIN); + Pack *paramList = NULL; MEM_CONTEXT_TEMP_BEGIN() { - PackWrite *const packWrite = pckWriteNewBuf(paramList); + PackWrite *const packWrite = pckWriteNewP(); pckWriteI32P(packWrite, level); pckWriteEndP(packWrite); + + paramList = pckMove(pckWriteResult(packWrite), memContextPrior()); } MEM_CONTEXT_TEMP_END(); diff --git a/src/common/compress/gz/compress.c b/src/common/compress/gz/compress.c index f2d162f2c..411f879f5 100644 --- a/src/common/compress/gz/compress.c +++ b/src/common/compress/gz/compress.c @@ -188,14 +188,16 @@ gzCompressNew(int level) memContextCallbackSet(objMemContext(driver), gzCompressFreeResource, driver); // Create param list - Buffer *const paramList = bufNew(PACK_EXTRA_MIN); + Pack *paramList = NULL; MEM_CONTEXT_TEMP_BEGIN() { - PackWrite *const packWrite = pckWriteNewBuf(paramList); + PackWrite *const packWrite = pckWriteNewP(); pckWriteI32P(packWrite, level); pckWriteEndP(packWrite); + + paramList = pckMove(pckWriteResult(packWrite), memContextPrior()); } MEM_CONTEXT_TEMP_END(); diff --git a/src/common/compress/helper.c b/src/common/compress/helper.c index 2511208bf..350e4de73 100644 --- a/src/common/compress/helper.c +++ b/src/common/compress/helper.c @@ -208,11 +208,11 @@ compressFilter(CompressType type, int level) /**********************************************************************************************************************************/ IoFilter * -compressFilterPack(const StringId filterType, const Buffer *const filterParamList) +compressFilterPack(const StringId filterType, const Pack *const filterParam) { FUNCTION_LOG_BEGIN(logLevelTrace); FUNCTION_LOG_PARAM(STRING_ID, filterType); - FUNCTION_LOG_PARAM(VARIANT_LIST, filterParamList); + FUNCTION_LOG_PARAM(VARIANT_LIST, filterParam); FUNCTION_LOG_END(); ASSERT(filterType != 0); @@ -227,14 +227,14 @@ compressFilterPack(const StringId filterType, const Buffer *const filterParamLis if (filterType == compress->compressType) { - ASSERT(filterParamList != NULL); + ASSERT(filterParam != NULL); - result = objMoveContext(compress->compressNew(pckReadI32P(pckReadNewBuf(filterParamList))), memContextPrior()); + result = ioFilterMove(compress->compressNew(pckReadI32P(pckReadNew(filterParam))), memContextPrior()); break; } else if (filterType == compress->decompressType) { - result = objMoveContext(compress->decompressNew(), memContextPrior()); + result = ioFilterMove(compress->decompressNew(), memContextPrior()); break; } } diff --git a/src/common/compress/helper.h b/src/common/compress/helper.h index a9488fa8f..c94a9b7bc 100644 --- a/src/common/compress/helper.h +++ b/src/common/compress/helper.h @@ -57,7 +57,7 @@ IoFilter *compressFilter(CompressType type, int level); // Compression/decompression filter based on string type and a parameter list. This is useful when a filter must be created on a // remote system since the filter type and parameters can be passed through a protocol. -IoFilter *compressFilterPack(StringId filterType, const Buffer *filterParamList); +IoFilter *compressFilterPack(StringId filterType, const Pack *filterParam); // Decompression filter for the specified type. Error when compress type is none or invalid. IoFilter *decompressFilter(CompressType type); diff --git a/src/common/compress/lz4/compress.c b/src/common/compress/lz4/compress.c index a2413abaf..5dd527151 100644 --- a/src/common/compress/lz4/compress.c +++ b/src/common/compress/lz4/compress.c @@ -271,14 +271,16 @@ lz4CompressNew(int level) memContextCallbackSet(objMemContext(driver), lz4CompressFreeResource, driver); // Create param list - Buffer *const paramList = bufNew(PACK_EXTRA_MIN); + Pack *paramList = NULL; MEM_CONTEXT_TEMP_BEGIN() { - PackWrite *const packWrite = pckWriteNewBuf(paramList); + PackWrite *const packWrite = pckWriteNewP(); pckWriteI32P(packWrite, level); pckWriteEndP(packWrite); + + paramList = pckMove(pckWriteResult(packWrite), memContextPrior()); } MEM_CONTEXT_TEMP_END(); diff --git a/src/common/compress/zst/compress.c b/src/common/compress/zst/compress.c index 237272536..f9a73f946 100644 --- a/src/common/compress/zst/compress.c +++ b/src/common/compress/zst/compress.c @@ -191,14 +191,16 @@ zstCompressNew(int level) zstError(ZSTD_initCStream(driver->context, driver->level)); // Create param list - Buffer *const paramList = bufNew(PACK_EXTRA_MIN); + Pack *paramList = NULL; MEM_CONTEXT_TEMP_BEGIN() { - PackWrite *const packWrite = pckWriteNewBuf(paramList); + PackWrite *const packWrite = pckWriteNewP(); pckWriteI32P(packWrite, level); pckWriteEndP(packWrite); + + paramList = pckMove(pckWriteResult(packWrite), memContextPrior()); } MEM_CONTEXT_TEMP_END(); diff --git a/src/common/crypto/cipherBlock.c b/src/common/crypto/cipherBlock.c index cca4dbf7c..6d4aac9fc 100644 --- a/src/common/crypto/cipherBlock.c +++ b/src/common/crypto/cipherBlock.c @@ -435,17 +435,19 @@ cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const memcpy(driver->pass, bufPtrConst(pass), driver->passSize); // Create param list - Buffer *const paramList = bufNew(PACK_EXTRA_MIN); + Pack *paramList = NULL; MEM_CONTEXT_TEMP_BEGIN() { - PackWrite *const packWrite = pckWriteNewBuf(paramList); + PackWrite *const packWrite = pckWriteNewP(); pckWriteU64P(packWrite, mode); pckWriteU64P(packWrite, cipherType); pckWriteBinP(packWrite, pass); pckWriteStrP(packWrite, digestName); pckWriteEndP(packWrite); + + paramList = pckMove(pckWriteResult(packWrite), memContextPrior()); } MEM_CONTEXT_TEMP_END(); @@ -460,19 +462,19 @@ cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const } IoFilter * -cipherBlockNewPack(const Buffer *const paramList) +cipherBlockNewPack(const Pack *const paramList) { IoFilter *result = NULL; MEM_CONTEXT_TEMP_BEGIN() { - PackRead *const paramListPack = pckReadNewBuf(paramList); + PackRead *const paramListPack = pckReadNew(paramList); const CipherMode cipherMode = (CipherMode)pckReadU64P(paramListPack); const CipherType cipherType = (CipherType)pckReadU64P(paramListPack); const Buffer *const pass = pckReadBinP(paramListPack); const String *const digestName = pckReadStrP(paramListPack); - result = objMoveContext(cipherBlockNew(cipherMode, cipherType, pass, digestName), memContextPrior()); + result = ioFilterMove(cipherBlockNew(cipherMode, cipherType, pass, digestName), memContextPrior()); } MEM_CONTEXT_TEMP_END(); diff --git a/src/common/crypto/cipherBlock.h b/src/common/crypto/cipherBlock.h index 6d284db22..8a6bed191 100644 --- a/src/common/crypto/cipherBlock.h +++ b/src/common/crypto/cipherBlock.h @@ -16,7 +16,7 @@ Filter type constant Constructors ***********************************************************************************************************************************/ IoFilter *cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const String *digestName); -IoFilter *cipherBlockNewPack(const Buffer *paramList); +IoFilter *cipherBlockNewPack(const Pack *paramList); /*********************************************************************************************************************************** Helper functions diff --git a/src/common/crypto/hash.c b/src/common/crypto/hash.c index 88db67afb..b22bf1758 100644 --- a/src/common/crypto/hash.c +++ b/src/common/crypto/hash.c @@ -142,7 +142,7 @@ cryptoHash(CryptoHash *this) /*********************************************************************************************************************************** Get string representation of the hash as a filter result ***********************************************************************************************************************************/ -static Buffer * +static Pack * cryptoHashResult(THIS_VOID) { THIS(CryptoHash); @@ -153,18 +153,20 @@ cryptoHashResult(THIS_VOID) ASSERT(this != NULL); - Buffer *const result = bufNew(PACK_EXTRA_MIN); + Pack *result = NULL; MEM_CONTEXT_TEMP_BEGIN() { - PackWrite *const pack = pckWriteNewBuf(result); + PackWrite *const packWrite = pckWriteNewP(); - pckWriteStrP(pack, bufHex(cryptoHash(this))); - pckWriteEndP(pack); + pckWriteStrP(packWrite, bufHex(cryptoHash(this))); + pckWriteEndP(packWrite); + + result = pckMove(pckWriteResult(packWrite), memContextPrior()); } MEM_CONTEXT_TEMP_END(); - FUNCTION_LOG_RETURN(BUFFER, result); + FUNCTION_LOG_RETURN(PACK, result); } /**********************************************************************************************************************************/ @@ -215,14 +217,16 @@ cryptoHashNew(const String *type) } // Create param list - Buffer *const paramList = bufNew(PACK_EXTRA_MIN); + Pack *paramList = NULL; MEM_CONTEXT_TEMP_BEGIN() { - PackWrite *const packWrite = pckWriteNewBuf(paramList); + PackWrite *const packWrite = pckWriteNewP(); pckWriteStrP(packWrite, type); pckWriteEndP(packWrite); + + paramList = pckMove(pckWriteResult(packWrite), memContextPrior()); } MEM_CONTEXT_TEMP_END(); @@ -235,13 +239,13 @@ cryptoHashNew(const String *type) } IoFilter * -cryptoHashNewPack(const Buffer *const paramList) +cryptoHashNewPack(const Pack *const paramList) { IoFilter *result = NULL; MEM_CONTEXT_TEMP_BEGIN() { - result = objMoveContext(cryptoHashNew(pckReadStrP(pckReadNewBuf(paramList))), memContextPrior()); + result = ioFilterMove(cryptoHashNew(pckReadStrP(pckReadNew(paramList))), memContextPrior()); } MEM_CONTEXT_TEMP_END(); diff --git a/src/common/crypto/hash.h b/src/common/crypto/hash.h index 98490afd9..27ea7d2d4 100644 --- a/src/common/crypto/hash.h +++ b/src/common/crypto/hash.h @@ -50,7 +50,7 @@ Hash type sizes Constructors ***********************************************************************************************************************************/ IoFilter *cryptoHashNew(const String *type); -IoFilter *cryptoHashNewPack(const Buffer *paramList); +IoFilter *cryptoHashNewPack(const Pack *paramList); /*********************************************************************************************************************************** Helper functions diff --git a/src/common/io/filter/filter.c b/src/common/io/filter/filter.c index ab682349a..4344051bc 100644 --- a/src/common/io/filter/filter.c +++ b/src/common/io/filter/filter.c @@ -21,12 +21,12 @@ struct IoFilter Allocations will be in the memory context of the caller. ***********************************************************************************************************************************/ IoFilter * -ioFilterNew(const StringId type, void *const driver, Buffer *const paramList, const IoFilterInterface interface) +ioFilterNew(const StringId type, void *const driver, Pack *const paramList, const IoFilterInterface interface) { FUNCTION_LOG_BEGIN(logLevelTrace); FUNCTION_LOG_PARAM(STRING_ID, type); FUNCTION_LOG_PARAM_P(VOID, driver); - FUNCTION_LOG_PARAM(BUFFER, paramList); + FUNCTION_LOG_PARAM(PACK, paramList); FUNCTION_LOG_PARAM(IO_FILTER_INTERFACE, interface); FUNCTION_LOG_END(); @@ -139,7 +139,7 @@ ioFilterInputSame(const IoFilter *this) } /**********************************************************************************************************************************/ -Buffer * +Pack * ioFilterResult(const IoFilter *this) { FUNCTION_TEST_BEGIN(); diff --git a/src/common/io/filter/filter.h b/src/common/io/filter/filter.h index 080ad4354..000a80b8a 100644 --- a/src/common/io/filter/filter.h +++ b/src/common/io/filter/filter.h @@ -18,14 +18,13 @@ typedef struct IoFilter IoFilter; #include "common/io/filter/filter.intern.h" #include "common/type/object.h" -#include "common/type/string.h" -#include "common/type/variant.h" +#include "common/type/pack.h" /*********************************************************************************************************************************** Getters/Setters ***********************************************************************************************************************************/ // Get filter result -Buffer *ioFilterResult(const IoFilter *this); +Pack *ioFilterResult(const IoFilter *this); // Identifies the filter and is used when pulling results from the filter group __attribute__((always_inline)) static inline StringId diff --git a/src/common/io/filter/filter.intern.h b/src/common/io/filter/filter.intern.h index 8ee7ce2e0..53fcf472d 100644 --- a/src/common/io/filter/filter.intern.h +++ b/src/common/io/filter/filter.intern.h @@ -18,6 +18,8 @@ Each filter has a type that allows it to be identified in the filter list. #ifndef COMMON_IO_FILTER_FILTER_INTERN_H #define COMMON_IO_FILTER_FILTER_INTERN_H +#include "common/type/buffer.h" +#include "common/type/pack.h" #include "common/type/stringId.h" /*********************************************************************************************************************************** @@ -46,13 +48,13 @@ typedef struct IoFilterInterface // If the filter produces a result then this function must be implemented to return the result. A result can be anything that // is not processed output, e.g. a count of total bytes or a cryptographic hash. The returned buffer must be a pack containing // the result. - Buffer *(*result)(void *driver); + Pack *(*result)(void *driver); } IoFilterInterface; #define ioFilterNewP(type, driver, paramList, ...) \ ioFilterNew(type, driver, paramList, (IoFilterInterface){__VA_ARGS__}) -IoFilter *ioFilterNew(StringId type, void *driver, Buffer *paramList, IoFilterInterface); +IoFilter *ioFilterNew(StringId type, void *driver, Pack *paramList, IoFilterInterface); /*********************************************************************************************************************************** Getters/Setters @@ -63,7 +65,7 @@ typedef struct IoFilterPub StringId type; // Filter type IoFilterInterface interface; // Filter interface void *driver; // Filter driver - const Buffer *paramList; // Filter parameters + const Pack *paramList; // Filter parameters } IoFilterPub; // Is the filter done? @@ -95,7 +97,7 @@ ioFilterOutput(const IoFilter *const this) } // List of filter parameters -__attribute__((always_inline)) static inline const Buffer * +__attribute__((always_inline)) static inline const Pack * ioFilterParamList(const IoFilter *const this) { return THIS_PUB(IoFilter)->paramList; diff --git a/src/common/io/filter/group.c b/src/common/io/filter/group.c index 15572c6a5..60c3f7520 100644 --- a/src/common/io/filter/group.c +++ b/src/common/io/filter/group.c @@ -38,7 +38,7 @@ Filter results typedef struct IoFilterResult { StringId type; // Filter type - Buffer *result; // Filter result + Pack *result; // Filter result } IoFilterResult; /*********************************************************************************************************************************** @@ -385,7 +385,7 @@ ioFilterGroupClose(IoFilterGroup *this) } /**********************************************************************************************************************************/ -Buffer * +Pack * ioFilterGroupParamAll(const IoFilterGroup *this) { FUNCTION_LOG_BEGIN(logLevelDebug); @@ -396,27 +396,27 @@ ioFilterGroupParamAll(const IoFilterGroup *this) ASSERT(!this->pub.opened); ASSERT(this->pub.filterList != NULL); - Buffer *result = NULL; + Pack *result = NULL; MEM_CONTEXT_TEMP_BEGIN() { - result = bufNew(PACK_EXTRA_MIN); - PackWrite *const pack = pckWriteNewBuf(result); + PackWrite *const packWrite = pckWriteNewP(); for (unsigned int filterIdx = 0; filterIdx < ioFilterGroupSize(this); filterIdx++) { IoFilter *filter = ioFilterGroupGet(this, filterIdx)->filter; - pckWriteStrIdP(pack, ioFilterType(filter)); - pckWritePackBufP(pack, ioFilterParamList(filter)); + pckWriteStrIdP(packWrite, ioFilterType(filter)); + pckWritePackP(packWrite, ioFilterParamList(filter)); } - pckWriteEndP(pack); - bufMove(result, memContextPrior()); + pckWriteEndP(packWrite); + + result = pckMove(pckWriteResult(packWrite), memContextPrior()); } MEM_CONTEXT_TEMP_END(); - FUNCTION_LOG_RETURN(BUFFER, result); + FUNCTION_LOG_RETURN(PACK, result); } /**********************************************************************************************************************************/ @@ -447,7 +447,7 @@ ioFilterGroupResult(const IoFilterGroup *const this, const StringId filterType, // If the index matches return the result if (foundIdx == param.idx) { - result = pckReadNewBuf(filterResult->result); + result = pckReadNew(filterResult->result); break; } @@ -460,7 +460,7 @@ ioFilterGroupResult(const IoFilterGroup *const this, const StringId filterType, } /**********************************************************************************************************************************/ -PackWrite * +Pack * ioFilterGroupResultAll(const IoFilterGroup *const this) { FUNCTION_LOG_BEGIN(logLevelDebug); @@ -470,57 +470,61 @@ ioFilterGroupResultAll(const IoFilterGroup *const this) ASSERT(this != NULL); ASSERT(this->pub.closed); - PackWrite *result = NULL; + Pack *result = NULL; // Pack the result list MEM_CONTEXT_TEMP_BEGIN() { - Buffer *const buffer = bufNew(0); - result = pckWriteNewBuf(buffer); + PackWrite *const packWrite = pckWriteNewP(); for (unsigned int filterResultIdx = 0; filterResultIdx < lstSize(this->filterResult); filterResultIdx++) { const IoFilterResult *const filterResult = lstGet(this->filterResult, filterResultIdx); - pckWriteStrIdP(result, filterResult->type); - pckWritePackBufP(result, filterResult->result); + pckWriteStrIdP(packWrite, filterResult->type); + pckWritePackP(packWrite, filterResult->result); } - pckWriteEndP(result); + pckWriteEndP(packWrite); - pckWriteMove(result, memContextPrior()); - bufMove(buffer, memContextPrior()); + result = pckMove(pckWriteResult(packWrite), memContextPrior()); } MEM_CONTEXT_TEMP_END(); - FUNCTION_LOG_RETURN(PACK_WRITE, result); + FUNCTION_LOG_RETURN(PACK, result); } /**********************************************************************************************************************************/ void -ioFilterGroupResultAllSet(IoFilterGroup *const this, PackRead *const filterResultPack) +ioFilterGroupResultAllSet(IoFilterGroup *const this, const Pack *const filterResultPack) { FUNCTION_LOG_BEGIN(logLevelDebug); FUNCTION_LOG_PARAM(IO_FILTER_GROUP, this); - FUNCTION_LOG_PARAM(PACK_READ, filterResultPack); + FUNCTION_LOG_PARAM(PACK, filterResultPack); FUNCTION_LOG_END(); ASSERT(this != NULL); if (filterResultPack != NULL) { - // Unpack the results into a list - MEM_CONTEXT_BEGIN(lstMemContext(this->filterResult)) - { - while (!pckReadNullP(filterResultPack)) - { - const StringId type = pckReadStrIdP(filterResultPack); - Buffer *const result = pckReadPackBufP(filterResultPack); + PackRead *const packRead = pckReadNew(filterResultPack); - lstAdd(this->filterResult, &(IoFilterResult){.type = type, .result = result}); + // Unpack the results into a list + MEM_CONTEXT_TEMP_BEGIN() + { + MEM_CONTEXT_BEGIN(lstMemContext(this->filterResult)) + { + while (!pckReadNullP(packRead)) + { + const StringId type = pckReadStrIdP(packRead); + Pack *const result = pckReadPackP(packRead); + + lstAdd(this->filterResult, &(IoFilterResult){.type = type, .result = result}); + } } + MEM_CONTEXT_END(); } - MEM_CONTEXT_END(); + MEM_CONTEXT_TEMP_END(); } FUNCTION_LOG_RETURN_VOID(); diff --git a/src/common/io/filter/group.h b/src/common/io/filter/group.h index 878482b11..77b161b0e 100644 --- a/src/common/io/filter/group.h +++ b/src/common/io/filter/group.h @@ -16,9 +16,10 @@ Object type typedef struct IoFilterGroup IoFilterGroup; #include "common/io/filter/filter.h" +#include "common/type/list.h" #include "common/type/object.h" #include "common/type/pack.h" -#include "common/type/string.h" +#include "common/type/stringId.h" /*********************************************************************************************************************************** Constructors @@ -58,7 +59,7 @@ ioFilterGroupInputSame(const IoFilterGroup *const this) } // Get all filters and their parameters so they can be passed to a remote -Buffer *ioFilterGroupParamAll(const IoFilterGroup *this); +Pack *ioFilterGroupParamAll(const IoFilterGroup *this); // Get filter results. If the same filter was used more than once then idx can be used to specify which one to get. typedef struct IoFilterGroupResultParam @@ -73,8 +74,8 @@ typedef struct IoFilterGroupResultParam PackRead *ioFilterGroupResult(const IoFilterGroup *this, StringId filterType, IoFilterGroupResultParam param); // Get/set all filter results -PackWrite *ioFilterGroupResultAll(const IoFilterGroup *this); -void ioFilterGroupResultAllSet(IoFilterGroup *this, PackRead *filterResult); +Pack *ioFilterGroupResultAll(const IoFilterGroup *this); +void ioFilterGroupResultAllSet(IoFilterGroup *this, const Pack *filterResult); // Return total number of filters __attribute__((always_inline)) static inline unsigned int diff --git a/src/common/io/filter/size.c b/src/common/io/filter/size.c index 74d41d3b3..48a89b475 100644 --- a/src/common/io/filter/size.c +++ b/src/common/io/filter/size.c @@ -58,7 +58,7 @@ ioSizeProcess(THIS_VOID, const Buffer *input) /*********************************************************************************************************************************** Return filter result ***********************************************************************************************************************************/ -static Buffer * +static Pack * ioSizeResult(THIS_VOID) { THIS(IoSize); @@ -69,18 +69,20 @@ ioSizeResult(THIS_VOID) ASSERT(this != NULL); - Buffer *const result = bufNew(PACK_EXTRA_MIN); + Pack *result = NULL; MEM_CONTEXT_TEMP_BEGIN() { - PackWrite *const pack = pckWriteNewBuf(result); + PackWrite *const packWrite = pckWriteNewP(); - pckWriteU64P(pack, this->size); - pckWriteEndP(pack); + pckWriteU64P(packWrite, this->size); + pckWriteEndP(packWrite); + + result = pckMove(pckWriteResult(packWrite), memContextPrior()); } MEM_CONTEXT_TEMP_END(); - FUNCTION_LOG_RETURN(BUFFER, result); + FUNCTION_LOG_RETURN(PACK, result); } /**********************************************************************************************************************************/ diff --git a/src/common/io/write.intern.h b/src/common/io/write.intern.h index e62a35890..d9239c05c 100644 --- a/src/common/io/write.intern.h +++ b/src/common/io/write.intern.h @@ -5,6 +5,7 @@ IO Write Interface Internal #define COMMON_IO_WRITE_INTERN_H #include "common/io/write.h" +#include "common/type/buffer.h" /*********************************************************************************************************************************** Constructors diff --git a/src/common/type/pack.c b/src/common/type/pack.c index e337d0c0e..3ea62224d 100644 --- a/src/common/type/pack.c +++ b/src/common/type/pack.c @@ -300,18 +300,18 @@ pckReadNewIo(IoRead *read) } PackRead * -pckReadNewBuf(const Buffer *buffer) +pckReadNew(const Pack *const pack) { FUNCTION_TEST_BEGIN(); - FUNCTION_TEST_PARAM(BUFFER, buffer); + FUNCTION_TEST_PARAM(PACK, pack); FUNCTION_TEST_END(); - if (buffer == NULL) + if (pack == NULL) FUNCTION_TEST_RETURN(NULL); PackRead *this = pckReadNewInternal(); - this->bufferPtr = bufPtrConst(buffer); - this->bufferUsed = bufUsed(buffer); + this->bufferPtr = bufPtrConst((const Buffer *)pack); + this->bufferUsed = bufUsed((const Buffer *)pack); FUNCTION_TEST_RETURN(this); } @@ -873,24 +873,24 @@ pckReadObjEnd(PackRead *this) /**********************************************************************************************************************************/ PackRead * -pckReadPack(PackRead *this, PckReadPackParam param) +pckReadPackRead(PackRead *this, PckReadPackParam param) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM(PACK_READ, this); FUNCTION_TEST_PARAM(UINT, param.id); FUNCTION_TEST_END(); - Buffer *const buffer = pckReadPackBuf(this, param); - PackRead *const result = pckReadNewBuf(buffer); + Pack *const pack = pckReadPack(this, param); + PackRead *const result = pckReadNew(pack); if (result != NULL) - bufMove(buffer, objMemContext(result)); + pckMove(pack, objMemContext(result)); FUNCTION_TEST_RETURN(result); } -Buffer * -pckReadPackBuf(PackRead *this, PckReadPackParam param) +Pack * +pckReadPack(PackRead *const this, PckReadPackParam param) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM(PACK_READ, this); @@ -916,7 +916,7 @@ pckReadPackBuf(PackRead *this, PckReadPackParam param) this->bufferPos += size; } - FUNCTION_TEST_RETURN(result); + FUNCTION_TEST_RETURN((Pack *)result); } /**********************************************************************************************************************************/ @@ -1134,6 +1134,24 @@ pckWriteNewInternal(void) FUNCTION_TEST_RETURN(this); } +PackWrite * +pckWriteNew(const PckWriteNewParam param) +{ + FUNCTION_TEST_BEGIN(); + FUNCTION_TEST_PARAM(SIZE, param.size); + FUNCTION_TEST_END(); + + PackWrite *this = pckWriteNewInternal(); + + MEM_CONTEXT_BEGIN(objMemContext(this)) + { + this->buffer = bufNew(param.size == 0 ? PACK_EXTRA_MIN : param.size); + } + MEM_CONTEXT_END(); + + FUNCTION_TEST_RETURN(this); +} + PackWrite * pckWriteNewIo(IoWrite *write) { @@ -1155,21 +1173,6 @@ pckWriteNewIo(IoWrite *write) FUNCTION_TEST_RETURN(this); } -PackWrite * -pckWriteNewBuf(Buffer *buffer) -{ - FUNCTION_TEST_BEGIN(); - FUNCTION_TEST_PARAM(BUFFER, buffer); - FUNCTION_TEST_END(); - - ASSERT(buffer != NULL); - - PackWrite *this = pckWriteNewInternal(); - this->buffer = buffer; - - FUNCTION_TEST_RETURN(this); -} - /*********************************************************************************************************************************** Write to io or buffer ***********************************************************************************************************************************/ @@ -1609,25 +1612,7 @@ pckWriteObjEnd(PackWrite *this) /**********************************************************************************************************************************/ PackWrite * -pckWritePack(PackWrite *this, const PackWrite *value, PckWritePackParam param) -{ - FUNCTION_TEST_BEGIN(); - FUNCTION_TEST_PARAM(PACK_WRITE, this); - FUNCTION_TEST_PARAM(PACK_WRITE, value); - FUNCTION_TEST_PARAM(UINT, param.id); - FUNCTION_TEST_PARAM(BOOL, param.defaultWrite); - FUNCTION_TEST_END(); - - ASSERT(this != NULL); - - pckWritePackBuf(this, value != NULL ? pckWriteBuf(value) : NULL, param); - - FUNCTION_TEST_RETURN(this); -} - -/**********************************************************************************************************************************/ -PackWrite * -pckWritePackBuf(PackWrite *this, const Buffer *value, PckWritePackParam param) +pckWritePack(PackWrite *const this, const Pack *const value, const PckWritePackParam param) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM(PACK_WRITE, this); @@ -1641,10 +1626,9 @@ pckWritePackBuf(PackWrite *this, const Buffer *value, PckWritePackParam param) { ASSERT(value != NULL); - // Write pack buffer pckWriteTag(this, pckTypeMapPack, param.id, 0); - pckWriteU64Internal(this, bufUsed(value)); - pckWriteBuffer(this, value); + pckWriteU64Internal(this, bufUsed((Buffer *)value)); + pckWriteBuffer(this, (Buffer *)value); } FUNCTION_TEST_RETURN(this); @@ -1834,17 +1818,23 @@ pckWriteEnd(PackWrite *this) } /**********************************************************************************************************************************/ -const Buffer * -pckWriteBuf(const PackWrite *this) +Pack * +pckWriteResult(PackWrite *const this) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM(PACK_WRITE, this); FUNCTION_TEST_END(); - ASSERT(this != NULL); - ASSERT(this->tagStackTop == NULL); + Pack *result = NULL; - FUNCTION_TEST_RETURN(this->buffer); + if (this != NULL) + { + ASSERT(this->tagStackTop == NULL); + + result = (Pack *)this->buffer; + } + + FUNCTION_TEST_RETURN(result); } /**********************************************************************************************************************************/ diff --git a/src/common/type/pack.h b/src/common/type/pack.h index 5bf4fa2a3..5fb247459 100644 --- a/src/common/type/pack.h +++ b/src/common/type/pack.h @@ -35,7 +35,7 @@ containers. Fields contain data to be stored, e.g. integers, strings, etc. Here is a simple example of a pack: -PackWrite *write = pckWriteNewBuf(buffer); +PackWrite *write = pckWriteNewP(); pckWriteU64P(write, 77); pckWriteBoolP(write, false, .defaultWrite = true); pckWriteI32P(write, -1, .defaultValue = -1); @@ -48,7 +48,7 @@ default. Note that there is a gap in the ID stream, which represents the NULL/de This pack can be read with: -PackRead *read = pckReadNewBuf(buffer); +PackRead *read = pckReadNew(pack); pckReadU64P(read); pckReadBoolP(read); pckReadI32P(read, .defaultValue = -1); @@ -60,7 +60,7 @@ applied again when reading by setting .defaultValue if the default value is not If we don't care about the NULL/default, another way to read is: -PackRead *read = pckReadNewBuf(buffer); +PackRead *read = pckReadNew(pack); pckReadU64P(read); pckReadBoolP(read); pckReadStringP(read, .id = 4); @@ -100,6 +100,7 @@ Minimum number of extra bytes to allocate for packs that are growing or are like /*********************************************************************************************************************************** Object types ***********************************************************************************************************************************/ +typedef struct Pack Pack; typedef struct PackRead PackRead; typedef struct PackWrite PackWrite; @@ -107,6 +108,7 @@ typedef struct PackWrite PackWrite; #include "common/io/write.h" #include "common/type/object.h" #include "common/type/stringId.h" +#include "common/type/stringList.h" /*********************************************************************************************************************************** Pack data type @@ -129,13 +131,37 @@ typedef enum pckTypeU64 = STRID6("u64", 0x208951), } PackType; +/*********************************************************************************************************************************** +Pack Functions +***********************************************************************************************************************************/ +// Cast Buffer to Pack +__attribute__((always_inline)) static inline const Pack * +pckFromBuf(const Buffer *const buffer) +{ + return (const Pack *)buffer; +} + +// Move to a new parent mem context +__attribute__((always_inline)) static inline Pack * +pckMove(Pack *const this, MemContext *const parentNew) +{ + return (Pack *)bufMove((Buffer *)this, parentNew); +} + +// Cast Pack to Buffer +__attribute__((always_inline)) static inline const Buffer * +pckToBuf(const Pack *const pack) +{ + return (const Buffer *)pack; +} + /*********************************************************************************************************************************** Read Constructors ***********************************************************************************************************************************/ -PackRead *pckReadNewIo(IoRead *read); +// Note that the pack is not moved into the PackRead mem context and must be moved explicitly if the PackRead object is moved. +PackRead *pckReadNew(const Pack *pack); -// Note that the buffer is not moved into the PackRead mem context and must be moved explicitly if the PackRead object is moved. -PackRead *pckReadNewBuf(const Buffer *buffer); +PackRead *pckReadNewIo(IoRead *read); /*********************************************************************************************************************************** Read Functions @@ -263,16 +289,16 @@ typedef struct PckReadPackParam unsigned int id; } PckReadPackParam; -#define pckReadPackP(this, ...) \ - pckReadPack(this, (PckReadPackParam){VAR_PARAM_INIT, __VA_ARGS__}) +#define pckReadPackReadP(this, ...) \ + pckReadPackRead(this, (PckReadPackParam){VAR_PARAM_INIT, __VA_ARGS__}) -PackRead *pckReadPack(PackRead *this, PckReadPackParam param); +PackRead *pckReadPackRead(PackRead *this, PckReadPackParam param); // Read pack buffer -#define pckReadPackBufP(this, ...) \ - pckReadPackBuf(this, (PckReadPackParam){VAR_PARAM_INIT, __VA_ARGS__}) +#define pckReadPackP(this, ...) \ + pckReadPack(this, (PckReadPackParam){VAR_PARAM_INIT, __VA_ARGS__}) -Buffer *pckReadPackBuf(PackRead *this, PckReadPackParam param); +Pack *pckReadPack(PackRead *this, PckReadPackParam param); // Read pointer. Use with extreme caution. Pointers cannot be sent to another host -- they must only be used locally. typedef struct PckReadPtrParam @@ -381,10 +407,18 @@ pckReadFree(PackRead *const this) /*********************************************************************************************************************************** Write Constructors ***********************************************************************************************************************************/ -PackWrite *pckWriteNewIo(IoWrite *write); +typedef struct PckWriteNewParam +{ + VAR_PARAM_HEADER; + size_t size; +} PckWriteNewParam; -// Note that the buffer is not moved into the PackWrite mem context and must be moved explicitly if the PackWrite object is moved. -PackWrite *pckWriteNewBuf(Buffer *buffer); +#define pckWriteNewP(...) \ + pckWriteNew((PckWriteNewParam){VAR_PARAM_INIT, __VA_ARGS__}) + +PackWrite *pckWriteNew(PckWriteNewParam param); + +PackWrite *pckWriteNewIo(IoWrite *write); /*********************************************************************************************************************************** Write Functions @@ -503,13 +537,7 @@ typedef struct PckWritePackParam #define pckWritePackP(this, value, ...) \ pckWritePack(this, value, (PckWritePackParam){VAR_PARAM_INIT, __VA_ARGS__}) -PackWrite *pckWritePack(PackWrite *this, const PackWrite *value, PckWritePackParam param); - -// Write pack buffer -#define pckWritePackBufP(this, value, ...) \ - pckWritePackBuf(this, value, (PckWritePackParam){VAR_PARAM_INIT, __VA_ARGS__}) - -PackWrite *pckWritePackBuf(PackWrite *this, const Buffer *value, PckWritePackParam param); +PackWrite *pckWritePack(PackWrite *this, const Pack *value, PckWritePackParam param); // Write pointer. Use with extreme caution. Pointers cannot be sent to another host -- they must only be used locally. typedef struct PckWritePtrParam @@ -615,9 +643,9 @@ PackWrite *pckWriteEnd(PackWrite *this); /*********************************************************************************************************************************** Write Getters/Setters ***********************************************************************************************************************************/ -// Get buffer the pack is writing to (returns NULL if pckWriteNewBuf() was not used to construct the object). This function is only +// Get Pack the PackWrite was writing to (returns NULL if pckWriteNew() was not used to construct the object). This function is only // valid after pckWriteEndP() has been called. -const Buffer *pckWriteBuf(const PackWrite *this); +Pack *pckWriteResult(PackWrite *this); /*********************************************************************************************************************************** Write Destructor @@ -631,6 +659,11 @@ pckWriteFree(PackWrite *const this) /*********************************************************************************************************************************** Macros for function logging ***********************************************************************************************************************************/ +#define FUNCTION_LOG_PACK_TYPE \ + Pack * +#define FUNCTION_LOG_PACK_FORMAT(value, buffer, bufferSize) \ + objToLog(value, "Pack", buffer, bufferSize) + String *pckReadToLog(const PackRead *this); #define FUNCTION_LOG_PACK_READ_TYPE \ diff --git a/src/info/info.c b/src/info/info.c index d93139a50..ea4161562 100644 --- a/src/info/info.c +++ b/src/info/info.c @@ -300,7 +300,7 @@ infoNewLoad(IoRead *read, InfoLoadNewCallback *callbackFunction, void *callbackD INFO_CHECKSUM_END(data.checksumActual); // Verify the checksum - const String *checksumActual = pckReadStrP(pckReadNewBuf(ioFilterResult(data.checksumActual))); + const String *checksumActual = pckReadStrP(pckReadNew(ioFilterResult(data.checksumActual))); if (data.checksumExpected == NULL) THROW_FMT(ChecksumError, "invalid checksum, actual '%s' but no checksum found", strZ(checksumActual)); @@ -435,7 +435,7 @@ infoSave(Info *this, IoWrite *write, InfoSaveCallback *callbackFunction, void *c INFO_CHECKSUM_END(data.checksum); ioWrite(data.write, BUFSTRDEF("\n[" INFO_SECTION_BACKREST "]\n" INFO_KEY_CHECKSUM "=")); - ioWriteLine(data.write, BUFSTR(jsonFromStr(pckReadStrP(pckReadNewBuf(ioFilterResult(data.checksum)))))); + ioWriteLine(data.write, BUFSTR(jsonFromStr(pckReadStrP(pckReadNew(ioFilterResult(data.checksum)))))); // Close the file ioWriteClose(data.write); diff --git a/src/protocol/client.c b/src/protocol/client.c index f2b18117b..cadb7c5f2 100644 --- a/src/protocol/client.c +++ b/src/protocol/client.c @@ -154,7 +154,7 @@ protocolClientDataPut(ProtocolClient *const this, PackWrite *const data) // Write the data PackWrite *dataMessage = pckWriteNewIo(this->write); pckWriteU32P(dataMessage, protocolMessageTypeData, .defaultWrite = true); - pckWritePackP(dataMessage, data); + pckWritePackP(dataMessage, pckWriteResult(data)); pckWriteEndP(dataMessage); // Flush when there is no more data to put @@ -226,7 +226,7 @@ protocolClientDataGet(ProtocolClient *const this) MEM_CONTEXT_PRIOR_BEGIN() { - result = pckReadPackP(response); + result = pckReadPackReadP(response); } MEM_CONTEXT_PRIOR_END(); diff --git a/src/protocol/client.h b/src/protocol/client.h index 371a58877..20ee39c53 100644 --- a/src/protocol/client.h +++ b/src/protocol/client.h @@ -55,7 +55,7 @@ be added to the expected binary size to account for overhead. __attribute__((always_inline)) static inline PackWrite * protocolPackNew(void) { - return pckWriteNewBuf(bufNew(PROTOCOL_PACK_DEFAULT_SIZE)); + return pckWriteNewP(.size = PROTOCOL_PACK_DEFAULT_SIZE); } /*********************************************************************************************************************************** diff --git a/src/protocol/command.c b/src/protocol/command.c index 6efc5b562..6e4a82a3b 100644 --- a/src/protocol/command.c +++ b/src/protocol/command.c @@ -66,7 +66,7 @@ protocolCommandPut(ProtocolCommand *const this, IoWrite *const write) if (this->pack != NULL) { pckWriteEndP(this->pack); - pckWritePackP(commandPack, this->pack); + pckWritePackP(commandPack, pckWriteResult(this->pack)); } pckWriteEndP(commandPack); diff --git a/src/protocol/server.c b/src/protocol/server.c index c6e4ea3d4..284c30b85 100644 --- a/src/protocol/server.c +++ b/src/protocol/server.c @@ -124,7 +124,7 @@ protocolServerCommandGet(ProtocolServer *const this) MEM_CONTEXT_PRIOR_BEGIN() { result.id = pckReadStrIdP(command); - result.param = pckReadPackBufP(command); + result.param = pckReadPackP(command); } MEM_CONTEXT_PRIOR_END(); @@ -194,7 +194,7 @@ protocolServerProcess( TRY_BEGIN() { - handler(pckReadNewBuf(command.param), this); + handler(pckReadNew(command.param), this); } CATCH_ANY() { @@ -291,7 +291,7 @@ protocolServerDataGet(ProtocolServer *const this) MEM_CONTEXT_PRIOR_BEGIN() { - result = pckReadPackP(data); + result = pckReadPackReadP(data); } MEM_CONTEXT_PRIOR_END(); @@ -320,7 +320,7 @@ protocolServerDataPut(ProtocolServer *const this, PackWrite *const data) // Write the result PackWrite *resultMessage = pckWriteNewIo(this->write); pckWriteU32P(resultMessage, protocolMessageTypeData, .defaultWrite = true); - pckWritePackP(resultMessage, data); + pckWritePackP(resultMessage, pckWriteResult(data)); pckWriteEndP(resultMessage); // Flush on NULL result since it might be used to synchronize diff --git a/src/protocol/server.h b/src/protocol/server.h index 35902db4c..a770391a0 100644 --- a/src/protocol/server.h +++ b/src/protocol/server.h @@ -45,7 +45,7 @@ Functions typedef struct ProtocolServerCommandGetResult { StringId id; // Command identifier - Buffer *param; // Parameter pack + Pack *param; // Parameter pack } ProtocolServerCommandGetResult; ProtocolServerCommandGetResult protocolServerCommandGet(ProtocolServer *this); diff --git a/src/storage/gcs/write.c b/src/storage/gcs/write.c index 448c58eec..e557ab246 100644 --- a/src/storage/gcs/write.c +++ b/src/storage/gcs/write.c @@ -88,7 +88,7 @@ storageWriteGcsVerify(StorageWriteGcs *this, HttpResponse *response) CHECK(md5base64 != NULL); const String *md5actual = bufHex(bufNewDecode(encodeBase64, md5base64)); - const String *md5expected = pckReadStrP(pckReadNewBuf(ioFilterResult(this->md5hash))); + const String *md5expected = pckReadStrP(pckReadNew(ioFilterResult(this->md5hash))); if (!strEq(md5actual, md5expected)) { diff --git a/src/storage/remote/protocol.c b/src/storage/remote/protocol.c index 062633c83..4f25ac810 100644 --- a/src/storage/remote/protocol.c +++ b/src/storage/remote/protocol.c @@ -34,22 +34,22 @@ static struct Set filter group based on passed filters ***********************************************************************************************************************************/ static void -storageRemoteFilterGroup(IoFilterGroup *filterGroup, const Buffer *const filterPack) +storageRemoteFilterGroup(IoFilterGroup *filterGroup, const Pack *const filterPack) { FUNCTION_TEST_BEGIN(); FUNCTION_TEST_PARAM(IO_FILTER_GROUP, filterGroup); - FUNCTION_TEST_PARAM(BUFFER, filterPack); + FUNCTION_TEST_PARAM(PACK, filterPack); FUNCTION_TEST_END(); ASSERT(filterGroup != NULL); ASSERT(filterPack != NULL); - PackRead *const filterList = pckReadNewBuf(filterPack); + PackRead *const filterList = pckReadNew(filterPack); while (!pckReadNullP(filterList)) { const StringId filterKey = pckReadStrIdP(filterList); - const Buffer *const filterParam = pckReadPackBufP(filterList); + const Pack *const filterParam = pckReadPackP(filterList); IoFilter *filter = compressFilterPack(filterKey, filterParam); @@ -356,7 +356,7 @@ storageRemoteOpenReadProtocol(PackRead *const param, ProtocolServer *const serve const String *file = pckReadStrP(param); bool ignoreMissing = pckReadBoolP(param); const Variant *limit = jsonToVar(pckReadStrP(param)); - const Buffer *const filter = pckReadPackBufP(param); + const Pack *const filter = pckReadPackP(param); // Create the read object IoRead *fileRead = storageReadIo( @@ -383,7 +383,7 @@ storageRemoteOpenReadProtocol(PackRead *const param, ProtocolServer *const serve { MEM_CONTEXT_TEMP_BEGIN() { - PackWrite *write = pckWriteNewBuf(bufNew(ioBufferSize() + PROTOCOL_PACK_DEFAULT_SIZE)); + PackWrite *write = pckWriteNewP(.size = ioBufferSize() + PROTOCOL_PACK_DEFAULT_SIZE); pckWriteBinP(write, buffer); protocolServerDataPut(server, write); } @@ -433,7 +433,7 @@ storageRemoteOpenWriteProtocol(PackRead *const param, ProtocolServer *const serv bool syncFile = pckReadBoolP(param); bool syncPath = pckReadBoolP(param); bool atomic = pckReadBoolP(param); - const Buffer *const filter = pckReadPackBufP(param); + const Pack *const filter = pckReadPackP(param); IoWrite *fileWrite = storageWriteIo( storageInterfaceNewWriteP( diff --git a/src/storage/remote/read.c b/src/storage/remote/read.c index e51bc932a..e6244041d 100644 --- a/src/storage/remote/read.c +++ b/src/storage/remote/read.c @@ -75,7 +75,7 @@ storageReadRemoteOpen(THIS_VOID) pckWriteStrP(param, this->interface.name); pckWriteBoolP(param, this->interface.ignoreMissing); pckWriteStrP(param, jsonFromVar(this->interface.limit)); - pckWritePackBufP(param, ioFilterGroupParamAll(ioReadFilterGroup(storageReadIo(this->read)))); + pckWritePackP(param, ioFilterGroupParamAll(ioReadFilterGroup(storageReadIo(this->read)))); protocolClientCommandPut(this->client, command); diff --git a/src/storage/remote/write.c b/src/storage/remote/write.c index 1ad609129..8b39de65d 100644 --- a/src/storage/remote/write.c +++ b/src/storage/remote/write.c @@ -91,7 +91,7 @@ storageWriteRemoteOpen(THIS_VOID) pckWriteBoolP(param, this->interface.syncFile); pckWriteBoolP(param, this->interface.syncPath); pckWriteBoolP(param, this->interface.atomic); - pckWritePackBufP(param, ioFilterGroupParamAll(ioWriteFilterGroup(storageWriteIo(this->write)))); + pckWritePackP(param, ioFilterGroupParamAll(ioWriteFilterGroup(storageWriteIo(this->write)))); protocolClientCommandPut(this->client, command); protocolClientDataGet(this->client); @@ -134,7 +134,7 @@ storageWriteRemote(THIS_VOID, const Buffer *buffer) MEM_CONTEXT_TEMP_BEGIN() { protocolClientDataPut( - this->client, pckWriteBinP(pckWriteNewBuf(bufNew(ioBufferSize() + PROTOCOL_PACK_DEFAULT_SIZE)), buffer)); + this->client, pckWriteBinP(pckWriteNewP(.size = ioBufferSize() + PROTOCOL_PACK_DEFAULT_SIZE), buffer)); } MEM_CONTEXT_TEMP_END(); diff --git a/test/src/common/harnessInfo.c b/test/src/common/harnessInfo.c index c838e948f..195b3f224 100644 --- a/test/src/common/harnessInfo.c +++ b/test/src/common/harnessInfo.c @@ -97,7 +97,7 @@ harnessInfoChecksum(const String *info) // Append checksum to buffer bufCat(result, BUFSTRDEF("\n[backrest]\nbackrest-checksum=")); - bufCat(result, BUFSTR(jsonFromStr(pckReadStrP(pckReadNewBuf(ioFilterResult(data.checksum)))))); + bufCat(result, BUFSTR(jsonFromStr(pckReadStrP(pckReadNew(ioFilterResult(data.checksum)))))); bufCat(result, BUFSTRDEF("\n")); bufMove(result, memContextPrior()); diff --git a/test/src/common/harnessPack.c b/test/src/common/harnessPack.c index 5d81945e5..487b960d8 100644 --- a/test/src/common/harnessPack.c +++ b/test/src/common/harnessPack.c @@ -12,17 +12,17 @@ Harness for Loading Test Configurations #include "common/harnessPack.h" /**********************************************************************************************************************************/ -String *hrnPackBufToStr(const Buffer *buffer) +String *hrnPackToStr(const Pack *const pack) { FUNCTION_HARNESS_BEGIN(); - FUNCTION_HARNESS_PARAM(BUFFER, buffer); + FUNCTION_HARNESS_PARAM(PACK, pack); FUNCTION_HARNESS_END(); - FUNCTION_HARNESS_RETURN(STRING, hrnPackToStr(pckReadNewBuf(buffer))); + FUNCTION_HARNESS_RETURN(STRING, hrnPackReadToStr(pckReadNew(pack))); } /**********************************************************************************************************************************/ -String *hrnPackToStr(PackRead *read) +String *hrnPackReadToStr(PackRead *read) { FUNCTION_HARNESS_BEGIN(); FUNCTION_HARNESS_PARAM(PACK_READ, read); @@ -45,7 +45,7 @@ String *hrnPackToStr(PackRead *read) { case pckTypeArray: pckReadArrayBeginP(read, .id = id); - strCatFmt(result, "[%s]", strZ(hrnPackToStr(read))); + strCatFmt(result, "[%s]", strZ(hrnPackReadToStr(read))); pckReadArrayEndP(read); break; @@ -71,13 +71,13 @@ String *hrnPackToStr(PackRead *read) case pckTypeObj: pckReadObjBeginP(read, .id = id); - strCatFmt(result, "{%s}", strZ(hrnPackToStr(read))); + strCatFmt(result, "{%s}", strZ(hrnPackReadToStr(read))); pckReadObjEndP(read); break; case pckTypePack: { - strCatFmt(result, "<%s>", strZ(hrnPackToStr(pckReadPackP(read)))); + strCatFmt(result, "<%s>", strZ(hrnPackReadToStr(pckReadPackReadP(read)))); break; } diff --git a/test/src/common/harnessPack.h b/test/src/common/harnessPack.h index 2052237c6..805111bbe 100644 --- a/test/src/common/harnessPack.h +++ b/test/src/common/harnessPack.h @@ -6,8 +6,8 @@ Harness for Testing Packs /*********************************************************************************************************************************** Functions ***********************************************************************************************************************************/ -// Convert a pack to a string -String *hrnPackToStr(PackRead *read); +// Convert Pack to String +String *hrnPackToStr(const Pack *pack); -// Convert a pack buffer to a string -String *hrnPackBufToStr(const Buffer *buffer); +// Convert PackRead to String +String *hrnPackReadToStr(PackRead *read); diff --git a/test/src/module/build/helpTest.c b/test/src/module/build/helpTest.c index 0116edc13..3d7755149 100644 --- a/test/src/module/build/helpTest.c +++ b/test/src/module/build/helpTest.c @@ -338,7 +338,7 @@ testRun(void) "\n"); TEST_RESULT_STR_Z( - hrnPackToStr(pckReadNewBuf(pckWriteBuf(bldHlpRenderHelpAutoCPack(bldCfg, bldHlpParse(storageTest, bldCfg))))), + hrnPackReadToStr(pckReadNew(pckWriteResult(bldHlpRenderHelpAutoCPack(bldCfg, bldHlpParse(storageTest, bldCfg))))), "1:array:" "[" // backup command diff --git a/test/src/module/command/backupTest.c b/test/src/module/command/backupTest.c index ac172b050..e301072a5 100644 --- a/test/src/module/command/backupTest.c +++ b/test/src/module/command/backupTest.c @@ -1330,7 +1330,7 @@ testRun(void) pckWriteStrP(resultPack, NULL); pckWriteEndP(resultPack); - protocolParallelJobResultSet(job, pckReadNewBuf(pckWriteBuf(resultPack))); + protocolParallelJobResultSet(job, pckReadNew(pckWriteResult(resultPack))); // Create manifest with file Manifest *manifest = NULL; diff --git a/test/src/module/common/compressTest.c b/test/src/module/common/compressTest.c index 7307b2d22..fbc94e27e 100644 --- a/test/src/module/common/compressTest.c +++ b/test/src/module/common/compressTest.c @@ -79,7 +79,7 @@ testSuite(CompressType type, const char *decompressCmd) Buffer *compressed = NULL; Buffer *decompressed = bufNewC(simpleData, strlen(simpleData)); - PackWrite *packWrite = pckWriteNewBuf(bufNew(PACK_EXTRA_MIN)); + PackWrite *packWrite = pckWriteNewP(); pckWriteI32P(packWrite, 1); pckWriteEndP(packWrite); @@ -91,7 +91,7 @@ testSuite(CompressType type, const char *decompressCmd) TEST_ASSIGN( compressed, testCompress( - compressFilterPack(compressHelperLocal[type].compressType, pckWriteBuf(packWrite)), decompressed, 1024, + compressFilterPack(compressHelperLocal[type].compressType, pckWriteResult(packWrite)), decompressed, 1024, 256 * 1024 * 1024), "simple data - compress large in/large out buffer"); diff --git a/test/src/module/common/cryptoTest.c b/test/src/module/common/cryptoTest.c index 4a4296557..fd0ee2fde 100644 --- a/test/src/module/common/cryptoTest.c +++ b/test/src/module/common/cryptoTest.c @@ -301,11 +301,11 @@ testRun(void) TEST_RESULT_VOID(ioFilterFree(hash), " free hash"); // ------------------------------------------------------------------------------------------------------------------------- - PackWrite *packWrite = pckWriteNewBuf(bufNew(PACK_EXTRA_MIN)); + PackWrite *packWrite = pckWriteNewP(); pckWriteStrP(packWrite, HASH_TYPE_SHA1_STR); pckWriteEndP(packWrite); - TEST_ASSIGN(hash, cryptoHashNewPack(pckWriteBuf(packWrite)), "create sha1 hash"); + TEST_ASSIGN(hash, cryptoHashNewPack(pckWriteResult(packWrite)), "create sha1 hash"); TEST_RESULT_STR_Z(bufHex(cryptoHash((CryptoHash *)ioFilterDriver(hash))), HASH_TYPE_SHA1_ZERO, " check empty hash"); TEST_RESULT_STR_Z( bufHex(cryptoHash((CryptoHash *)ioFilterDriver(hash))), HASH_TYPE_SHA1_ZERO, " check empty hash again"); @@ -320,14 +320,14 @@ testRun(void) TEST_RESULT_VOID(ioFilterProcessIn(hash, BUFSTRDEF("5")), " add 5"); TEST_RESULT_STR_Z( - pckReadStrP(pckReadNewBuf(ioFilterResult(hash))), "8cb2237d0679ca88db6464eac60da96345513964", " check small hash"); + pckReadStrP(pckReadNew(ioFilterResult(hash))), "8cb2237d0679ca88db6464eac60da96345513964", " check small hash"); TEST_RESULT_VOID(ioFilterFree(hash), " free hash"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("md5 hash - zero bytes"); TEST_ASSIGN(hash, cryptoHashNew(STRDEF(HASH_TYPE_MD5)), "create md5 hash"); - TEST_RESULT_STR_Z(pckReadStrP(pckReadNewBuf(ioFilterResult(hash))), HASH_TYPE_MD5_ZERO, "check empty hash"); + TEST_RESULT_STR_Z(pckReadStrP(pckReadNew(ioFilterResult(hash))), HASH_TYPE_MD5_ZERO, "check empty hash"); // Exercise most of the conditions in the local MD5 code // ------------------------------------------------------------------------------------------------------------------------- @@ -346,7 +346,7 @@ testRun(void) TEST_RESULT_VOID( ioFilterProcessIn(hash, BUFSTRZ("12345678901234567890123456789001234567890012345678901234")), "add 58 bytes"); - TEST_RESULT_STR_Z(pckReadStrP(pckReadNewBuf(ioFilterResult(hash))), "3318600bc9c1d379e91e4bae90721243", "check hash"); + TEST_RESULT_STR_Z(pckReadStrP(pckReadNew(ioFilterResult(hash))), "3318600bc9c1d379e91e4bae90721243", "check hash"); // Full coverage of local MD5 requires processing > 511MB of data but that makes the test run too long. Instead we'll cheat // a bit and initialize the context at 511MB to start. This does not produce a valid MD5 hash but does provide coverage of @@ -358,11 +358,11 @@ testRun(void) ((CryptoHash *)ioFilterDriver(hash))->md5Context->lo = 0x1fffffff; TEST_RESULT_VOID(ioFilterProcessIn(hash, BUFSTRZ("1")), "add 1"); - TEST_RESULT_STR_Z(pckReadStrP(pckReadNewBuf(ioFilterResult(hash))), "5c99876f9cafa7f485eac9c7a8a2764c", "check hash"); + TEST_RESULT_STR_Z(pckReadStrP(pckReadNew(ioFilterResult(hash))), "5c99876f9cafa7f485eac9c7a8a2764c", "check hash"); // ------------------------------------------------------------------------------------------------------------------------- TEST_ASSIGN(hash, cryptoHashNew(STRDEF(HASH_TYPE_SHA256)), "create sha256 hash"); - TEST_RESULT_STR_Z(pckReadStrP(pckReadNewBuf(ioFilterResult(hash))), HASH_TYPE_SHA256_ZERO, " check empty hash"); + TEST_RESULT_STR_Z(pckReadStrP(pckReadNew(ioFilterResult(hash))), HASH_TYPE_SHA256_ZERO, " check empty hash"); // ------------------------------------------------------------------------------------------------------------------------- TEST_RESULT_STR_Z( diff --git a/test/src/module/common/ioTest.c b/test/src/module/common/ioTest.c index 1415c5a3a..6cc453b42 100644 --- a/test/src/module/common/ioTest.c +++ b/test/src/module/common/ioTest.c @@ -96,18 +96,17 @@ ioTestFilterSizeProcess(THIS_VOID, const Buffer *buffer) FUNCTION_LOG_RETURN_VOID(); } -static Buffer * +static Pack * ioTestFilterSizeResult(THIS_VOID) { THIS(IoTestFilterSize); - Buffer *const result = bufNew(16); - PackWrite *const pack = pckWriteNewBuf(result); + PackWrite *const packWrite = pckWriteNewP(); - pckWriteU64P(pack, this->size); - pckWriteEndP(pack); + pckWriteU64P(packWrite, this->size); + pckWriteEndP(packWrite); - return result; + return pckWriteResult(packWrite); } static IoFilter * @@ -227,21 +226,14 @@ ioTestFilterMultiplyNew(const StringId type, unsigned int multiplier, unsigned i .flushChar = flushChar, }; - Buffer *const paramList = bufNew(PACK_EXTRA_MIN); - - MEM_CONTEXT_TEMP_BEGIN() - { - PackWrite *const packWrite = pckWriteNewBuf(paramList); - - pckWriteStrIdP(packWrite, type); - pckWriteU32P(packWrite, multiplier); - pckWriteU32P(packWrite, flushTotal); - pckWriteEndP(packWrite); - } - MEM_CONTEXT_TEMP_END(); + PackWrite *const packWrite = pckWriteNewP(); + pckWriteStrIdP(packWrite, type); + pckWriteU32P(packWrite, multiplier); + pckWriteU32P(packWrite, flushTotal); + pckWriteEndP(packWrite); this = ioFilterNewP( - type, driver, paramList, .done = ioTestFilterMultiplyDone, .inOut = ioTestFilterMultiplyProcess, + type, driver, pckWriteResult(packWrite), .done = ioTestFilterMultiplyDone, .inOut = ioTestFilterMultiplyProcess, .inputSame = ioTestFilterMultiplyInputSame); } OBJ_NEW_END(); @@ -331,7 +323,7 @@ testRun(void) TEST_RESULT_VOID(ioFilterGroupAdd(ioReadFilterGroup(bufferRead), bufferFilter), " add filter to filter group"); TEST_RESULT_PTR(ioFilterMove(NULL, memContextTop()), NULL, " move NULL filter to top context"); TEST_RESULT_STR_Z( - hrnPackBufToStr(ioFilterGroupParamAll(ioReadFilterGroup(bufferRead))), + hrnPackToStr(ioFilterGroupParamAll(ioReadFilterGroup(bufferRead))), "1:strid:size, 3:strid:double, 4:pack:<1:strid:double, 2:u32:2, 3:u32:3>, 5:strid:size, 7:strid:buffer", " check filter params"); @@ -360,7 +352,7 @@ testRun(void) TEST_RESULT_UINT(ioRead(bufferRead, buffer), 0, " read 0 bytes"); TEST_RESULT_VOID(ioReadClose(bufferRead), " close buffer read object"); TEST_RESULT_STR_Z( - hrnPackBufToStr(pckWriteBuf(ioFilterGroupResultAll(ioReadFilterGroup(bufferRead)))), + hrnPackToStr(ioFilterGroupResultAll(ioReadFilterGroup(bufferRead))), "1:strid:size, 2:pack:<1:u64:3>, 3:strid:double, 5:strid:size, 6:pack:<1:u64:9>, 7:strid:buffer", " check filter result all"); @@ -390,16 +382,16 @@ testRun(void) filterGroup->pub.opened = true; TEST_RESULT_VOID(ioFilterGroupResultAllSet(filterGroup, NULL), "null result"); - PackWrite *filterResult = pckWriteNewBuf(bufNew(256)); + PackWrite *filterResult = pckWriteNewP(.size = 256); pckWriteU64P(filterResult, 777); pckWriteEndP(filterResult); - PackWrite *filterResultAll = pckWriteNewBuf(bufNew(256)); + PackWrite *filterResultAll = pckWriteNewP(.size = 256); pckWriteStrIdP(filterResultAll, STRID5("test", 0xa4cb40)); - pckWritePackP(filterResultAll, filterResult); + pckWritePackP(filterResultAll, pckWriteResult(filterResult)); pckWriteEndP(filterResultAll); - TEST_RESULT_VOID(ioFilterGroupResultAllSet(filterGroup, pckReadNewBuf(pckWriteBuf(filterResultAll))), "add result"); + TEST_RESULT_VOID(ioFilterGroupResultAllSet(filterGroup, pckWriteResult(filterResultAll)), "add result"); filterGroup->pub.closed = true; TEST_RESULT_UINT(pckReadU64P(ioFilterGroupResultP(filterGroup, STRID5("test", 0xa4cb40))), 777, " check filter result"); diff --git a/test/src/module/common/typePackTest.c b/test/src/module/common/typePackTest.c index d003323f4..9ae8dd40a 100644 --- a/test/src/module/common/typePackTest.c +++ b/test/src/module/common/typePackTest.c @@ -101,12 +101,12 @@ testRun(void) TEST_RESULT_VOID(pckWriteBinP(packWrite, bufNew(0)), "write bin zero length"); // Write pack - PackWrite *packSub = pckWriteNewBuf(bufNew(128)); + PackWrite *packSub = pckWriteNewP(); pckWriteU64P(packSub, 345); pckWriteStrP(packSub, STRDEF("sub"), .id = 3); pckWriteEndP(packSub); - TEST_RESULT_VOID(pckWritePackP(packWrite, packSub), "write pack"); + TEST_RESULT_VOID(pckWritePackP(packWrite, pckWriteResult(packSub)), "write pack"); TEST_RESULT_VOID(pckWritePackP(packWrite, NULL), "write null pack"); // Write string list @@ -124,7 +124,7 @@ testRun(void) ioWriteClose(write); TEST_RESULT_STR_Z( - hrnPackBufToStr(pack), + hrnPackToStr(pckFromBuf(pack)), "1:u64:488" ", 2:u64:1911246845" ", 7:u64:18446744073709551615" @@ -312,8 +312,8 @@ testRun(void) TEST_RESULT_PTR(pckReadBinP(packRead), NULL, "read bin null"); TEST_RESULT_UINT(bufSize(pckReadBinP(packRead)), 0, "read bin zero length"); - TEST_RESULT_STR_Z(hrnPackToStr(pckReadPackP(packRead)), "1:u64:345, 3:str:sub", "read pack"); - TEST_RESULT_PTR(pckReadPackP(packRead), NULL, "read null pack"); + TEST_RESULT_STR_Z(hrnPackReadToStr(pckReadPackReadP(packRead)), "1:u64:345, 3:str:sub", "read pack"); + TEST_RESULT_PTR(pckReadPackReadP(packRead), NULL, "read null pack"); TEST_RESULT_STRLST_Z(pckReadStrLstP(packRead), "a\nbcd\n", "read string list"); TEST_RESULT_PTR(pckReadStrLstP(packRead), NULL, "read null string list"); @@ -327,27 +327,29 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("EOF on short buffer"); - TEST_ASSIGN(packRead, pckReadNewBuf(BUFSTRDEF("\255")), "new read"); + TEST_ASSIGN(packRead, pckReadNew(pckFromBuf(BUFSTRDEF("\255"))), "new read"); TEST_ERROR(pckReadU64Internal(packRead), FormatError, "unexpected EOF"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("error on invalid uint64"); - TEST_ASSIGN(packRead, pckReadNewBuf(BUFSTRDEF("\255\255\255\255\255\255\255\255\255\255")), "new read"); + TEST_ASSIGN(packRead, pckReadNew(pckFromBuf(BUFSTRDEF("\255\255\255\255\255\255\255\255\255\255"))), "new read"); TEST_ERROR(pckReadU64Internal(packRead), FormatError, "unterminated base-128 integer"); // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("pack/unpack pointer"); - TEST_ASSIGN(packWrite, pckWriteNewBuf(bufNew(0)), "new write"); + TEST_ASSIGN(packWrite, pckWriteNewP(.size = 1), "new write"); TEST_RESULT_VOID(pckWritePtrP(packWrite, NULL), "write default pointer"); TEST_RESULT_VOID(pckWritePtrP(packWrite, "sample"), "write pointer"); TEST_RESULT_VOID(pckWriteEndP(packWrite), "write end"); - TEST_ASSIGN(packRead, pckReadNewBuf(pckWriteBuf(packWrite)), "new read"); + TEST_ASSIGN(packRead, pckReadNew(pckWriteResult(packWrite)), "new read"); TEST_RESULT_Z(pckReadPtrP(packRead), NULL, "read default pointer"); TEST_RESULT_Z(pckReadPtrP(packRead, .id = 2), "sample", "read pointer"); + TEST_RESULT_PTR(pckWriteResult(NULL), NULL, "null pack result"); + // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("pack/unpack write internal buffer empty"); @@ -362,7 +364,7 @@ testRun(void) TEST_RESULT_VOID(pckWriteStrP(packWrite, STRDEF("test")), "write string longer than internal buffer"); TEST_RESULT_VOID(pckWriteEndP(packWrite), "end with internal buffer empty"); - TEST_ASSIGN(packRead, pckReadNewBuf(pack), "new read"); + TEST_ASSIGN(packRead, pckReadNew(pckFromBuf(pack)), "new read"); TEST_RESULT_STR_Z(pckReadStrP(packRead), "test", "read string"); } diff --git a/test/src/module/storage/remoteTest.c b/test/src/module/storage/remoteTest.c index 521e6cd3d..280ac6732 100644 --- a/test/src/module/storage/remoteTest.c +++ b/test/src/module/storage/remoteTest.c @@ -305,7 +305,7 @@ testRun(void) TEST_RESULT_STR_Z(strNewBuf(storageGetP(fileRead)), "TESTDATA", "check contents"); TEST_RESULT_STR_Z( - hrnPackBufToStr(pckWriteBuf(ioFilterGroupResultAll(filterGroup))), + hrnPackToStr(ioFilterGroupResultAll(filterGroup)), "1:strid:size, 2:pack:<1:u64:8>, 3:strid:hash, 4:pack:<1:str:bbbcf2c59433f68f22376cd2439d6cd309378df6>," " 5:strid:pg-chksum, 6:pack:<1:str:{\"align\":false,\"valid\":false}>, 7:strid:cipher-blk, 9:strid:cipher-blk," " 11:strid:gz-cmp, 13:strid:gz-dcmp, 15:strid:buffer", @@ -328,7 +328,7 @@ testRun(void) TEST_RESULT_STR_Z(strNewBuf(storageGetP(fileRead)), "", "no content"); TEST_RESULT_STR_Z( - hrnPackBufToStr(pckWriteBuf(ioFilterGroupResultAll(filterGroup))), + hrnPackToStr(ioFilterGroupResultAll(filterGroup)), "1:strid:size, 2:pack:<1:u64:8>, 3:strid:hash, 4:pack:<1:str:bbbcf2c59433f68f22376cd2439d6cd309378df6>, 5:strid:sink," " 7:strid:buffer", "filter results"); @@ -336,12 +336,12 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- TEST_TITLE("error on invalid filter"); - Buffer *filterPack = bufNew(PACK_EXTRA_MIN); - PackWrite *filterWrite = pckWriteNewBuf(filterPack); + PackWrite *filterWrite = pckWriteNewP(); pckWriteStrIdP(filterWrite, STRID5("bogus", 0x13a9de20)); pckWriteEndP(filterWrite); - TEST_ERROR(storageRemoteFilterGroup(ioFilterGroupNew(), filterPack), AssertError, "unable to add filter 'bogus'"); + TEST_ERROR( + storageRemoteFilterGroup(ioFilterGroupNew(), pckWriteResult(filterWrite)), AssertError, "unable to add filter 'bogus'"); } // *****************************************************************************************************************************