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

Access encoded data while encoding in order to compute checksum #44

Open
interstateone opened this issue Feb 26, 2019 · 2 comments
Open
Labels
feature request New feature or request

Comments

@interstateone
Copy link

A .binarycookies file contains many pages of cookies, and the entire file contains a checksum near the end. The checksum is the sum of each page's checksum, which is the sum of every 4th byte in the page. I don't think it's possible to compute this with the current API, right?

I don't have a strong opinion about an ideal API for this, but if SequentialBinaryEncodingContainer.encode(_:) returned the encoded data then I think that would at least provide the necessary data. In regard to the recent addition of the ability to encode arrays of BinaryEncodable, if the API returned the encoded data for the entire array I don't think that would work in this case, because the "sum every 4th byte" behaviour needed for this checksum starts at the beginning of each page (Hopefully that explanation is clear). This only means that for this file format each page would need to be encoded individually instead of encoding the entire array at once.

In the current implementation, each page encodes itself to Data during the encoding process in order to compute its checksum, so each Page is encoded twice over the course of encoding a file. I would imagine that for larger files the inefficiency of this would be more noticeable.

@jverkoey jverkoey added the feature request New feature or request label Feb 26, 2019
@jverkoey
Copy link
Owner

jverkoey commented Mar 2, 2019

To clarify: is the request here to return the encoded Data from each of BinaryEncodingContainer's encode APIs?

E.g.

encode<T>(_ value: T) throws where T: BinaryEncodable -> Data

@interstateone
Copy link
Author

Yes I think that change would provide what's needed to compute the checksum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants