Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API for fetching skippable frame content #2708

Merged
merged 1 commit into from
Jun 14, 2021
Merged

Conversation

binhdvo
Copy link
Contributor

@binhdvo binhdvo commented Jun 11, 2021

Provides functions for navigating frames in memory and identifying and extracting content from skippable frames. Streaming mode left out of scope for now.

lib/zstd.h Outdated
*
* @return : number of bytes written or a ZSTD error.
*/
ZSTDLIB_API unsigned long long ZSTD_readSkippableFrame(void* dst, size_t dstCapacity, unsigned* magicVariant,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: A ZSTD error sum type (error | size) cannot be an unsigned long long. This will have to return a size_t.

It is fine to return a size_t because we know the data is contiguous, so a size_t is large enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this caused one of the CI tests to fail before, let me try again

@binhdvo binhdvo force-pushed the skippable branch 7 times, most recently from 277dc93 to 57edb43 Compare June 11, 2021 23:04
if (zfh.frameType == ZSTD_skippableFrame) {
return readSkippableFrameSize(src, srcSize);
} else {
return ZSTD_findFrameCompressedSize(src, srcSize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't ZSTD_findFrameCompressedSize() already able to provide the size of a skippable frame ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I thought that was only for compressed frames; removed the new function.

/* deliver payload */
if (skippableContentSize > 0 && dst != NULL)
ZSTD_memcpy(dst, (const BYTE *)src + ZSTD_SKIPPABLEHEADERSIZE, skippableContentSize);
if (magicVariant != NULL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the API allow magicVariant == NULL ?
In which case, the documentation should mention it and tell what happens in this case.
If not, an assert() here would be more appropriate.
Finally, an alternative design could be to return a struct that combine the 2 results (size_t bytes written, and unsigned magic variant), making them clearly return values, and avoiding potential confusion with regards to caller-side allocation, in+out values, etc.

@Cyan4973
Copy link
Contributor

Almost there !
I like the consistency of this proposal, which is a clear mirror of existing readSkippableFrame().
Let's just have a discussion about function's return type, and I guess it will be good to go.

lib/zstd.h Outdated
* in the magicVariant.
*
* 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 frame is not skippable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comment :

if the source size is not representable * with a 4-byte unsigned int

I think the binary format does not allow such scenario. Skippable frame content size must be represented as a 4-bytes unsigned int.

@binhdvo binhdvo merged commit 0152435 into facebook:dev Jun 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants