Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Expose skippable frames via the API. #459

Closed
rouzier opened this issue Dec 1, 2021 · 2 comments
Closed

Expose skippable frames via the API. #459

rouzier opened this issue Dec 1, 2021 · 2 comments

Comments

@rouzier
Copy link

rouzier commented Dec 1, 2021

Is it possible to add an API to use skippable frames.

https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md#skippable-frames

@klauspost
Copy link
Owner

@rouzier It is possible. You can of course prepend or append it to any encode.

Adding one is fairly simple. This is used for adding the final padding, and a standalone version could look like this:

// CreateSkippableFrame will add a skippable frame with the specified payload
// and append it to dst.
func CreateSkippableFrame(dst []byte, payload []byte) ([]byte, error) {
	if len(payload) == 0 {
		return dst, nil
	}
	if len(payload) > math.MaxUint32 {
		return dst, fmt.Errorf("requested skippable frame size (%d) > max uint32", len(payload))
	}
	dst = append(dst, 0x50, 0x2a, 0x4d, 0x18)
	f := uint32(len(payload))
	dst = append(dst, uint8(f), uint8(f>>8), uint8(f>>16), uint8(f>>24))
	dst = append(dst, payload...)
	return dst, nil
}

(untested, beware)

@klauspost
Copy link
Owner

Adding functionality to include it should also have callbacks for getting the payloads when decoding.

klauspost pushed a commit that referenced this issue Jan 25, 2022
Changes made:
* Add Header.HeaderSize to track the actual size of the header.
The header is variable length, so providing this information allows
the caller to do other low-level tasks, such as determining whether
the entirety of a zstandard frame is a single segment block.
* Add Header.Skippable{ID,Size} to make the Header type more
useful for extracting data from metadata frames (see #459).
* Re-arrange fields in Header to better match the order
these appear in RFC 8478.
Repository owner locked and limited conversation to collaborators Sep 25, 2022
@klauspost klauspost converted this issue into discussion #670 Sep 25, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants