Introduce traversal function that selects links out of a tree.#110
Conversation
|
It may be interesting to compare this to https://github.com/whyrusleeping/cbor-gen/blob/0b9f6c5fb1636544f94f5087817df99699de49ba/utils.go#L47 -- that function also plucks links out of a block. It's also probably faster and lower overhead if you didn't already otherwise need to parse the block, because it scans over the serial form and only bothers to create in-memory objects for the links. On the other hand, that function also only works with CBOR. We might be able to create functions a bit closer to those semantics in a codec-agnostic way in go-ipld-prime in the future, too. Some of the tokenization reworking aims to get us closer to able to handle Data Model info as a stream without full tree reification. We'd need a fair amount of further rework to codec implementations to make that fly, though. (Stuff that's on the docket, but probably not landing "today".) Regardless: this function that does operate on in-memory trees is still reasonable to have in the traversal package -- both immediately, because it's easy; and in the long run even if we did make stream methods with similar outputs, because which is useful is situationally dependent on how much parsing you may have already needed to do for other parts of the situation you're in. |
ribasushi
left a comment
There was a problem hiding this comment.
LGTM! Agreed with motivation and limitations notes.
Like it says on the tin.
This is just a quick, simple, handy function to have on hand.