node.go 1.06 KB
Newer Older
Eric Myhre's avatar
Eric Myhre committed
1 2
package ipld

3 4
import "github.com/ipfs/go-cid"

Eric Myhre's avatar
Eric Myhre committed
5
type Node interface {
6
	// GetField resolves a path in the the object and returns
7 8 9 10 11 12 13 14
	// either a primitive (e.g. string, int, etc), a link (type CID),
	// or another Node.
	//
	// If a Node is returned, it will be a unrooted node -- that is,
	// it can be used to view the fields below it, but since it was not
	// originally stored as a full node, you cannot immediately take
	// a link to it for embedding in other objects (you'd have to make
	// a new RootNode with the same content first, then store that).
Eric Myhre's avatar
Eric Myhre committed
15
	TraverseField(path string) (Node, error)
16 17 18 19 20

	// GetIndex is the equivalent of GetField but for indexing into an array
	// (or a numerically-keyed map).  Like GetField, it returns
	// either a primitive (e.g. string, int, etc), a link (type CID),
	// or another Node.
Eric Myhre's avatar
Eric Myhre committed
21
	TraverseIndex(idx int) (Node, error)
Eric Myhre's avatar
Eric Myhre committed
22

Eric Myhre's avatar
Eric Myhre committed
23 24 25 26
	AsBool() (bool, error)
	AsString() (string, error)
	AsInt() (int, error)
	AsLink() (cid.Cid, error)
Eric Myhre's avatar
Eric Myhre committed
27
}
28 29

type SerializableNode interface {
30
	CID() cid.Cid
31 32 33
}

type MutableNode interface {
34
	// FUTURE: setter methods go here
35
}