Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ld
go-ld-prime
Commits
420ebbf1
Commit
420ebbf1
authored
Feb 05, 2020
by
Eric Myhre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stamp out remaining mixins.
parent
b98d1ef0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
464 additions
and
0 deletions
+464
-0
_rsrch/nodesolution/impls/mixins/boolMixin.go
_rsrch/nodesolution/impls/mixins/boolMixin.go
+94
-0
_rsrch/nodesolution/impls/mixins/bytesMixin.go
_rsrch/nodesolution/impls/mixins/bytesMixin.go
+94
-0
_rsrch/nodesolution/impls/mixins/floatMixin.go
_rsrch/nodesolution/impls/mixins/floatMixin.go
+94
-0
_rsrch/nodesolution/impls/mixins/linkMixin.go
_rsrch/nodesolution/impls/mixins/linkMixin.go
+97
-0
_rsrch/nodesolution/impls/mixins/listMixin.go
_rsrch/nodesolution/impls/mixins/listMixin.go
+85
-0
No files found.
_rsrch/nodesolution/impls/mixins/boolMixin.go
0 → 100644
View file @
420ebbf1
package
mixins
import
(
ipld
"github.com/ipld/go-ipld-prime/_rsrch/nodesolution"
)
// Bool can be embedded in a struct to provide all the methods that
// have fixed output for any int-kinded nodes.
// (Mostly this includes all the methods which simply return ErrWrongKind.)
// Other methods will still need to be implemented to finish conforming to Node.
//
// To conserve memory and get a TypeName in errors without embedding,
// write methods on your type with a body that simply initializes this struct
// and immediately uses the relevant method;
// this is more verbose in source, but compiles to a tighter result:
// in memory, there's no embed; and in runtime, the calls will be inlined
// and thus have no cost in execution time.
type
Bool
struct
{
TypeName
string
}
func
(
Bool
)
ReprKind
()
ipld
.
ReprKind
{
return
ipld
.
ReprKind_Bool
}
func
(
x
Bool
)
LookupString
(
string
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
Bool
)
Lookup
(
key
ipld
.
Node
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"Lookup"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
Bool
)
LookupIndex
(
idx
int
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupIndex"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustList
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
Bool
)
LookupSegment
(
ipld
.
PathSegment
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupSegment"
,
AppropriateKind
:
ipld
.
ReprKindSet_Recursive
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
Bool
)
MapIterator
()
ipld
.
MapIterator
{
return
nil
}
func
(
Bool
)
ListIterator
()
ipld
.
ListIterator
{
return
nil
}
func
(
Bool
)
Length
()
int
{
return
-
1
}
func
(
Bool
)
IsUndefined
()
bool
{
return
false
}
func
(
Bool
)
IsNull
()
bool
{
return
false
}
func
(
x
Bool
)
AsInt
()
(
int
,
error
)
{
return
0
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsInt"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustInt
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
Bool
)
AsFloat
()
(
float64
,
error
)
{
return
0
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsFloat"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustFloat
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
Bool
)
AsString
()
(
string
,
error
)
{
return
""
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustString
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
Bool
)
AsBytes
()
([]
byte
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsBytes"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBytes
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
Bool
)
AsLink
()
(
ipld
.
Link
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsLink"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustLink
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
// BoolAssembler has similar purpose as Bool, but for (you guessed it)
// the NodeAssembler interface rather than the Node interface.
type
BoolAssembler
struct
{
TypeName
string
}
func
(
x
BoolAssembler
)
BeginMap
(
sizeHint
int
)
(
ipld
.
MapNodeAssembler
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"BeginMap"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
BoolAssembler
)
BeginList
(
sizeHint
int
)
(
ipld
.
ListNodeAssembler
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"BeginList"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustList
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
BoolAssembler
)
AssignNull
()
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignNull"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustNull
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
BoolAssembler
)
AssignInt
(
int
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignInt"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustInt
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
BoolAssembler
)
AssignFloat
(
float64
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignFloat"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustFloat
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
BoolAssembler
)
AssignString
(
string
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustString
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
func
(
x
BoolAssembler
)
AssignBytes
([]
byte
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignBytes"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBytes
,
ActualKind
:
ipld
.
ReprKind_Bool
}
}
_rsrch/nodesolution/impls/mixins/bytesMixin.go
0 → 100644
View file @
420ebbf1
package
mixins
import
(
ipld
"github.com/ipld/go-ipld-prime/_rsrch/nodesolution"
)
// Bytes can be embedded in a struct to provide all the methods that
// have fixed output for any int-kinded nodes.
// (Mostly this includes all the methods which simply return ErrWrongKind.)
// Other methods will still need to be implemented to finish conforming to Node.
//
// To conserve memory and get a TypeName in errors without embedding,
// write methods on your type with a body that simply initializes this struct
// and immediately uses the relevant method;
// this is more verbose in source, but compiles to a tighter result:
// in memory, there's no embed; and in runtime, the calls will be inlined
// and thus have no cost in execution time.
type
Bytes
struct
{
TypeName
string
}
func
(
Bytes
)
ReprKind
()
ipld
.
ReprKind
{
return
ipld
.
ReprKind_Bytes
}
func
(
x
Bytes
)
LookupString
(
string
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
Bytes
)
Lookup
(
key
ipld
.
Node
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"Lookup"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
Bytes
)
LookupIndex
(
idx
int
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupIndex"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustList
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
Bytes
)
LookupSegment
(
ipld
.
PathSegment
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupSegment"
,
AppropriateKind
:
ipld
.
ReprKindSet_Recursive
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
Bytes
)
MapIterator
()
ipld
.
MapIterator
{
return
nil
}
func
(
Bytes
)
ListIterator
()
ipld
.
ListIterator
{
return
nil
}
func
(
Bytes
)
Length
()
int
{
return
-
1
}
func
(
Bytes
)
IsUndefined
()
bool
{
return
false
}
func
(
Bytes
)
IsNull
()
bool
{
return
false
}
func
(
x
Bytes
)
AsBool
()
(
bool
,
error
)
{
return
false
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsBool"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBool
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
Bytes
)
AsInt
()
(
int
,
error
)
{
return
0
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsInt"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustInt
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
Bytes
)
AsFloat
()
(
float64
,
error
)
{
return
0
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsFloat"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustFloat
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
Bytes
)
AsString
()
(
string
,
error
)
{
return
""
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustString
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
Bytes
)
AsLink
()
(
ipld
.
Link
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsLink"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustLink
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
// BytesAssembler has similar purpose as Bytes, but for (you guessed it)
// the NodeAssembler interface rather than the Node interface.
type
BytesAssembler
struct
{
TypeName
string
}
func
(
x
BytesAssembler
)
BeginMap
(
sizeHint
int
)
(
ipld
.
MapNodeAssembler
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"BeginMap"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
BytesAssembler
)
BeginList
(
sizeHint
int
)
(
ipld
.
ListNodeAssembler
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"BeginList"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustList
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
BytesAssembler
)
AssignNull
()
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignNull"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustNull
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
BytesAssembler
)
AssignBool
(
bool
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignBool"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBool
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
BytesAssembler
)
AssignInt
(
int
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignInt"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustInt
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
BytesAssembler
)
AssignFloat
(
float64
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignFloat"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustFloat
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
func
(
x
BytesAssembler
)
AssignString
(
string
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustString
,
ActualKind
:
ipld
.
ReprKind_Bytes
}
}
_rsrch/nodesolution/impls/mixins/floatMixin.go
0 → 100644
View file @
420ebbf1
package
mixins
import
(
ipld
"github.com/ipld/go-ipld-prime/_rsrch/nodesolution"
)
// Float can be embedded in a struct to provide all the methods that
// have fixed output for any int-kinded nodes.
// (Mostly this includes all the methods which simply return ErrWrongKind.)
// Other methods will still need to be implemented to finish conforming to Node.
//
// To conserve memory and get a TypeName in errors without embedding,
// write methods on your type with a body that simply initializes this struct
// and immediately uses the relevant method;
// this is more verbose in source, but compiles to a tighter result:
// in memory, there's no embed; and in runtime, the calls will be inlined
// and thus have no cost in execution time.
type
Float
struct
{
TypeName
string
}
func
(
Float
)
ReprKind
()
ipld
.
ReprKind
{
return
ipld
.
ReprKind_Float
}
func
(
x
Float
)
LookupString
(
string
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
Float
)
Lookup
(
key
ipld
.
Node
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"Lookup"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
Float
)
LookupIndex
(
idx
int
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupIndex"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustList
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
Float
)
LookupSegment
(
ipld
.
PathSegment
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupSegment"
,
AppropriateKind
:
ipld
.
ReprKindSet_Recursive
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
Float
)
MapIterator
()
ipld
.
MapIterator
{
return
nil
}
func
(
Float
)
ListIterator
()
ipld
.
ListIterator
{
return
nil
}
func
(
Float
)
Length
()
int
{
return
-
1
}
func
(
Float
)
IsUndefined
()
bool
{
return
false
}
func
(
Float
)
IsNull
()
bool
{
return
false
}
func
(
x
Float
)
AsBool
()
(
bool
,
error
)
{
return
false
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsBool"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBool
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
Float
)
AsInt
()
(
int
,
error
)
{
return
0
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsInt"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustInt
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
Float
)
AsString
()
(
string
,
error
)
{
return
""
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustString
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
Float
)
AsBytes
()
([]
byte
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsBytes"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBytes
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
Float
)
AsLink
()
(
ipld
.
Link
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsLink"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustLink
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
// FloatAssembler has similar purpose as Float, but for (you guessed it)
// the NodeAssembler interface rather than the Node interface.
type
FloatAssembler
struct
{
TypeName
string
}
func
(
x
FloatAssembler
)
BeginMap
(
sizeHint
int
)
(
ipld
.
MapNodeAssembler
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"BeginMap"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
FloatAssembler
)
BeginList
(
sizeHint
int
)
(
ipld
.
ListNodeAssembler
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"BeginList"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustList
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
FloatAssembler
)
AssignNull
()
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignNull"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustNull
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
FloatAssembler
)
AssignBool
(
bool
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignBool"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBool
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
FloatAssembler
)
AssignInt
(
int
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignInt"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustInt
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
FloatAssembler
)
AssignString
(
string
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustString
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
func
(
x
FloatAssembler
)
AssignBytes
([]
byte
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignBytes"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBytes
,
ActualKind
:
ipld
.
ReprKind_Float
}
}
_rsrch/nodesolution/impls/mixins/linkMixin.go
0 → 100644
View file @
420ebbf1
package
mixins
import
(
ipld
"github.com/ipld/go-ipld-prime/_rsrch/nodesolution"
)
// Link can be embedded in a struct to provide all the methods that
// have fixed output for any int-kinded nodes.
// (Mostly this includes all the methods which simply return ErrWrongKind.)
// Other methods will still need to be implemented to finish conforming to Node.
//
// To conserve memory and get a TypeName in errors without embedding,
// write methods on your type with a body that simply initializes this struct
// and immediately uses the relevant method;
// this is more verbose in source, but compiles to a tighter result:
// in memory, there's no embed; and in runtime, the calls will be inlined
// and thus have no cost in execution time.
type
Link
struct
{
TypeName
string
}
func
(
Link
)
ReprKind
()
ipld
.
ReprKind
{
return
ipld
.
ReprKind_Link
}
func
(
x
Link
)
LookupString
(
string
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
Link
)
Lookup
(
key
ipld
.
Node
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"Lookup"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
Link
)
LookupIndex
(
idx
int
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupIndex"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustList
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
Link
)
LookupSegment
(
ipld
.
PathSegment
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupSegment"
,
AppropriateKind
:
ipld
.
ReprKindSet_Recursive
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
Link
)
MapIterator
()
ipld
.
MapIterator
{
return
nil
}
func
(
Link
)
ListIterator
()
ipld
.
ListIterator
{
return
nil
}
func
(
Link
)
Length
()
int
{
return
-
1
}
func
(
Link
)
IsUndefined
()
bool
{
return
false
}
func
(
Link
)
IsNull
()
bool
{
return
false
}
func
(
x
Link
)
AsBool
()
(
bool
,
error
)
{
return
false
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsBool"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBool
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
Link
)
AsInt
()
(
int
,
error
)
{
return
0
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsInt"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustInt
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
Link
)
AsFloat
()
(
float64
,
error
)
{
return
0
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsFloat"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustFloat
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
Link
)
AsString
()
(
string
,
error
)
{
return
""
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustString
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
Link
)
AsBytes
()
([]
byte
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsBytes"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBytes
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
// LinkAssembler has similar purpose as Link, but for (you guessed it)
// the NodeAssembler interface rather than the Node interface.
type
LinkAssembler
struct
{
TypeName
string
}
func
(
x
LinkAssembler
)
BeginMap
(
sizeHint
int
)
(
ipld
.
MapNodeAssembler
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"BeginMap"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
LinkAssembler
)
BeginList
(
sizeHint
int
)
(
ipld
.
ListNodeAssembler
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"BeginList"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustList
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
LinkAssembler
)
AssignNull
()
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignNull"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustNull
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
LinkAssembler
)
AssignBool
(
bool
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignBool"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBool
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
LinkAssembler
)
AssignInt
(
int
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignInt"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustInt
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
LinkAssembler
)
AssignFloat
(
float64
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignFloat"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustFloat
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
LinkAssembler
)
AssignString
(
string
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustString
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
func
(
x
LinkAssembler
)
AssignBytes
([]
byte
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignBytes"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBytes
,
ActualKind
:
ipld
.
ReprKind_Link
}
}
_rsrch/nodesolution/impls/mixins/listMixin.go
0 → 100644
View file @
420ebbf1
package
mixins
import
(
ipld
"github.com/ipld/go-ipld-prime/_rsrch/nodesolution"
)
// List can be embedded in a struct to provide all the methods that
// have fixed output for any int-kinded nodes.
// (Mostly this includes all the methods which simply return ErrWrongKind.)
// Other methods will still need to be implemented to finish conforming to Node.
//
// To conserve memory and get a TypeName in errors without embedding,
// write methods on your type with a body that simply initializes this struct
// and immediately uses the relevant method;
// this is more verbose in source, but compiles to a tighter result:
// in memory, there's no embed; and in runtime, the calls will be inlined
// and thus have no cost in execution time.
type
List
struct
{
TypeName
string
}
func
(
List
)
ReprKind
()
ipld
.
ReprKind
{
return
ipld
.
ReprKind_List
}
func
(
x
List
)
LookupString
(
string
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"LookupString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
x
List
)
Lookup
(
key
ipld
.
Node
)
(
ipld
.
Node
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"Lookup"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
List
)
MapIterator
()
ipld
.
MapIterator
{
return
nil
}
func
(
List
)
IsUndefined
()
bool
{
return
false
}
func
(
List
)
IsNull
()
bool
{
return
false
}
func
(
x
List
)
AsBool
()
(
bool
,
error
)
{
return
false
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsBool"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBool
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
x
List
)
AsInt
()
(
int
,
error
)
{
return
0
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsInt"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustInt
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
x
List
)
AsFloat
()
(
float64
,
error
)
{
return
0
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsFloat"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustFloat
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
x
List
)
AsString
()
(
string
,
error
)
{
return
""
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustString
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
x
List
)
AsBytes
()
([]
byte
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsBytes"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBytes
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
x
List
)
AsLink
()
(
ipld
.
Link
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AsLink"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustLink
,
ActualKind
:
ipld
.
ReprKind_List
}
}
// ListAssembler has similar purpose as List, but for (you guessed it)
// the NodeAssembler interface rather than the Node interface.
type
ListAssembler
struct
{
TypeName
string
}
func
(
x
ListAssembler
)
BeginMap
(
sizeHint
int
)
(
ipld
.
MapNodeAssembler
,
error
)
{
return
nil
,
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"BeginMap"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustMap
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
x
ListAssembler
)
AssignNull
()
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignNull"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustNull
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
x
ListAssembler
)
AssignBool
(
bool
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignBool"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBool
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
x
ListAssembler
)
AssignInt
(
int
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignInt"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustInt
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
x
ListAssembler
)
AssignFloat
(
float64
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignFloat"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustFloat
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
x
ListAssembler
)
AssignString
(
string
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignString"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustString
,
ActualKind
:
ipld
.
ReprKind_List
}
}
func
(
x
ListAssembler
)
AssignBytes
([]
byte
)
error
{
return
ipld
.
ErrWrongKind
{
TypeName
:
x
.
TypeName
,
MethodName
:
"AssignBytes"
,
AppropriateKind
:
ipld
.
ReprKindSet_JustBytes
,
ActualKind
:
ipld
.
ReprKind_List
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment