feat: add carv2-messaging example for embedding messages in CARv2 #89
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.
Background
This comes from a feature request by @mikeal to be able to signal additional, potentially arbitrary properties for backend communication, like supplying "PieceCID" for the CAR, and other things .. pushing CAR from just a block transport to also have a messaging layer that relates to those blocks that's more than just "here are the roots".
Proposal
So this is .. sneaky .. we take a standard CARv1 (in this case, just a single-block simplistic example), wrap it in a CARv2, push the "data offset" back enough to embed a length-prefixed dag-cbor "message" just after the CARv2 header.
We have a "characteristics" bitfield in CARv2 but only one bit that's currently being used, this proposes that the second-to-leftmost bit being used to indicate "message after v2 header".
The resulting .car file is readable by js-car as-is, the API shows you what you'd see if you passed it the original CARv1 contents, but it's wrapped in a CARv2 and you can poke at the bytes to see that there's a secret message in there just after the CARv2 header and before the CARv1 payload.
It's also valid according to go-car:
I'm interested to see who might object to such flagrant abuse of CARv2 flexibility ..