Use pre-defined constants

This commit is contained in:
senhuang42 2020-12-21 11:33:41 -05:00
parent 339d8ba103
commit 5c41490bfe
3 changed files with 14 additions and 13 deletions

View File

@ -2954,16 +2954,16 @@ static size_t ZSTD_writeFrameHeader(void* dst, size_t dstCapacity,
return pos; return pos;
} }
/* ZSTD_generateSkippableFrame_advanced() : /* ZSTD_writeSkippableFrame_advanced() :
* Writes out a skippable frame with the specified magic number variant (16 are supported), * Writes out a skippable frame with the specified magic number variant (16 are supported),
* from ZSTD_MAGIC_SKIPPABLE_START to ZSTD_MAGIC_SKIPPABLE_START+15, and the desired source data. * from ZSTD_MAGIC_SKIPPABLE_START to ZSTD_MAGIC_SKIPPABLE_START+15, and the desired source data.
* *
* Returns the total number of bytes written, or a ZSTD error code. * Returns the total number of bytes written, or a ZSTD error code.
*/ */
size_t ZSTD_generateSkippableFrame_advanced(void* dst, size_t dstCapacity, size_t ZSTD_writeSkippableFrame(void* dst, size_t dstCapacity,
const void* src, size_t srcSize, U32 magicVariant) { const void* src, size_t srcSize, unsigned magicVariant) {
BYTE* op = dst; BYTE* op = (BYTE*)dst;
RETURN_ERROR_IF(dstCapacity < srcSize + 8 /* Skippable frame overhead */, RETURN_ERROR_IF(dstCapacity < srcSize + ZSTD_SKIPPABLEHEADERSIZE /* Skippable frame overhead */,
dstSize_tooSmall, "Not enough room for skippable frame"); dstSize_tooSmall, "Not enough room for skippable frame");
RETURN_ERROR_IF(srcSize > (unsigned)0xFFFFFFFF, srcSize_wrong, "Src size too large for skippable frame"); RETURN_ERROR_IF(srcSize > (unsigned)0xFFFFFFFF, srcSize_wrong, "Src size too large for skippable frame");
RETURN_ERROR_IF(magicVariant > 15, parameter_outOfBound, "Skippable frame magic number variant not supported"); RETURN_ERROR_IF(magicVariant > 15, parameter_outOfBound, "Skippable frame magic number variant not supported");
@ -2971,7 +2971,7 @@ size_t ZSTD_generateSkippableFrame_advanced(void* dst, size_t dstCapacity,
MEM_writeLE32(op, (U32)(ZSTD_MAGIC_SKIPPABLE_START + magicVariant)); MEM_writeLE32(op, (U32)(ZSTD_MAGIC_SKIPPABLE_START + magicVariant));
MEM_writeLE32(op+4, (U32)srcSize); MEM_writeLE32(op+4, (U32)srcSize);
ZSTD_memcpy(op+8, src, srcSize); ZSTD_memcpy(op+8, src, srcSize);
return srcSize + 8; return srcSize + ZSTD_SKIPPABLEHEADERSIZE;
} }
/* ZSTD_writeLastEmptyBlock() : /* ZSTD_writeLastEmptyBlock() :

View File

@ -1372,20 +1372,21 @@ ZSTDLIB_API size_t ZSTD_compressSequences(ZSTD_CCtx* const cctx, void* dst, size
const void* src, size_t srcSize); const void* src, size_t srcSize);
/*! ZSTD_generateSkippableFrame() : /*! ZSTD_writeSkippableFrame() :
* Generates a zstd skippable frame containing data given by src, and writes it to dst buffer. * Generates a zstd skippable frame containing data given by src, and writes it to dst buffer.
* *
* Skippable frames have a 4-byte magic number, which can range from ZSTD_MAGIC_SKIPPABLE_START to ZSTD_MAGIC_SKIPPABLE_START+15. * Skippable frames begin with a a 4-byte magic number. There are 16 possible choices of magic number,
* ranging from ZSTD_MAGIC_SKIPPABLE_START to ZSTD_MAGIC_SKIPPABLE_START+15.
* As such, the parameter magicVariant controls the exact skippable frame magic number variant used, so * As such, the parameter magicVariant controls the exact skippable frame magic number variant used, so
* the final magic number will be ZSTD_MAGIC_SKIPPABLE_START + magicVariant. * the magic number used will be ZSTD_MAGIC_SKIPPABLE_START + magicVariant.
* *
* Returns an error if destination buffer is not large enough, if the source size is not representable * Returns an error if destination buffer is not large enough, if the source size is not representable
* with a 4-byte unsigned int, or if the magicVariant is greater than 15. * with a 4-byte unsigned int, or if the parameter magicVariant is greater than 15 (and therefore invalid).
* *
* @return : number of bytes written or a ZSTD error. * @return : number of bytes written or a ZSTD error.
*/ */
ZSTDLIB_API size_t ZSTD_generateSkippableFrame(void* dst, size_t dstCapacity, ZSTDLIB_API size_t ZSTD_writeSkippableFrame(void* dst, size_t dstCapacity,
const void* src, size_t srcSize, unsigned magicVariant); const void* src, size_t srcSize, unsigned magicVariant);
/*************************************** /***************************************

View File

@ -1583,7 +1583,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
off += r; off += r;
if (i == segs/2) { if (i == segs/2) {
/* insert skippable frame */ /* insert skippable frame */
skippableSize = ZSTD_generateSkippableFrame(compressedBuffer + off, compressedBufferSize, skipBuff, skipLen, seed % 15); skippableSize = ZSTD_writeSkippableFrame(compressedBuffer + off, compressedBufferSize, skipBuff, skipLen, seed % 15);
CHECK_Z(skippableSize); CHECK_Z(skippableSize);
off += skippableSize; off += skippableSize;
} }