Closed willscott closed 1 year ago
I went with this so that the .AsLink()
directly provides .FieldHash().AsLink()
of the PBLink
as a way of maintaining compatibility with current semantics.
This is (if i remember correctly) to provide the higher level semantics of directory traversal that are used for pathing through unixfs.
@willscott I agree, and probably changing PBLink
to allow AsLink
to return a cidlink.Link
would be conceptually problematic (IIUC the rough go-ipld-prime node contract is that an object is exactly one of the data model types not multiple). I wouldn't be surprised if other uses of PBLink would run into similar issues and want a standard way to access both representations of the data (all the fields, and just the CID). Again, not a blocker for me though.
Good question @aschmahmann, I'm not sure there's a clean answer (or that I'm the best person to provide one!); except to say that I think there should be a reasonable expectation of consistent behaviour of an ipld.Node
based on inspecting its Kind()
. A PBLink
is a Kind_Map
and making it act like a link might lead to some funky (unexpected) behaviour in strange parts of a system using it.
You could look at #51 with that lens and see how the approach here is a bit cleaner. Not that #51 has obvious breakage potential, but this approach has the standard mapping of Kind:Behaviour.
When making a map iterator over a directory, calls to
.Next()
currently return a value of theFieldHash()
of the dagpb link.This change has them instead return a
IterLink
.In both cases, the "exposed" interface of the returned type,
AsLink()
exposes the underlying hash cidLink to the entry.By using a wrapping
IterLink
type, we provide an opportunity to type-cast the response, and instead of treating the response under it's returnedipld.Node
interface, the client has the ability to do something of the form: