specialized checksumPrepend and checksumAppend #462
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current implementation of
checksummed
implies that the developer knows framing. Though, sometimes it's easier to define a codec by providing the targetCodec
and the parameters for the checksum, e.g. size and an algorithm. For instance, look at roundtrip undefined size, I'm not sure this logic can be easily expressed using checksummed to append the CRC.From my POV, the construction of ChecksumPrepend in terms of
checksummed
is harder than it should be. IIRC, I tried to express it withCodec.exmap(_.swap)(_.swap)
but it was too difficult to understand when I looked at it later.Moreover, framing in
checksummed
controls not only the place of CRC value and the region of bits to compute the CRC but also what is being passed to the target. That not only defines how the CRC is computed, but also what is fed to the target, which seems to be wrong, at least by violating the SRP. Also, framing doesn't allow a user to omit bit regions for CRC computation. I encountered it when I implemented a codec with the structure| THE_CRC | REGION NOT UNDER CRC | REGION UNDER THE_CRC |