thunks.go 2.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
package ipld

var Null Node = nullNode{}
var Undef Node = undefNode{}

type nullNode struct{}

func (nullNode) ReprKind() ReprKind {
	return ReprKind_Null
}
11 12
func (nullNode) LookupString(key string) (Node, error) {
	return nil, ErrWrongKind{MethodName: "<null>.LookupString", AppropriateKind: ReprKindSet_JustMap, ActualKind: ReprKind_Null}
13
}
14 15 16
func (nullNode) Lookup(key Node) (Node, error) {
	return nil, ErrWrongKind{MethodName: "<null>.Lookup", AppropriateKind: ReprKindSet_JustMap, ActualKind: ReprKind_Null}
}
17 18
func (nullNode) LookupIndex(idx int) (Node, error) {
	return nil, ErrWrongKind{MethodName: "<null>.LookupIndex", AppropriateKind: ReprKindSet_JustList, ActualKind: ReprKind_Null}
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
}
func (nullNode) MapIterator() MapIterator {
	return mapIteratorReject{ErrWrongKind{MethodName: "<null>.MapIterator", AppropriateKind: ReprKindSet_JustMap, ActualKind: ReprKind_Null}}
}
func (nullNode) ListIterator() ListIterator {
	return listIteratorReject{ErrWrongKind{MethodName: "<null>.ListIterator", AppropriateKind: ReprKindSet_JustList, ActualKind: ReprKind_Null}}
}
func (nullNode) Length() int {
	return -1
}
func (nullNode) IsUndefined() bool {
	return false
}
func (nullNode) IsNull() bool {
	return true
}
func (nullNode) AsBool() (bool, error) {
	return false, ErrWrongKind{MethodName: "<null>.AsBool", AppropriateKind: ReprKindSet_JustBool, ActualKind: ReprKind_Null}
}
func (nullNode) AsInt() (int, error) {
	return 0, ErrWrongKind{MethodName: "<null>.AsInt", AppropriateKind: ReprKindSet_JustInt, ActualKind: ReprKind_Null}
}
func (nullNode) AsFloat() (float64, error) {
	return 0, ErrWrongKind{MethodName: "<null>.AsFloat", AppropriateKind: ReprKindSet_JustFloat, ActualKind: ReprKind_Null}
}
func (nullNode) AsString() (string, error) {
	return "", ErrWrongKind{MethodName: "<null>.AsString", AppropriateKind: ReprKindSet_JustString, ActualKind: ReprKind_Null}
}
func (nullNode) AsBytes() ([]byte, error) {
	return nil, ErrWrongKind{MethodName: "<null>.AsBytes", AppropriateKind: ReprKindSet_JustBytes, ActualKind: ReprKind_Null}
}
func (nullNode) AsLink() (Link, error) {
	return nil, ErrWrongKind{MethodName: "<null>.AsLink", AppropriateKind: ReprKindSet_JustLink, ActualKind: ReprKind_Null}
}
func (nullNode) NodeBuilder() NodeBuilder {
	panic("cannot build null nodes")
}

type undefNode struct{ nullNode }

func (undefNode) IsUndefined() bool {
	return true
}
func (undefNode) IsNull() bool {
	return false
}

type mapIteratorReject struct{ err error }
type listIteratorReject struct{ err error }

func (itr mapIteratorReject) Next() (Node, Node, error) { return nil, nil, itr.err }
func (itr mapIteratorReject) Done() bool                { return false }

func (itr listIteratorReject) Next() (int, Node, error) { return -1, nil, itr.err }
func (itr listIteratorReject) Done() bool               { return false }