U32 longLengthPos;
} seqStore_t;
+/**
+ * Contains the compressed frame size and an upper-bound for the decompressed frame size.
+ * Note: before using `compressedSize` you must check for errors using ZSTD_isError().
+ * similarly, before using `decompressedBound`, you must check for errors using:
+ * `decompressedBound` != ZSTD_CONTENTSIZE_ERROR
+ */
+typedef struct {
+ size_t compressedSize;
+ unsigned long long decompressedBound;
+} ZSTD_frameSizeInfo;
+
const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
***************************************/
#include "mem.h" /* MEM_STATIC */
#include "error_private.h" /* ERROR */
-#include "zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer */
+#include "zstd_internal.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTD_frameSizeInfo */
#if !defined (ZSTD_LEGACY_SUPPORT) || (ZSTD_LEGACY_SUPPORT == 0)
# undef ZSTD_LEGACY_SUPPORT
}
}
-MEM_STATIC void ZSTD_errorFrameSizeInfoLegacy(size_t* cSize, unsigned long long* dBound, size_t ret)
-{
- *cSize = ret;
- *dBound = ZSTD_CONTENTSIZE_ERROR;
-}
-
MEM_STATIC ZSTD_frameSizeInfo ZSTD_findFrameSizeInfoLegacy(const void *src, size_t srcSize)
{
U32 const version = ZSTD_isLegacy(src, srcSize);
break;
#endif
default :
- ZSTD_errorFrameSizeInfoLegacy(&frameSizeInfo.compressedSize,
- &frameSizeInfo.decompressedBound, ERROR(prefix_unknown));
+ frameSizeInfo.compressedSize = ERROR(prefix_unknown);
+ frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
break;
}
return frameSizeInfo;
const void* src, size_t compressedSize);
/**
- ZSTDv01_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.1.x format
- compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
- return : the number of bytes that would be read to decompress this frame
- or an errorCode if it fails (which can be tested using ZSTDv01_isError())
+ ZSTDv01_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.1.x format
+ srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
+ cSize (output parameter) : the number of bytes that would be read to decompress this frame
+ or an errorCode if it fails (which can be tested using ZSTDv01_isError())
+ dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
+ or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/
void ZSTDv01_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound);
const void* src, size_t compressedSize);
/**
- ZSTDv02_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.2.x format
- compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
- return : the number of bytes that would be read to decompress this frame
- or an errorCode if it fails (which can be tested using ZSTDv02_isError())
+ ZSTDv02_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.2.x format
+ srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
+ cSize (output parameter) : the number of bytes that would be read to decompress this frame
+ or an errorCode if it fails (which can be tested using ZSTDv01_isError())
+ dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
+ or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/
void ZSTDv02_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound);
const void* src, size_t compressedSize);
/**
- ZSTDv03_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.3.x format
- compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
- return : the number of bytes that would be read to decompress this frame
- or an errorCode if it fails (which can be tested using ZSTDv03_isError())
+ ZSTDv03_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.3.x format
+ srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
+ cSize (output parameter) : the number of bytes that would be read to decompress this frame
+ or an errorCode if it fails (which can be tested using ZSTDv01_isError())
+ dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
+ or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/
void ZSTDv03_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound);
const void* src, size_t compressedSize);
/**
- ZSTDv04_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.4.x format
- compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
- return : the number of bytes that would be read to decompress this frame
- or an errorCode if it fails (which can be tested using ZSTDv04_isError())
+ ZSTDv04_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.4.x format
+ srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
+ cSize (output parameter) : the number of bytes that would be read to decompress this frame
+ or an errorCode if it fails (which can be tested using ZSTDv01_isError())
+ dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
+ or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/
void ZSTDv04_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound);
const void* src, size_t compressedSize);
/**
- ZSTDv05_getFrameSrcSize() : get the source length of a ZSTD frame
- compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
- return : the number of bytes that would be read to decompress this frame
- or an errorCode if it fails (which can be tested using ZSTDv05_isError())
+ ZSTDv05_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.5.x format
+ srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
+ cSize (output parameter) : the number of bytes that would be read to decompress this frame
+ or an errorCode if it fails (which can be tested using ZSTDv01_isError())
+ dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
+ or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/
void ZSTDv05_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound);
const void* src, size_t compressedSize);
/**
-ZSTDv06_getFrameSrcSize() : get the source length of a ZSTD frame
- compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
- return : the number of bytes that would be read to decompress this frame
- or an errorCode if it fails (which can be tested using ZSTDv06_isError())
+ZSTDv06_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.6.x format
+ srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
+ cSize (output parameter) : the number of bytes that would be read to decompress this frame
+ or an errorCode if it fails (which can be tested using ZSTDv01_isError())
+ dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
+ or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/
void ZSTDv06_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound);
const void* src, size_t compressedSize);
/**
-ZSTDv07_getFrameSrcSize() : get the source length of a ZSTD frame
- compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
- return : the number of bytes that would be read to decompress this frame
- or an errorCode if it fails (which can be tested using ZSTDv07_isError())
+ZSTDv07_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.7.x format
+ srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
+ cSize (output parameter) : the number of bytes that would be read to decompress this frame
+ or an errorCode if it fails (which can be tested using ZSTDv01_isError())
+ dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
+ or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/
void ZSTDv07_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound);
* Frame size functions
***************************************/
-/**
- * Contains the compressed frame size and an upper-bound for the decompressed frame size.
- * Note: before using `compressedSize` you must check for errors using ZSTD_isError().
- * similarly, before using `decompressedBound`, you must check for errors using:
- * `decompressedBound` != ZSTD_CONTENTSIZE_ERROR
- */
-typedef struct {
- size_t compressedSize;
- unsigned long long decompressedBound;
-} ZSTD_frameSizeInfo;
-
/*! ZSTD_findDecompressedSize() :
* `src` should point to the start of a series of ZSTD encoded and/or skippable frames
* `srcSize` must be the _exact_ size of this series
DISPLAY("ERROR: ZSTD_decompressBound: decompressed bound too small\n");
return 1;
}
+ { const char* ip = COMPRESSED;
+ size_t remainingSize = COMPRESSED_SIZE;
+ while (1) {
+ size_t frameSize = ZSTD_findFrameCompressedSize(ip, remainingSize);
+ if (ZSTD_isError(frameSize)) {
+ DISPLAY("ERROR: ZSTD_findFrameCompressedSize: %s\n", ZSTD_getErrorName(frameSize));
+ return 1;
+ }
+ if (frameSize > remainingSize) {
+ DISPLAY("ERROR: ZSTD_findFrameCompressedSize: expected frameSize to align with src buffer");
+ return 1;
+ }
+ ip += frameSize;
+ remainingSize -= frameSize;
+ if (remainingSize == 0) break;
+ }
+ }
DISPLAY("Frame Decoding OK\n");
return 0;
}