-
Notifications
You must be signed in to change notification settings - Fork 49
/
simplebytes.go
75 lines (69 loc) · 2.21 KB
/
simplebytes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
74
75
package testutil
import (
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/node/basicnode"
"github.com/ipld/go-ipld-prime/node/mixins"
)
var _ datamodel.Node = simpleBytes(nil)
// simpleBytes is like basicnode's plainBytes but it doesn't implement
// LargeBytesNode so we can exercise the non-LBN case.
type simpleBytes []byte
// NewSimpleBytes is identical to basicnode.NewBytes but the returned node
// doesn't implement LargeBytesNode, which can be useful for testing cases
// where we want to exercise non-LBN code paths.
func NewSimpleBytes(value []byte) datamodel.Node {
v := simpleBytes(value)
return &v
}
// -- Node interface methods -->
func (simpleBytes) Kind() datamodel.Kind {
return datamodel.Kind_Bytes
}
func (simpleBytes) LookupByString(string) (datamodel.Node, error) {
return mixins.Bytes{TypeName: "bytes"}.LookupByString("")
}
func (simpleBytes) LookupByNode(key datamodel.Node) (datamodel.Node, error) {
return mixins.Bytes{TypeName: "bytes"}.LookupByNode(nil)
}
func (simpleBytes) LookupByIndex(idx int64) (datamodel.Node, error) {
return mixins.Bytes{TypeName: "bytes"}.LookupByIndex(0)
}
func (simpleBytes) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
return mixins.Bytes{TypeName: "bytes"}.LookupBySegment(seg)
}
func (simpleBytes) MapIterator() datamodel.MapIterator {
return nil
}
func (simpleBytes) ListIterator() datamodel.ListIterator {
return nil
}
func (simpleBytes) Length() int64 {
return -1
}
func (simpleBytes) IsAbsent() bool {
return false
}
func (simpleBytes) IsNull() bool {
return false
}
func (simpleBytes) AsBool() (bool, error) {
return mixins.Bytes{TypeName: "bytes"}.AsBool()
}
func (simpleBytes) AsInt() (int64, error) {
return mixins.Bytes{TypeName: "bytes"}.AsInt()
}
func (simpleBytes) AsFloat() (float64, error) {
return mixins.Bytes{TypeName: "bytes"}.AsFloat()
}
func (simpleBytes) AsString() (string, error) {
return mixins.Bytes{TypeName: "bytes"}.AsString()
}
func (n simpleBytes) AsBytes() ([]byte, error) {
return []byte(n), nil
}
func (simpleBytes) AsLink() (datamodel.Link, error) {
return mixins.Bytes{TypeName: "bytes"}.AsLink()
}
func (simpleBytes) Prototype() datamodel.NodePrototype {
return basicnode.Prototype__Bytes{}
}