github.com/ipld/go-ipld-prime@v0.21.0/testutil/simplebytes.go (about) 1 package testutil 2 3 import ( 4 "github.com/ipld/go-ipld-prime/datamodel" 5 "github.com/ipld/go-ipld-prime/node/basicnode" 6 "github.com/ipld/go-ipld-prime/node/mixins" 7 ) 8 9 var _ datamodel.Node = simpleBytes(nil) 10 11 // simpleBytes is like basicnode's plainBytes but it doesn't implement 12 // LargeBytesNode so we can exercise the non-LBN case. 13 type simpleBytes []byte 14 15 // NewSimpleBytes is identical to basicnode.NewBytes but the returned node 16 // doesn't implement LargeBytesNode, which can be useful for testing cases 17 // where we want to exercise non-LBN code paths. 18 func NewSimpleBytes(value []byte) datamodel.Node { 19 v := simpleBytes(value) 20 return &v 21 } 22 23 // -- Node interface methods --> 24 25 func (simpleBytes) Kind() datamodel.Kind { 26 return datamodel.Kind_Bytes 27 } 28 func (simpleBytes) LookupByString(string) (datamodel.Node, error) { 29 return mixins.Bytes{TypeName: "bytes"}.LookupByString("") 30 } 31 func (simpleBytes) LookupByNode(key datamodel.Node) (datamodel.Node, error) { 32 return mixins.Bytes{TypeName: "bytes"}.LookupByNode(nil) 33 } 34 func (simpleBytes) LookupByIndex(idx int64) (datamodel.Node, error) { 35 return mixins.Bytes{TypeName: "bytes"}.LookupByIndex(0) 36 } 37 func (simpleBytes) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) { 38 return mixins.Bytes{TypeName: "bytes"}.LookupBySegment(seg) 39 } 40 func (simpleBytes) MapIterator() datamodel.MapIterator { 41 return nil 42 } 43 func (simpleBytes) ListIterator() datamodel.ListIterator { 44 return nil 45 } 46 func (simpleBytes) Length() int64 { 47 return -1 48 } 49 func (simpleBytes) IsAbsent() bool { 50 return false 51 } 52 func (simpleBytes) IsNull() bool { 53 return false 54 } 55 func (simpleBytes) AsBool() (bool, error) { 56 return mixins.Bytes{TypeName: "bytes"}.AsBool() 57 } 58 func (simpleBytes) AsInt() (int64, error) { 59 return mixins.Bytes{TypeName: "bytes"}.AsInt() 60 } 61 func (simpleBytes) AsFloat() (float64, error) { 62 return mixins.Bytes{TypeName: "bytes"}.AsFloat() 63 } 64 func (simpleBytes) AsString() (string, error) { 65 return mixins.Bytes{TypeName: "bytes"}.AsString() 66 } 67 func (n simpleBytes) AsBytes() ([]byte, error) { 68 return []byte(n), nil 69 } 70 func (simpleBytes) AsLink() (datamodel.Link, error) { 71 return mixins.Bytes{TypeName: "bytes"}.AsLink() 72 } 73 func (simpleBytes) Prototype() datamodel.NodePrototype { 74 return basicnode.Prototype__Bytes{} 75 }