feat: add carv2-messaging example for embedding messages in CARv2#89
Draft
feat: add carv2-messaging example for embedding messages in CARv2#89
Conversation
Member
Author
|
I should also say - this is very manual in here, if we adopt this then the API would have to be made to handle at least some of this so you don't have to get so dirty with the bytes and bits... cause it's kind of nasty atm. |
b646b67 to
9f26864
Compare
rvagg
added a commit
to ipld/go-car
that referenced
this pull request
Jul 13, 2022
EmbedMessage sets the second-to-leftmost bit to indicate that there is a length-prefixed dag-cbor message object directly after the header. If that bit is set, Reader#ReadEmbeddedMessage will decode and return that message. Ref: ipld/js-car#89
Member
Author
|
go-car impl (including ability to read and recreate the .car created by this example): ipld/go-car#322 |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ..