-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When making a map iterator over a directory, calls to
.Next()
curre…
…ntly return a value of the `FieldHash()` 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 returned `ipld.Node` interface, the client has the ability to do something of the form: ``` k, next, err := iterator.Next() nextSize := next.(*iter.IterLink).Substrate.FieldSize() ```
- Loading branch information
Showing
2 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package iter | ||
|
||
import ( | ||
dagpb "github.com/ipld/go-codec-dagpb" | ||
"github.com/ipld/go-ipld-prime/datamodel" | ||
basicnode "github.com/ipld/go-ipld-prime/node/basic" | ||
) | ||
|
||
type IterLink struct { | ||
Substrate dagpb.PBLink | ||
} | ||
|
||
func (il *IterLink) AsBool() (bool, error) { | ||
return false, datamodel.ErrWrongKind{} | ||
} | ||
func (il *IterLink) AsBytes() ([]byte, error) { | ||
return nil, datamodel.ErrWrongKind{} | ||
} | ||
func (il *IterLink) AsFloat() (float64, error) { | ||
return 0.0, datamodel.ErrWrongKind{} | ||
} | ||
func (il *IterLink) AsInt() (int64, error) { | ||
return 0, datamodel.ErrWrongKind{} | ||
} | ||
func (il *IterLink) AsLink() (datamodel.Link, error) { | ||
return il.Substrate.FieldHash().AsLink() | ||
} | ||
func (il *IterLink) AsString() (string, error) { | ||
return "", datamodel.ErrWrongKind{} | ||
} | ||
|
||
func (il *IterLink) IsAbsent() bool { | ||
return il.Substrate.IsAbsent() | ||
} | ||
func (il *IterLink) IsNull() bool { | ||
return il.Substrate.IsNull() | ||
} | ||
func (il *IterLink) Kind() datamodel.Kind { | ||
return datamodel.Kind_Link | ||
} | ||
func (il *IterLink) Length() int64 { | ||
return 0 | ||
} | ||
func (il *IterLink) ListIterator() datamodel.ListIterator { | ||
return nil | ||
} | ||
func (il *IterLink) LookupByIndex(idx int64) (datamodel.Node, error) { | ||
return nil, datamodel.ErrWrongKind{} | ||
} | ||
func (il *IterLink) LookupByNode(key datamodel.Node) (datamodel.Node, error) { | ||
return nil, datamodel.ErrWrongKind{} | ||
} | ||
func (il *IterLink) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { | ||
return nil, datamodel.ErrWrongKind{} | ||
} | ||
func (il *IterLink) LookupByString(key string) (datamodel.Node, error) { | ||
return nil, datamodel.ErrWrongKind{} | ||
} | ||
func (il *IterLink) MapIterator() datamodel.MapIterator { | ||
return nil | ||
} | ||
func (il *IterLink) Prototype() datamodel.NodePrototype { | ||
return basicnode.Prototype__Link{} | ||
} | ||
func (il *IterLink) Representation() datamodel.Node { | ||
return il | ||
} |