Skip to content

Commit

Permalink
Merge pull request #127 from mvdan/kind-renames
Browse files Browse the repository at this point in the history
all: rename schema.Kind to TypeKind, ipld.ReprKind to Kind
  • Loading branch information
warpfork authored Dec 27, 2020
2 parents 6e6625b + 2d7d25c commit 4dc6893
Show file tree
Hide file tree
Showing 114 changed files with 1,628 additions and 1,628 deletions.
4 changes: 2 additions & 2 deletions _rsrch/nodestyle/nodeStyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"io"
)

type ReprKind uint8
type Kind uint8

type Node interface {
ReprKind() ReprKind
Kind() Kind
LookupByString(key string) (Node, error)
LookupByNode(key Node) (Node, error)
LookupByIndex(idx int) (Node, error)
Expand Down
6 changes: 3 additions & 3 deletions adl/rot13adl/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func ExampleUnmarshallingToADL() {
fmt.Printf("reify error: %v\n", err)

// We can inspect the synthetic ADL node like any other node!
fmt.Printf("adl node kind: %v\n", syntheticView.ReprKind())
fmt.Printf("adl node kind: %v\n", syntheticView.Kind())
fmt.Printf("adl view value: %q\n", must.String(syntheticView))

// Output:
Expand All @@ -48,13 +48,13 @@ func ExampleCreatingViaADL() {
n := nb.Build()

// We can inspect the synthetic ADL node like any other node!
fmt.Printf("adl node kind: %v\n", n.ReprKind())
fmt.Printf("adl node kind: %v\n", n.Kind())
fmt.Printf("adl view value: %q\n", must.String(n))

// We can get the substrate view and examine that as a node too.
// (This requires a cast to see that we have an ADL, though. Not all IPLD nodes have a 'Substrate' property.)
substrateNode := n.(rot13adl.R13String).Substrate()
fmt.Printf("substrate node kind: %v\n", substrateNode.ReprKind())
fmt.Printf("substrate node kind: %v\n", substrateNode.Kind())
fmt.Printf("substrate value: %q\n", must.String(substrateNode))

// To marshal the ADL, just use marshal methods on its substrate as normal:
Expand Down
4 changes: 2 additions & 2 deletions adl/rot13adl/rot13node.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type _R13String struct {
synthesized string // the content that the ADL presents. calculated proactively from the original, in this implementation (though you could imagine implementing it lazily, in either direction, too).
}

func (*_R13String) ReprKind() ipld.ReprKind {
return ipld.ReprKind_String
func (*_R13String) Kind() ipld.Kind {
return ipld.Kind_String
}
func (*_R13String) LookupByString(string) (ipld.Node, error) {
return mixins.String{TypeName: "rot13adl.R13String"}.LookupByString("")
Expand Down
4 changes: 2 additions & 2 deletions adl/rot13adl/rot13node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestReify(t *testing.T) {
synth, err := Reify(sn)
// Inspect the resulting high level node.
Require(t, err, ShouldEqual, nil)
Wish(t, synth.ReprKind(), ShouldEqual, ipld.ReprKind_String)
Wish(t, synth.Kind(), ShouldEqual, ipld.Kind_String)
s, err := synth.AsString()
Wish(t, err, ShouldEqual, nil)
Wish(t, s, ShouldEqual, "abcd")
Expand All @@ -54,7 +54,7 @@ func TestReify(t *testing.T) {
synth, err := Reify(sn)
// Inspect the resulting high level node.
Require(t, err, ShouldEqual, nil)
Wish(t, synth.ReprKind(), ShouldEqual, ipld.ReprKind_String)
Wish(t, synth.Kind(), ShouldEqual, ipld.Kind_String)
s, err := synth.AsString()
Wish(t, err, ShouldEqual, nil)
Wish(t, s, ShouldEqual, "abcd")
Expand Down
4 changes: 2 additions & 2 deletions adl/rot13adl/rot13substrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type _Substrate _R13String
// and I'm not sure what, if any, suffix actually makes meaningful sense to a user either.
// I added the segment ".internal." to the middle of the name mangle; does this seem helpful?

func (*_Substrate) ReprKind() ipld.ReprKind {
return ipld.ReprKind_String
func (*_Substrate) Kind() ipld.Kind {
return ipld.Kind_String
}
func (*_Substrate) LookupByString(string) (ipld.Node, error) {
return mixins.String{TypeName: "rot13adl.internal.Substrate"}.LookupByString("")
Expand Down
44 changes: 22 additions & 22 deletions codec/codectools/token_producers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func TokenWalk(n ipld.Node, visitFn func(tk *Token) error) error {
}

func tokenWalk(tk *Token, n ipld.Node, visitFn func(*Token) error) error {
switch n.ReprKind() {
case ipld.ReprKind_Map:
switch n.Kind() {
case ipld.Kind_Map:
tk.Kind = TokenKind_MapOpen
tk.Length = n.Length()
tk.Node = n
Expand All @@ -64,7 +64,7 @@ func tokenWalk(tk *Token, n ipld.Node, visitFn func(*Token) error) error {
tk.Kind = TokenKind_MapClose
tk.Node = n
return visitFn(tk)
case ipld.ReprKind_List:
case ipld.Kind_List:
tk.Kind = TokenKind_ListOpen
tk.Length = n.Length()
tk.Node = n
Expand All @@ -84,36 +84,36 @@ func tokenWalk(tk *Token, n ipld.Node, visitFn func(*Token) error) error {
tk.Kind = TokenKind_ListClose
tk.Node = n
return visitFn(tk)
case ipld.ReprKind_Null:
case ipld.Kind_Null:
tk.Kind = TokenKind_Null
return visitFn(tk)
case ipld.ReprKind_Bool:
case ipld.Kind_Bool:
tk.Kind = TokenKind_Bool
tk.Bool, _ = n.AsBool()
return visitFn(tk)
case ipld.ReprKind_Int:
case ipld.Kind_Int:
tk.Kind = TokenKind_Int
i, _ := n.AsInt()
tk.Int = int64(i) // TODO: upgrade all of ipld to use high precision int consistently
return visitFn(tk)
case ipld.ReprKind_Float:
case ipld.Kind_Float:
tk.Kind = TokenKind_Float
tk.Float, _ = n.AsFloat()
return visitFn(tk)
case ipld.ReprKind_String:
case ipld.Kind_String:
tk.Kind = TokenKind_String
tk.Str, _ = n.AsString()
return visitFn(tk)
case ipld.ReprKind_Bytes:
case ipld.Kind_Bytes:
tk.Kind = TokenKind_Bytes
tk.Bytes, _ = n.AsBytes()
return visitFn(tk)
case ipld.ReprKind_Link:
case ipld.Kind_Link:
tk.Kind = TokenKind_Link
tk.Link, _ = n.AsLink()
return visitFn(tk)
default:
panic(fmt.Errorf("unrecognized node kind (%q?)", n.ReprKind()))
panic(fmt.Errorf("unrecognized node kind (%q?)", n.Kind()))
}
return nil
}
Expand Down Expand Up @@ -195,58 +195,58 @@ func (nt *NodeTokenizer) ReadToken() (next *Token, err error) {
tip := nt.stk.Tip()
switch tip.state {
case 0:
switch tip.n.ReprKind() {
case ipld.ReprKind_Map:
switch tip.n.Kind() {
case ipld.Kind_Map:
nt.tk.Kind = TokenKind_MapOpen
nt.tk.Length = tip.n.Length()
nt.tk.Node = tip.n
tip.state = 2
tip.mitr = tip.n.MapIterator()
return &nt.tk, nil
case ipld.ReprKind_List:
case ipld.Kind_List:
nt.tk.Kind = TokenKind_ListOpen
nt.tk.Length = tip.n.Length()
nt.tk.Node = tip.n
tip.state = 1
tip.litr = tip.n.ListIterator()
return &nt.tk, nil
case ipld.ReprKind_Null:
case ipld.Kind_Null:
nt.tk.Kind = TokenKind_Null
nt.stk.Pop()
return &nt.tk, nil
case ipld.ReprKind_Bool:
case ipld.Kind_Bool:
nt.tk.Kind = TokenKind_Bool
nt.tk.Bool, _ = tip.n.AsBool()
nt.stk.Pop()
return &nt.tk, nil
case ipld.ReprKind_Int:
case ipld.Kind_Int:
nt.tk.Kind = TokenKind_Int
i, _ := tip.n.AsInt()
nt.tk.Int = int64(i) // TODO: upgrade all of ipld to use high precision int consistently
nt.stk.Pop()
return &nt.tk, nil
case ipld.ReprKind_Float:
case ipld.Kind_Float:
nt.tk.Kind = TokenKind_Float
nt.tk.Float, _ = tip.n.AsFloat()
nt.stk.Pop()
return &nt.tk, nil
case ipld.ReprKind_String:
case ipld.Kind_String:
nt.tk.Kind = TokenKind_String
nt.tk.Str, _ = tip.n.AsString()
nt.stk.Pop()
return &nt.tk, nil
case ipld.ReprKind_Bytes:
case ipld.Kind_Bytes:
nt.tk.Kind = TokenKind_Bytes
nt.tk.Bytes, _ = tip.n.AsBytes()
nt.stk.Pop()
return &nt.tk, nil
case ipld.ReprKind_Link:
case ipld.Kind_Link:
nt.tk.Kind = TokenKind_Link
nt.tk.Link, _ = tip.n.AsLink()
nt.stk.Pop()
return &nt.tk, nil
default:
panic(fmt.Errorf("unrecognized node kind (%q?)", tip.n.ReprKind()))
panic(fmt.Errorf("unrecognized node kind (%q?)", tip.n.Kind()))
}
case 1:
if tip.litr.Done() {
Expand Down
24 changes: 12 additions & 12 deletions codec/dagcbor/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ import (
)

// This should be identical to the general feature in the parent package,
// except for the `case ipld.ReprKind_Link` block,
// except for the `case ipld.Kind_Link` block,
// which is dag-cbor's special sauce for schemafree links.
func Marshal(n ipld.Node, sink shared.TokenSink) error {
var tk tok.Token
return marshal(n, &tk, sink)
}

func marshal(n ipld.Node, tk *tok.Token, sink shared.TokenSink) error {
switch n.ReprKind() {
case ipld.ReprKind_Invalid:
switch n.Kind() {
case ipld.Kind_Invalid:
return fmt.Errorf("cannot traverse a node that is absent")
case ipld.ReprKind_Null:
case ipld.Kind_Null:
tk.Type = tok.TNull
_, err := sink.Step(tk)
return err
case ipld.ReprKind_Map:
case ipld.Kind_Map:
// Emit start of map.
tk.Type = tok.TMapOpen
tk.Length = int(n.Length()) // TODO: overflow check
Expand Down Expand Up @@ -55,7 +55,7 @@ func marshal(n ipld.Node, tk *tok.Token, sink shared.TokenSink) error {
tk.Type = tok.TMapClose
_, err := sink.Step(tk)
return err
case ipld.ReprKind_List:
case ipld.Kind_List:
// Emit start of list.
tk.Type = tok.TArrOpen
l := n.Length()
Expand All @@ -77,7 +77,7 @@ func marshal(n ipld.Node, tk *tok.Token, sink shared.TokenSink) error {
tk.Type = tok.TArrClose
_, err := sink.Step(tk)
return err
case ipld.ReprKind_Bool:
case ipld.Kind_Bool:
v, err := n.AsBool()
if err != nil {
return err
Expand All @@ -86,7 +86,7 @@ func marshal(n ipld.Node, tk *tok.Token, sink shared.TokenSink) error {
tk.Bool = v
_, err = sink.Step(tk)
return err
case ipld.ReprKind_Int:
case ipld.Kind_Int:
v, err := n.AsInt()
if err != nil {
return err
Expand All @@ -95,7 +95,7 @@ func marshal(n ipld.Node, tk *tok.Token, sink shared.TokenSink) error {
tk.Int = int64(v)
_, err = sink.Step(tk)
return err
case ipld.ReprKind_Float:
case ipld.Kind_Float:
v, err := n.AsFloat()
if err != nil {
return err
Expand All @@ -104,7 +104,7 @@ func marshal(n ipld.Node, tk *tok.Token, sink shared.TokenSink) error {
tk.Float64 = v
_, err = sink.Step(tk)
return err
case ipld.ReprKind_String:
case ipld.Kind_String:
v, err := n.AsString()
if err != nil {
return err
Expand All @@ -113,7 +113,7 @@ func marshal(n ipld.Node, tk *tok.Token, sink shared.TokenSink) error {
tk.Str = v
_, err = sink.Step(tk)
return err
case ipld.ReprKind_Bytes:
case ipld.Kind_Bytes:
v, err := n.AsBytes()
if err != nil {
return err
Expand All @@ -122,7 +122,7 @@ func marshal(n ipld.Node, tk *tok.Token, sink shared.TokenSink) error {
tk.Bytes = v
_, err = sink.Step(tk)
return err
case ipld.ReprKind_Link:
case ipld.Kind_Link:
v, err := n.AsLink()
if err != nil {
return err
Expand Down
24 changes: 12 additions & 12 deletions codec/dagjson/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import (
)

// This should be identical to the general feature in the parent package,
// except for the `case ipld.ReprKind_Link` block,
// except for the `case ipld.Kind_Link` block,
// which is dag-json's special sauce for schemafree links.

func Marshal(n ipld.Node, sink shared.TokenSink) error {
var tk tok.Token
switch n.ReprKind() {
case ipld.ReprKind_Invalid:
switch n.Kind() {
case ipld.Kind_Invalid:
return fmt.Errorf("cannot traverse a node that is absent")
case ipld.ReprKind_Null:
case ipld.Kind_Null:
tk.Type = tok.TNull
_, err := sink.Step(&tk)
return err
case ipld.ReprKind_Map:
case ipld.Kind_Map:
// Emit start of map.
tk.Type = tok.TMapOpen
tk.Length = int(n.Length()) // TODO: overflow check
Expand Down Expand Up @@ -52,7 +52,7 @@ func Marshal(n ipld.Node, sink shared.TokenSink) error {
tk.Type = tok.TMapClose
_, err := sink.Step(&tk)
return err
case ipld.ReprKind_List:
case ipld.Kind_List:
// Emit start of list.
tk.Type = tok.TArrOpen
l := n.Length()
Expand All @@ -74,7 +74,7 @@ func Marshal(n ipld.Node, sink shared.TokenSink) error {
tk.Type = tok.TArrClose
_, err := sink.Step(&tk)
return err
case ipld.ReprKind_Bool:
case ipld.Kind_Bool:
v, err := n.AsBool()
if err != nil {
return err
Expand All @@ -83,7 +83,7 @@ func Marshal(n ipld.Node, sink shared.TokenSink) error {
tk.Bool = v
_, err = sink.Step(&tk)
return err
case ipld.ReprKind_Int:
case ipld.Kind_Int:
v, err := n.AsInt()
if err != nil {
return err
Expand All @@ -92,7 +92,7 @@ func Marshal(n ipld.Node, sink shared.TokenSink) error {
tk.Int = int64(v)
_, err = sink.Step(&tk)
return err
case ipld.ReprKind_Float:
case ipld.Kind_Float:
v, err := n.AsFloat()
if err != nil {
return err
Expand All @@ -101,7 +101,7 @@ func Marshal(n ipld.Node, sink shared.TokenSink) error {
tk.Float64 = v
_, err = sink.Step(&tk)
return err
case ipld.ReprKind_String:
case ipld.Kind_String:
v, err := n.AsString()
if err != nil {
return err
Expand All @@ -110,7 +110,7 @@ func Marshal(n ipld.Node, sink shared.TokenSink) error {
tk.Str = v
_, err = sink.Step(&tk)
return err
case ipld.ReprKind_Bytes:
case ipld.Kind_Bytes:
v, err := n.AsBytes()
if err != nil {
return err
Expand All @@ -119,7 +119,7 @@ func Marshal(n ipld.Node, sink shared.TokenSink) error {
tk.Bytes = v
_, err = sink.Step(&tk)
return err
case ipld.ReprKind_Link:
case ipld.Kind_Link:
v, err := n.AsLink()
if err != nil {
return err
Expand Down
Loading

0 comments on commit 4dc6893

Please sign in to comment.