diff --git a/blueprints/services/dagjson-over-http/client.go b/blueprints/services/dagjson-over-http/client.go index f223987..40987c3 100644 --- a/blueprints/services/dagjson-over-http/client.go +++ b/blueprints/services/dagjson-over-http/client.go @@ -257,6 +257,21 @@ func (c *{{.Type}}) {{.AsyncMethodDecl}} { c.ulk.Unlock() return nil, {{.ErrSchema}} } + // HTTP codes other than 200 correspond to service implementation rejecting the call when it is received + // for reasons unrelated to protocol schema + if resp.StatusCode != 200 { + resp.Body.Close() + if resp.Header != nil { + if errValues, ok := resp.Header["Error"]; ok && len(errValues) == 1 { + err = {{.ErrService}}{Cause: {{.Errorf}}("%s", errValues[0])} + } else { + err = {{.Errorf}}("service rejected the call, no cause provided") + } + } else { + err = {{.Errorf}}("service rejected the call") + } + return nil, err + } ch := make(chan {{.MethodReturnAsync}}, 1) go {{.ProcessReturnAsync}}(ctx, ch, resp.Body) diff --git a/blueprints/services/dagjson-over-http/server.go b/blueprints/services/dagjson-over-http/server.go index 3e7f285..cf8d777 100644 --- a/blueprints/services/dagjson-over-http/server.go +++ b/blueprints/services/dagjson-over-http/server.go @@ -69,7 +69,8 @@ func (x GoServerImpl) GoDef() cg.Blueprint { case env.{{.MethodName}} != nil: ch, err := s.{{.MethodName}}({{.ContextBackground}}(), env.{{.MethodName}}) if err != nil { - {{.LoggerVar}}.Errorf("get p2p provider rejected request (%v)", err) + {{.LoggerVar}}.Errorf("service rejected request (%v)", err) + writer.Header()["Error"] = []string{err.Error()} writer.WriteHeader(500) return } diff --git a/examples/gen-routing-api/proto/proto_edelweiss.go b/examples/gen-routing-api/proto/proto_edelweiss.go index 7a05127..60d1959 100644 --- a/examples/gen-routing-api/proto/proto_edelweiss.go +++ b/examples/gen-routing-api/proto/proto_edelweiss.go @@ -1,21 +1,21 @@ package proto import ( - pd7 "bytes" - pd8 "context" - pd11 "errors" - pd3 "fmt" - pd6 "io" - pd12 "net/http" - pd4 "net/url" - pd5 "sync" - - pd13 "github.com/ipfs/go-log" + pd11 "bytes" + pd10 "context" + pd12 "errors" + pd2 "fmt" + pd5 "io" + pd9 "net/http" + pd7 "net/url" + pd13 "sync" + + pd4 "github.com/ipfs/go-log" pd14 "github.com/ipld/edelweiss/services" - pd1 "github.com/ipld/edelweiss/values" - pd10 "github.com/ipld/go-ipld-prime" - pd9 "github.com/ipld/go-ipld-prime/codec/dagjson" - pd2 "github.com/ipld/go-ipld-prime/datamodel" + pd3 "github.com/ipld/edelweiss/values" + pd6 "github.com/ipld/go-ipld-prime" + pd8 "github.com/ipld/go-ipld-prime/codec/dagjson" + pd1 "github.com/ipld/go-ipld-prime/datamodel" ) // -- protocol type DelegatedRouting_IdentifyArg -- @@ -23,22 +23,22 @@ import ( type DelegatedRouting_IdentifyArg struct { } -func (x DelegatedRouting_IdentifyArg) Node() pd2.Node { +func (x DelegatedRouting_IdentifyArg) Node() pd1.Node { return x } -func (x *DelegatedRouting_IdentifyArg) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA +func (x *DelegatedRouting_IdentifyArg) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd1.ParseFunc{} + fieldMap := map[string]pd3.ParseFunc{} for !iter.Done() { if kn, vn, err := iter.Next(); err != nil { return err } else { if k, err := kn.AsString(); err != nil { - return pd3.Errorf("structure map key is not a string") + return pd2.Errorf("structure map key is not a string") } else { _ = vn switch k { @@ -48,7 +48,7 @@ func (x *DelegatedRouting_IdentifyArg) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -60,66 +60,66 @@ type DelegatedRouting_IdentifyArg_MapIterator struct { s *DelegatedRouting_IdentifyArg } -func (x *DelegatedRouting_IdentifyArg_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *DelegatedRouting_IdentifyArg_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { } - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } func (x *DelegatedRouting_IdentifyArg_MapIterator) Done() bool { return x.i+1 >= 0 } -func (x DelegatedRouting_IdentifyArg) Kind() pd2.Kind { - return pd2.Kind_Map +func (x DelegatedRouting_IdentifyArg) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x DelegatedRouting_IdentifyArg) LookupByString(key string) (pd2.Node, error) { +func (x DelegatedRouting_IdentifyArg) LookupByString(key string) (pd1.Node, error) { switch key { } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_IdentifyArg) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x DelegatedRouting_IdentifyArg) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_IdentifyArg) LookupByIndex(idx int64) (pd2.Node, error) { +func (x DelegatedRouting_IdentifyArg) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_IdentifyArg) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x DelegatedRouting_IdentifyArg) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_IdentifyArg) MapIterator() pd2.MapIterator { +func (x DelegatedRouting_IdentifyArg) MapIterator() pd1.MapIterator { return &DelegatedRouting_IdentifyArg_MapIterator{-1, &x} } -func (x DelegatedRouting_IdentifyArg) ListIterator() pd2.ListIterator { +func (x DelegatedRouting_IdentifyArg) ListIterator() pd1.ListIterator { return nil } @@ -136,54 +136,54 @@ func (x DelegatedRouting_IdentifyArg) IsNull() bool { } func (x DelegatedRouting_IdentifyArg) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x DelegatedRouting_IdentifyArg) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x DelegatedRouting_IdentifyArg) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x DelegatedRouting_IdentifyArg) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x DelegatedRouting_IdentifyArg) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_IdentifyArg) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x DelegatedRouting_IdentifyArg) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x DelegatedRouting_IdentifyArg) Prototype() pd2.NodePrototype { +func (x DelegatedRouting_IdentifyArg) Prototype() pd1.NodePrototype { return nil } // -- protocol type AnonList1 -- -type AnonList1 []pd1.String +type AnonList1 []pd3.String -func (v AnonList1) Node() pd2.Node { +func (v AnonList1) Node() pd1.Node { return v } -func (v *AnonList1) Parse(n pd2.Node) error { - if n.Kind() == pd2.Kind_Null { +func (v *AnonList1) Parse(n pd1.Node) error { + if n.Kind() == pd1.Kind_Null { *v = nil return nil } - if n.Kind() != pd2.Kind_List { - return pd1.ErrNA + if n.Kind() != pd1.Kind_List { + return pd3.ErrNA } else { *v = make(AnonList1, n.Length()) iter := n.ListIterator() for !iter.Done() { if i, n, err := iter.Next(); err != nil { - return pd1.ErrNA + return pd3.ErrNA } else if err = (*v)[i].Parse(n); err != nil { return err } @@ -192,39 +192,39 @@ func (v *AnonList1) Parse(n pd2.Node) error { } } -func (AnonList1) Kind() pd2.Kind { - return pd2.Kind_List +func (AnonList1) Kind() pd1.Kind { + return pd1.Kind_List } -func (AnonList1) LookupByString(string) (pd2.Node, error) { - return nil, pd1.ErrNA +func (AnonList1) LookupByString(string) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (AnonList1) LookupByNode(key pd2.Node) (pd2.Node, error) { - return nil, pd1.ErrNA +func (AnonList1) LookupByNode(key pd1.Node) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (v AnonList1) LookupByIndex(i int64) (pd2.Node, error) { +func (v AnonList1) LookupByIndex(i int64) (pd1.Node, error) { if i < 0 || i >= v.Length() { - return nil, pd1.ErrBounds + return nil, pd3.ErrBounds } else { return v[i].Node(), nil } } -func (v AnonList1) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (v AnonList1) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { if i, err := seg.Index(); err != nil { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } else { return v.LookupByIndex(i) } } -func (AnonList1) MapIterator() pd2.MapIterator { +func (AnonList1) MapIterator() pd1.MapIterator { return nil } -func (v AnonList1) ListIterator() pd2.ListIterator { +func (v AnonList1) ListIterator() pd1.ListIterator { return &AnonList1_ListIterator{v, 0} } @@ -241,30 +241,30 @@ func (AnonList1) IsNull() bool { } func (v AnonList1) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (AnonList1) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (AnonList1) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (AnonList1) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (AnonList1) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (AnonList1) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (AnonList1) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (AnonList1) Prototype() pd2.NodePrototype { +func (AnonList1) Prototype() pd1.NodePrototype { return nil // not needed } @@ -273,9 +273,9 @@ type AnonList1_ListIterator struct { at int64 } -func (iter *AnonList1_ListIterator) Next() (int64, pd2.Node, error) { +func (iter *AnonList1_ListIterator) Next() (int64, pd1.Node, error) { if iter.Done() { - return -1, nil, pd1.ErrBounds + return -1, nil, pd3.ErrBounds } v := iter.list[iter.at] i := int64(iter.at) @@ -293,16 +293,16 @@ type DelegatedRouting_IdentifyResult struct { Methods AnonList1 } -func (x DelegatedRouting_IdentifyResult) Node() pd2.Node { +func (x DelegatedRouting_IdentifyResult) Node() pd1.Node { return x } -func (x *DelegatedRouting_IdentifyResult) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA +func (x *DelegatedRouting_IdentifyResult) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd1.ParseFunc{ + fieldMap := map[string]pd3.ParseFunc{ "Methods": x.Methods.Parse, } for !iter.Done() { @@ -310,13 +310,13 @@ func (x *DelegatedRouting_IdentifyResult) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd3.Errorf("structure map key is not a string") + return pd2.Errorf("structure map key is not a string") } else { _ = vn switch k { case "Methods": if _, notParsed := fieldMap["Methods"]; !notParsed { - return pd3.Errorf("field %s already parsed", "Methods") + return pd2.Errorf("field %s already parsed", "Methods") } if err := x.Methods.Parse(vn); err != nil { return err @@ -328,7 +328,7 @@ func (x *DelegatedRouting_IdentifyResult) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -340,74 +340,74 @@ type DelegatedRouting_IdentifyResult_MapIterator struct { s *DelegatedRouting_IdentifyResult } -func (x *DelegatedRouting_IdentifyResult_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *DelegatedRouting_IdentifyResult_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd1.String("Methods"), x.s.Methods.Node(), nil + return pd3.String("Methods"), x.s.Methods.Node(), nil } - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } func (x *DelegatedRouting_IdentifyResult_MapIterator) Done() bool { return x.i+1 >= 1 } -func (x DelegatedRouting_IdentifyResult) Kind() pd2.Kind { - return pd2.Kind_Map +func (x DelegatedRouting_IdentifyResult) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x DelegatedRouting_IdentifyResult) LookupByString(key string) (pd2.Node, error) { +func (x DelegatedRouting_IdentifyResult) LookupByString(key string) (pd1.Node, error) { switch key { case "Methods": return x.Methods.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_IdentifyResult) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x DelegatedRouting_IdentifyResult) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_IdentifyResult) LookupByIndex(idx int64) (pd2.Node, error) { +func (x DelegatedRouting_IdentifyResult) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.Methods.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_IdentifyResult) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x DelegatedRouting_IdentifyResult) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "Methods": return x.Methods.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_IdentifyResult) MapIterator() pd2.MapIterator { +func (x DelegatedRouting_IdentifyResult) MapIterator() pd1.MapIterator { return &DelegatedRouting_IdentifyResult_MapIterator{-1, &x} } -func (x DelegatedRouting_IdentifyResult) ListIterator() pd2.ListIterator { +func (x DelegatedRouting_IdentifyResult) ListIterator() pd1.ListIterator { return nil } @@ -424,49 +424,49 @@ func (x DelegatedRouting_IdentifyResult) IsNull() bool { } func (x DelegatedRouting_IdentifyResult) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x DelegatedRouting_IdentifyResult) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x DelegatedRouting_IdentifyResult) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x DelegatedRouting_IdentifyResult) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x DelegatedRouting_IdentifyResult) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_IdentifyResult) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x DelegatedRouting_IdentifyResult) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x DelegatedRouting_IdentifyResult) Prototype() pd2.NodePrototype { +func (x DelegatedRouting_IdentifyResult) Prototype() pd1.NodePrototype { return nil } // -- protocol type DelegatedRouting_Error -- type DelegatedRouting_Error struct { - Code pd1.String + Code pd3.String } -func (x DelegatedRouting_Error) Node() pd2.Node { +func (x DelegatedRouting_Error) Node() pd1.Node { return x } -func (x *DelegatedRouting_Error) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA +func (x *DelegatedRouting_Error) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd1.ParseFunc{ + fieldMap := map[string]pd3.ParseFunc{ "Code": x.Code.Parse, } for !iter.Done() { @@ -474,13 +474,13 @@ func (x *DelegatedRouting_Error) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd3.Errorf("structure map key is not a string") + return pd2.Errorf("structure map key is not a string") } else { _ = vn switch k { case "Code": if _, notParsed := fieldMap["Code"]; !notParsed { - return pd3.Errorf("field %s already parsed", "Code") + return pd2.Errorf("field %s already parsed", "Code") } if err := x.Code.Parse(vn); err != nil { return err @@ -492,7 +492,7 @@ func (x *DelegatedRouting_Error) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -504,74 +504,74 @@ type DelegatedRouting_Error_MapIterator struct { s *DelegatedRouting_Error } -func (x *DelegatedRouting_Error_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *DelegatedRouting_Error_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd1.String("Code"), x.s.Code.Node(), nil + return pd3.String("Code"), x.s.Code.Node(), nil } - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } func (x *DelegatedRouting_Error_MapIterator) Done() bool { return x.i+1 >= 1 } -func (x DelegatedRouting_Error) Kind() pd2.Kind { - return pd2.Kind_Map +func (x DelegatedRouting_Error) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x DelegatedRouting_Error) LookupByString(key string) (pd2.Node, error) { +func (x DelegatedRouting_Error) LookupByString(key string) (pd1.Node, error) { switch key { case "Code": return x.Code.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_Error) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x DelegatedRouting_Error) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_Error) LookupByIndex(idx int64) (pd2.Node, error) { +func (x DelegatedRouting_Error) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.Code.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_Error) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x DelegatedRouting_Error) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "Code": return x.Code.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_Error) MapIterator() pd2.MapIterator { +func (x DelegatedRouting_Error) MapIterator() pd1.MapIterator { return &DelegatedRouting_Error_MapIterator{-1, &x} } -func (x DelegatedRouting_Error) ListIterator() pd2.ListIterator { +func (x DelegatedRouting_Error) ListIterator() pd1.ListIterator { return nil } @@ -588,30 +588,30 @@ func (x DelegatedRouting_Error) IsNull() bool { } func (x DelegatedRouting_Error) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x DelegatedRouting_Error) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x DelegatedRouting_Error) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x DelegatedRouting_Error) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x DelegatedRouting_Error) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x DelegatedRouting_Error) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x DelegatedRouting_Error) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x DelegatedRouting_Error) Prototype() pd2.NodePrototype { +func (x DelegatedRouting_Error) Prototype() pd1.NodePrototype { return nil } @@ -622,10 +622,10 @@ type AnonInductive4 struct { GetP2PProvide *GetP2PProvideRequest } -func (x *AnonInductive4) Parse(n pd2.Node) error { +func (x *AnonInductive4) Parse(n pd1.Node) error { *x = AnonInductive4{} - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() kn, vn, err := iter.Next() @@ -634,7 +634,7 @@ func (x *AnonInductive4) Parse(n pd2.Node) error { } k, err := kn.AsString() if err != nil { - return pd3.Errorf("inductive map key is not a string") + return pd2.Errorf("inductive map key is not a string") } switch k { case "IdentifyRequest": @@ -654,7 +654,7 @@ func (x *AnonInductive4) Parse(n pd2.Node) error { } - return pd3.Errorf("inductive map has no applicable keys") + return pd2.Errorf("inductive map has no applicable keys") } @@ -663,19 +663,19 @@ type AnonInductive4_MapIterator struct { s *AnonInductive4 } -func (x *AnonInductive4_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *AnonInductive4_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { if x.done { - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } else { x.done = true switch { case x.s.Identify != nil: - return pd1.String("IdentifyRequest"), x.s.Identify.Node(), nil + return pd3.String("IdentifyRequest"), x.s.Identify.Node(), nil case x.s.GetP2PProvide != nil: - return pd1.String("GetP2PProvideRequest"), x.s.GetP2PProvide.Node(), nil + return pd3.String("GetP2PProvideRequest"), x.s.GetP2PProvide.Node(), nil default: - return nil, nil, pd3.Errorf("no inductive cases are set") + return nil, nil, pd2.Errorf("no inductive cases are set") } } } @@ -684,15 +684,15 @@ func (x *AnonInductive4_MapIterator) Done() bool { return x.done } -func (x AnonInductive4) Node() pd2.Node { +func (x AnonInductive4) Node() pd1.Node { return x } -func (x AnonInductive4) Kind() pd2.Kind { - return pd2.Kind_Map +func (x AnonInductive4) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x AnonInductive4) LookupByString(key string) (pd2.Node, error) { +func (x AnonInductive4) LookupByString(key string) (pd1.Node, error) { switch { case x.Identify != nil && key == "IdentifyRequest": return x.Identify.Node(), nil @@ -700,12 +700,12 @@ func (x AnonInductive4) LookupByString(key string) (pd2.Node, error) { return x.GetP2PProvide.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x AnonInductive4) LookupByNode(key pd2.Node) (pd2.Node, error) { - if key.Kind() != pd2.Kind_String { - return nil, pd1.ErrNA +func (x AnonInductive4) LookupByNode(key pd1.Node) (pd1.Node, error) { + if key.Kind() != pd1.Kind_String { + return nil, pd3.ErrNA } if s, err := key.AsString(); err != nil { return nil, err @@ -714,11 +714,11 @@ func (x AnonInductive4) LookupByNode(key pd2.Node) (pd2.Node, error) { } } -func (x AnonInductive4) LookupByIndex(idx int64) (pd2.Node, error) { - return nil, pd1.ErrNA +func (x AnonInductive4) LookupByIndex(idx int64) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (x AnonInductive4) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x AnonInductive4) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "IdentifyRequest": return x.Identify.Node(), nil @@ -726,14 +726,14 @@ func (x AnonInductive4) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.GetP2PProvide.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x AnonInductive4) MapIterator() pd2.MapIterator { +func (x AnonInductive4) MapIterator() pd1.MapIterator { return &AnonInductive4_MapIterator{false, &x} } -func (x AnonInductive4) ListIterator() pd2.ListIterator { +func (x AnonInductive4) ListIterator() pd1.ListIterator { return nil } @@ -750,30 +750,30 @@ func (x AnonInductive4) IsNull() bool { } func (x AnonInductive4) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x AnonInductive4) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x AnonInductive4) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x AnonInductive4) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x AnonInductive4) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x AnonInductive4) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x AnonInductive4) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x AnonInductive4) Prototype() pd2.NodePrototype { +func (x AnonInductive4) Prototype() pd1.NodePrototype { return nil } @@ -785,10 +785,10 @@ type AnonInductive5 struct { Error *DelegatedRouting_Error } -func (x *AnonInductive5) Parse(n pd2.Node) error { +func (x *AnonInductive5) Parse(n pd1.Node) error { *x = AnonInductive5{} - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() kn, vn, err := iter.Next() @@ -797,7 +797,7 @@ func (x *AnonInductive5) Parse(n pd2.Node) error { } k, err := kn.AsString() if err != nil { - return pd3.Errorf("inductive map key is not a string") + return pd2.Errorf("inductive map key is not a string") } switch k { case "IdentifyResponse": @@ -824,7 +824,7 @@ func (x *AnonInductive5) Parse(n pd2.Node) error { } - return pd3.Errorf("inductive map has no applicable keys") + return pd2.Errorf("inductive map has no applicable keys") } @@ -833,21 +833,21 @@ type AnonInductive5_MapIterator struct { s *AnonInductive5 } -func (x *AnonInductive5_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *AnonInductive5_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { if x.done { - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } else { x.done = true switch { case x.s.Identify != nil: - return pd1.String("IdentifyResponse"), x.s.Identify.Node(), nil + return pd3.String("IdentifyResponse"), x.s.Identify.Node(), nil case x.s.GetP2PProvide != nil: - return pd1.String("GetP2PProvideResponse"), x.s.GetP2PProvide.Node(), nil + return pd3.String("GetP2PProvideResponse"), x.s.GetP2PProvide.Node(), nil case x.s.Error != nil: - return pd1.String("Error"), x.s.Error.Node(), nil + return pd3.String("Error"), x.s.Error.Node(), nil default: - return nil, nil, pd3.Errorf("no inductive cases are set") + return nil, nil, pd2.Errorf("no inductive cases are set") } } } @@ -856,15 +856,15 @@ func (x *AnonInductive5_MapIterator) Done() bool { return x.done } -func (x AnonInductive5) Node() pd2.Node { +func (x AnonInductive5) Node() pd1.Node { return x } -func (x AnonInductive5) Kind() pd2.Kind { - return pd2.Kind_Map +func (x AnonInductive5) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x AnonInductive5) LookupByString(key string) (pd2.Node, error) { +func (x AnonInductive5) LookupByString(key string) (pd1.Node, error) { switch { case x.Identify != nil && key == "IdentifyResponse": return x.Identify.Node(), nil @@ -874,12 +874,12 @@ func (x AnonInductive5) LookupByString(key string) (pd2.Node, error) { return x.Error.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x AnonInductive5) LookupByNode(key pd2.Node) (pd2.Node, error) { - if key.Kind() != pd2.Kind_String { - return nil, pd1.ErrNA +func (x AnonInductive5) LookupByNode(key pd1.Node) (pd1.Node, error) { + if key.Kind() != pd1.Kind_String { + return nil, pd3.ErrNA } if s, err := key.AsString(); err != nil { return nil, err @@ -888,11 +888,11 @@ func (x AnonInductive5) LookupByNode(key pd2.Node) (pd2.Node, error) { } } -func (x AnonInductive5) LookupByIndex(idx int64) (pd2.Node, error) { - return nil, pd1.ErrNA +func (x AnonInductive5) LookupByIndex(idx int64) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (x AnonInductive5) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x AnonInductive5) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "IdentifyResponse": return x.Identify.Node(), nil @@ -902,14 +902,14 @@ func (x AnonInductive5) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.Error.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x AnonInductive5) MapIterator() pd2.MapIterator { +func (x AnonInductive5) MapIterator() pd1.MapIterator { return &AnonInductive5_MapIterator{false, &x} } -func (x AnonInductive5) ListIterator() pd2.ListIterator { +func (x AnonInductive5) ListIterator() pd1.ListIterator { return nil } @@ -926,43 +926,43 @@ func (x AnonInductive5) IsNull() bool { } func (x AnonInductive5) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x AnonInductive5) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x AnonInductive5) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x AnonInductive5) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x AnonInductive5) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x AnonInductive5) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x AnonInductive5) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x AnonInductive5) Prototype() pd2.NodePrototype { +func (x AnonInductive5) Prototype() pd1.NodePrototype { return nil } -var logger_client_DelegatedRouting = pd13.Logger("service/client/delegatedrouting") +var logger_client_DelegatedRouting = pd4.Logger("service/client/delegatedrouting") type DelegatedRouting_Client interface { - Identify(ctx pd8.Context, req *DelegatedRouting_IdentifyArg) ([]*DelegatedRouting_IdentifyResult, error) + Identify(ctx pd10.Context, req *DelegatedRouting_IdentifyArg) ([]*DelegatedRouting_IdentifyResult, error) - GetP2PProvide(ctx pd8.Context, req *GetP2PProvideRequest) ([]*GetP2PProvideResponse, error) + GetP2PProvide(ctx pd10.Context, req *GetP2PProvideRequest) ([]*GetP2PProvideResponse, error) - Identify_Async(ctx pd8.Context, req *DelegatedRouting_IdentifyArg) (<-chan DelegatedRouting_Identify_AsyncResult, error) + Identify_Async(ctx pd10.Context, req *DelegatedRouting_IdentifyArg) (<-chan DelegatedRouting_Identify_AsyncResult, error) - GetP2PProvide_Async(ctx pd8.Context, req *GetP2PProvideRequest) (<-chan DelegatedRouting_GetP2PProvide_AsyncResult, error) + GetP2PProvide_Async(ctx pd10.Context, req *GetP2PProvideRequest) (<-chan DelegatedRouting_GetP2PProvide_AsyncResult, error) } type DelegatedRouting_Identify_AsyncResult struct { @@ -978,13 +978,13 @@ type DelegatedRouting_GetP2PProvide_AsyncResult struct { type DelegatedRouting_ClientOption func(*client_DelegatedRouting) error type client_DelegatedRouting struct { - httpClient *pd12.Client - endpoint *pd4.URL - ulk pd5.Mutex + httpClient *pd9.Client + endpoint *pd7.URL + ulk pd13.Mutex unsupported map[string]bool // cache of methods not supported by server } -func DelegatedRouting_Client_WithHTTPClient(hc *pd12.Client) DelegatedRouting_ClientOption { +func DelegatedRouting_Client_WithHTTPClient(hc *pd9.Client) DelegatedRouting_ClientOption { return func(c *client_DelegatedRouting) error { c.httpClient = hc return nil @@ -992,11 +992,11 @@ func DelegatedRouting_Client_WithHTTPClient(hc *pd12.Client) DelegatedRouting_Cl } func New_DelegatedRouting_Client(endpoint string, opts ...DelegatedRouting_ClientOption) (*client_DelegatedRouting, error) { - u, err := pd4.Parse(endpoint) + u, err := pd7.Parse(endpoint) if err != nil { return nil, err } - c := &client_DelegatedRouting{endpoint: u, httpClient: pd12.DefaultClient, unsupported: make(map[string]bool)} + c := &client_DelegatedRouting{endpoint: u, httpClient: pd9.DefaultClient, unsupported: make(map[string]bool)} for _, o := range opts { if err := o(c); err != nil { return nil, err @@ -1005,8 +1005,8 @@ func New_DelegatedRouting_Client(endpoint string, opts ...DelegatedRouting_Clien return c, nil } -func (c *client_DelegatedRouting) Identify(ctx pd8.Context, req *DelegatedRouting_IdentifyArg) ([]*DelegatedRouting_IdentifyResult, error) { - ctx, cancel := pd8.WithCancel(ctx) +func (c *client_DelegatedRouting) Identify(ctx pd10.Context, req *DelegatedRouting_IdentifyArg) ([]*DelegatedRouting_IdentifyResult, error) { + ctx, cancel := pd10.WithCancel(ctx) defer cancel() ch, err := c.Identify_Async(ctx, req) if err != nil { @@ -1034,7 +1034,7 @@ func (c *client_DelegatedRouting) Identify(ctx pd8.Context, req *DelegatedRoutin } } -func (c *client_DelegatedRouting) Identify_Async(ctx pd8.Context, req *DelegatedRouting_IdentifyArg) (<-chan DelegatedRouting_Identify_AsyncResult, error) { +func (c *client_DelegatedRouting) Identify_Async(ctx pd10.Context, req *DelegatedRouting_IdentifyArg) (<-chan DelegatedRouting_Identify_AsyncResult, error) { // check if we have memoized that this method is not supported by the server c.ulk.Lock() notSupported := c.unsupported["Identify"] @@ -1047,17 +1047,17 @@ func (c *client_DelegatedRouting) Identify_Async(ctx pd8.Context, req *Delegated Identify: req, } - buf, err := pd10.Encode(envelope, pd9.Encode) + buf, err := pd6.Encode(envelope, pd8.Encode) if err != nil { - return nil, pd3.Errorf("unexpected serialization error (%v)", err) + return nil, pd2.Errorf("unexpected serialization error (%v)", err) } // encode request in URL u := *c.endpoint - q := pd4.Values{} + q := pd7.Values{} q.Set("q", string(buf)) u.RawQuery = q.Encode() - httpReq, err := pd12.NewRequestWithContext(ctx, "POST", u.String(), pd7.NewReader(buf)) + httpReq, err := pd9.NewRequestWithContext(ctx, "POST", u.String(), pd11.NewReader(buf)) if err != nil { return nil, err } @@ -1069,7 +1069,7 @@ func (c *client_DelegatedRouting) Identify_Async(ctx pd8.Context, req *Delegated resp, err := c.httpClient.Do(httpReq) if err != nil { - return nil, pd3.Errorf("sending HTTP request (%v)", err) + return nil, pd2.Errorf("sending HTTP request (%v)", err) } // HTTP codes 400 and 404 correspond to unrecognized method or request schema @@ -1081,13 +1081,28 @@ func (c *client_DelegatedRouting) Identify_Async(ctx pd8.Context, req *Delegated c.ulk.Unlock() return nil, pd14.ErrSchema } + // HTTP codes other than 200 correspond to service implementation rejecting the call when it is received + // for reasons unrelated to protocol schema + if resp.StatusCode != 200 { + resp.Body.Close() + if resp.Header != nil { + if errValues, ok := resp.Header["Error"]; ok && len(errValues) == 1 { + err = pd14.ErrService{Cause: pd2.Errorf("%s", errValues[0])} + } else { + err = pd2.Errorf("service rejected the call, no cause provided") + } + } else { + err = pd2.Errorf("service rejected the call") + } + return nil, err + } ch := make(chan DelegatedRouting_Identify_AsyncResult, 1) go process_DelegatedRouting_Identify_AsyncResult(ctx, ch, resp.Body) return ch, nil } -func process_DelegatedRouting_Identify_AsyncResult(ctx pd8.Context, ch chan<- DelegatedRouting_Identify_AsyncResult, r pd6.Reader) { +func process_DelegatedRouting_Identify_AsyncResult(ctx pd10.Context, ch chan<- DelegatedRouting_Identify_AsyncResult, r pd5.Reader) { defer close(ch) for { if ctx.Err() != nil { @@ -1095,8 +1110,8 @@ func process_DelegatedRouting_Identify_AsyncResult(ctx pd8.Context, ch chan<- De return } - n, err := pd10.DecodeStreaming(r, pd9.Decode) - if pd11.Is(err, pd6.EOF) || pd11.Is(err, pd6.ErrUnexpectedEOF) { + n, err := pd6.DecodeStreaming(r, pd8.Decode) + if pd12.Is(err, pd5.EOF) || pd12.Is(err, pd5.ErrUnexpectedEOF) { return } if err != nil { @@ -1110,7 +1125,7 @@ func process_DelegatedRouting_Identify_AsyncResult(ctx pd8.Context, ch chan<- De } if env.Error != nil { - ch <- DelegatedRouting_Identify_AsyncResult{Err: pd14.ErrService{Cause: pd11.New(string(env.Error.Code))}} // service-level error + ch <- DelegatedRouting_Identify_AsyncResult{Err: pd14.ErrService{Cause: pd12.New(string(env.Error.Code))}} // service-level error return } if env.Identify == nil { @@ -1120,8 +1135,8 @@ func process_DelegatedRouting_Identify_AsyncResult(ctx pd8.Context, ch chan<- De } } -func (c *client_DelegatedRouting) GetP2PProvide(ctx pd8.Context, req *GetP2PProvideRequest) ([]*GetP2PProvideResponse, error) { - ctx, cancel := pd8.WithCancel(ctx) +func (c *client_DelegatedRouting) GetP2PProvide(ctx pd10.Context, req *GetP2PProvideRequest) ([]*GetP2PProvideResponse, error) { + ctx, cancel := pd10.WithCancel(ctx) defer cancel() ch, err := c.GetP2PProvide_Async(ctx, req) if err != nil { @@ -1149,7 +1164,7 @@ func (c *client_DelegatedRouting) GetP2PProvide(ctx pd8.Context, req *GetP2PProv } } -func (c *client_DelegatedRouting) GetP2PProvide_Async(ctx pd8.Context, req *GetP2PProvideRequest) (<-chan DelegatedRouting_GetP2PProvide_AsyncResult, error) { +func (c *client_DelegatedRouting) GetP2PProvide_Async(ctx pd10.Context, req *GetP2PProvideRequest) (<-chan DelegatedRouting_GetP2PProvide_AsyncResult, error) { // check if we have memoized that this method is not supported by the server c.ulk.Lock() notSupported := c.unsupported["GetP2PProvide"] @@ -1162,17 +1177,17 @@ func (c *client_DelegatedRouting) GetP2PProvide_Async(ctx pd8.Context, req *GetP GetP2PProvide: req, } - buf, err := pd10.Encode(envelope, pd9.Encode) + buf, err := pd6.Encode(envelope, pd8.Encode) if err != nil { - return nil, pd3.Errorf("unexpected serialization error (%v)", err) + return nil, pd2.Errorf("unexpected serialization error (%v)", err) } // encode request in URL u := *c.endpoint - q := pd4.Values{} + q := pd7.Values{} q.Set("q", string(buf)) u.RawQuery = q.Encode() - httpReq, err := pd12.NewRequestWithContext(ctx, "POST", u.String(), pd7.NewReader(buf)) + httpReq, err := pd9.NewRequestWithContext(ctx, "POST", u.String(), pd11.NewReader(buf)) if err != nil { return nil, err } @@ -1184,7 +1199,7 @@ func (c *client_DelegatedRouting) GetP2PProvide_Async(ctx pd8.Context, req *GetP resp, err := c.httpClient.Do(httpReq) if err != nil { - return nil, pd3.Errorf("sending HTTP request (%v)", err) + return nil, pd2.Errorf("sending HTTP request (%v)", err) } // HTTP codes 400 and 404 correspond to unrecognized method or request schema @@ -1196,13 +1211,28 @@ func (c *client_DelegatedRouting) GetP2PProvide_Async(ctx pd8.Context, req *GetP c.ulk.Unlock() return nil, pd14.ErrSchema } + // HTTP codes other than 200 correspond to service implementation rejecting the call when it is received + // for reasons unrelated to protocol schema + if resp.StatusCode != 200 { + resp.Body.Close() + if resp.Header != nil { + if errValues, ok := resp.Header["Error"]; ok && len(errValues) == 1 { + err = pd14.ErrService{Cause: pd2.Errorf("%s", errValues[0])} + } else { + err = pd2.Errorf("service rejected the call, no cause provided") + } + } else { + err = pd2.Errorf("service rejected the call") + } + return nil, err + } ch := make(chan DelegatedRouting_GetP2PProvide_AsyncResult, 1) go process_DelegatedRouting_GetP2PProvide_AsyncResult(ctx, ch, resp.Body) return ch, nil } -func process_DelegatedRouting_GetP2PProvide_AsyncResult(ctx pd8.Context, ch chan<- DelegatedRouting_GetP2PProvide_AsyncResult, r pd6.Reader) { +func process_DelegatedRouting_GetP2PProvide_AsyncResult(ctx pd10.Context, ch chan<- DelegatedRouting_GetP2PProvide_AsyncResult, r pd5.Reader) { defer close(ch) for { if ctx.Err() != nil { @@ -1210,8 +1240,8 @@ func process_DelegatedRouting_GetP2PProvide_AsyncResult(ctx pd8.Context, ch chan return } - n, err := pd10.DecodeStreaming(r, pd9.Decode) - if pd11.Is(err, pd6.EOF) || pd11.Is(err, pd6.ErrUnexpectedEOF) { + n, err := pd6.DecodeStreaming(r, pd8.Decode) + if pd12.Is(err, pd5.EOF) || pd12.Is(err, pd5.ErrUnexpectedEOF) { return } if err != nil { @@ -1225,7 +1255,7 @@ func process_DelegatedRouting_GetP2PProvide_AsyncResult(ctx pd8.Context, ch chan } if env.Error != nil { - ch <- DelegatedRouting_GetP2PProvide_AsyncResult{Err: pd14.ErrService{Cause: pd11.New(string(env.Error.Code))}} // service-level error + ch <- DelegatedRouting_GetP2PProvide_AsyncResult{Err: pd14.ErrService{Cause: pd12.New(string(env.Error.Code))}} // service-level error return } if env.GetP2PProvide == nil { @@ -1235,17 +1265,17 @@ func process_DelegatedRouting_GetP2PProvide_AsyncResult(ctx pd8.Context, ch chan } } -var logger_server_DelegatedRouting = pd13.Logger("service/server/delegatedrouting") +var logger_server_DelegatedRouting = pd4.Logger("service/server/delegatedrouting") type DelegatedRouting_Server interface { - GetP2PProvide(ctx pd8.Context, req *GetP2PProvideRequest) (<-chan *DelegatedRouting_GetP2PProvide_AsyncResult, error) + GetP2PProvide(ctx pd10.Context, req *GetP2PProvideRequest) (<-chan *DelegatedRouting_GetP2PProvide_AsyncResult, error) } -func DelegatedRouting_AsyncHandler(s DelegatedRouting_Server) pd12.HandlerFunc { - return func(writer pd12.ResponseWriter, request *pd12.Request) { +func DelegatedRouting_AsyncHandler(s DelegatedRouting_Server) pd9.HandlerFunc { + return func(writer pd9.ResponseWriter, request *pd9.Request) { // parse request msg := request.URL.Query().Get("q") - n, err := pd10.Decode([]byte(msg), pd9.Decode) + n, err := pd6.Decode([]byte(msg), pd8.Decode) if err != nil { logger_server_DelegatedRouting.Errorf("received request not decodeable (%v)", err) writer.WriteHeader(400) @@ -1266,21 +1296,22 @@ func DelegatedRouting_AsyncHandler(s DelegatedRouting_Server) pd12.HandlerFunc { switch { case env.GetP2PProvide != nil: - ch, err := s.GetP2PProvide(pd8.Background(), env.GetP2PProvide) + ch, err := s.GetP2PProvide(pd10.Background(), env.GetP2PProvide) if err != nil { - logger_server_DelegatedRouting.Errorf("get p2p provider rejected request (%v)", err) + logger_server_DelegatedRouting.Errorf("service rejected request (%v)", err) + writer.Header()["Error"] = []string{err.Error()} writer.WriteHeader(500) return } for resp := range ch { var env *AnonInductive5 if resp.Err != nil { - env = &AnonInductive5{Error: &DelegatedRouting_Error{Code: pd1.String(resp.Err.Error())}} + env = &AnonInductive5{Error: &DelegatedRouting_Error{Code: pd3.String(resp.Err.Error())}} } else { env = &AnonInductive5{GetP2PProvide: resp.Resp} } - var buf pd7.Buffer - if err = pd10.EncodeStreaming(&buf, env, pd9.Encode); err != nil { + var buf pd11.Buffer + if err = pd6.EncodeStreaming(&buf, env, pd8.Encode); err != nil { logger_server_DelegatedRouting.Errorf("cannot encode response (%v)", err) continue } @@ -1292,13 +1323,13 @@ func DelegatedRouting_AsyncHandler(s DelegatedRouting_Server) pd12.HandlerFunc { var env *AnonInductive5 env = &AnonInductive5{ Identify: &DelegatedRouting_IdentifyResult{ - Methods: []pd1.String{ + Methods: []pd3.String{ "GetP2PProvide", }, }, } - var buf pd7.Buffer - if err = pd10.EncodeStreaming(&buf, env, pd9.Encode); err != nil { + var buf pd11.Buffer + if err = pd6.EncodeStreaming(&buf, env, pd8.Encode); err != nil { logger_server_DelegatedRouting.Errorf("cannot encode identify response (%v)", err) writer.WriteHeader(500) return @@ -1317,23 +1348,23 @@ func DelegatedRouting_AsyncHandler(s DelegatedRouting_Server) pd12.HandlerFunc { type AnonList7 []Multihash -func (v AnonList7) Node() pd2.Node { +func (v AnonList7) Node() pd1.Node { return v } -func (v *AnonList7) Parse(n pd2.Node) error { - if n.Kind() == pd2.Kind_Null { +func (v *AnonList7) Parse(n pd1.Node) error { + if n.Kind() == pd1.Kind_Null { *v = nil return nil } - if n.Kind() != pd2.Kind_List { - return pd1.ErrNA + if n.Kind() != pd1.Kind_List { + return pd3.ErrNA } else { *v = make(AnonList7, n.Length()) iter := n.ListIterator() for !iter.Done() { if i, n, err := iter.Next(); err != nil { - return pd1.ErrNA + return pd3.ErrNA } else if err = (*v)[i].Parse(n); err != nil { return err } @@ -1342,39 +1373,39 @@ func (v *AnonList7) Parse(n pd2.Node) error { } } -func (AnonList7) Kind() pd2.Kind { - return pd2.Kind_List +func (AnonList7) Kind() pd1.Kind { + return pd1.Kind_List } -func (AnonList7) LookupByString(string) (pd2.Node, error) { - return nil, pd1.ErrNA +func (AnonList7) LookupByString(string) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (AnonList7) LookupByNode(key pd2.Node) (pd2.Node, error) { - return nil, pd1.ErrNA +func (AnonList7) LookupByNode(key pd1.Node) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (v AnonList7) LookupByIndex(i int64) (pd2.Node, error) { +func (v AnonList7) LookupByIndex(i int64) (pd1.Node, error) { if i < 0 || i >= v.Length() { - return nil, pd1.ErrBounds + return nil, pd3.ErrBounds } else { return v[i].Node(), nil } } -func (v AnonList7) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (v AnonList7) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { if i, err := seg.Index(); err != nil { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } else { return v.LookupByIndex(i) } } -func (AnonList7) MapIterator() pd2.MapIterator { +func (AnonList7) MapIterator() pd1.MapIterator { return nil } -func (v AnonList7) ListIterator() pd2.ListIterator { +func (v AnonList7) ListIterator() pd1.ListIterator { return &AnonList7_ListIterator{v, 0} } @@ -1391,30 +1422,30 @@ func (AnonList7) IsNull() bool { } func (v AnonList7) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (AnonList7) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (AnonList7) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (AnonList7) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (AnonList7) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (AnonList7) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (AnonList7) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (AnonList7) Prototype() pd2.NodePrototype { +func (AnonList7) Prototype() pd1.NodePrototype { return nil // not needed } @@ -1423,9 +1454,9 @@ type AnonList7_ListIterator struct { at int64 } -func (iter *AnonList7_ListIterator) Next() (int64, pd2.Node, error) { +func (iter *AnonList7_ListIterator) Next() (int64, pd1.Node, error) { if iter.Done() { - return -1, nil, pd1.ErrBounds + return -1, nil, pd3.ErrBounds } v := iter.list[iter.at] i := int64(iter.at) @@ -1443,16 +1474,16 @@ type GetP2PProvideRequest struct { Keys AnonList7 } -func (x GetP2PProvideRequest) Node() pd2.Node { +func (x GetP2PProvideRequest) Node() pd1.Node { return x } -func (x *GetP2PProvideRequest) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA +func (x *GetP2PProvideRequest) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd1.ParseFunc{ + fieldMap := map[string]pd3.ParseFunc{ "Keys": x.Keys.Parse, } for !iter.Done() { @@ -1460,13 +1491,13 @@ func (x *GetP2PProvideRequest) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd3.Errorf("structure map key is not a string") + return pd2.Errorf("structure map key is not a string") } else { _ = vn switch k { case "Keys": if _, notParsed := fieldMap["Keys"]; !notParsed { - return pd3.Errorf("field %s already parsed", "Keys") + return pd2.Errorf("field %s already parsed", "Keys") } if err := x.Keys.Parse(vn); err != nil { return err @@ -1478,7 +1509,7 @@ func (x *GetP2PProvideRequest) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -1490,74 +1521,74 @@ type GetP2PProvideRequest_MapIterator struct { s *GetP2PProvideRequest } -func (x *GetP2PProvideRequest_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *GetP2PProvideRequest_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd1.String("Keys"), x.s.Keys.Node(), nil + return pd3.String("Keys"), x.s.Keys.Node(), nil } - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } func (x *GetP2PProvideRequest_MapIterator) Done() bool { return x.i+1 >= 1 } -func (x GetP2PProvideRequest) Kind() pd2.Kind { - return pd2.Kind_Map +func (x GetP2PProvideRequest) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x GetP2PProvideRequest) LookupByString(key string) (pd2.Node, error) { +func (x GetP2PProvideRequest) LookupByString(key string) (pd1.Node, error) { switch key { case "Keys": return x.Keys.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x GetP2PProvideRequest) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x GetP2PProvideRequest) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x GetP2PProvideRequest) LookupByIndex(idx int64) (pd2.Node, error) { +func (x GetP2PProvideRequest) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.Keys.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x GetP2PProvideRequest) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x GetP2PProvideRequest) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "Keys": return x.Keys.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x GetP2PProvideRequest) MapIterator() pd2.MapIterator { +func (x GetP2PProvideRequest) MapIterator() pd1.MapIterator { return &GetP2PProvideRequest_MapIterator{-1, &x} } -func (x GetP2PProvideRequest) ListIterator() pd2.ListIterator { +func (x GetP2PProvideRequest) ListIterator() pd1.ListIterator { return nil } @@ -1574,30 +1605,30 @@ func (x GetP2PProvideRequest) IsNull() bool { } func (x GetP2PProvideRequest) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x GetP2PProvideRequest) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x GetP2PProvideRequest) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x GetP2PProvideRequest) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x GetP2PProvideRequest) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x GetP2PProvideRequest) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x GetP2PProvideRequest) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x GetP2PProvideRequest) Prototype() pd2.NodePrototype { +func (x GetP2PProvideRequest) Prototype() pd1.NodePrototype { return nil } @@ -1605,23 +1636,23 @@ func (x GetP2PProvideRequest) Prototype() pd2.NodePrototype { type AnonList9 []ProvidersByKey -func (v AnonList9) Node() pd2.Node { +func (v AnonList9) Node() pd1.Node { return v } -func (v *AnonList9) Parse(n pd2.Node) error { - if n.Kind() == pd2.Kind_Null { +func (v *AnonList9) Parse(n pd1.Node) error { + if n.Kind() == pd1.Kind_Null { *v = nil return nil } - if n.Kind() != pd2.Kind_List { - return pd1.ErrNA + if n.Kind() != pd1.Kind_List { + return pd3.ErrNA } else { *v = make(AnonList9, n.Length()) iter := n.ListIterator() for !iter.Done() { if i, n, err := iter.Next(); err != nil { - return pd1.ErrNA + return pd3.ErrNA } else if err = (*v)[i].Parse(n); err != nil { return err } @@ -1630,39 +1661,39 @@ func (v *AnonList9) Parse(n pd2.Node) error { } } -func (AnonList9) Kind() pd2.Kind { - return pd2.Kind_List +func (AnonList9) Kind() pd1.Kind { + return pd1.Kind_List } -func (AnonList9) LookupByString(string) (pd2.Node, error) { - return nil, pd1.ErrNA +func (AnonList9) LookupByString(string) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (AnonList9) LookupByNode(key pd2.Node) (pd2.Node, error) { - return nil, pd1.ErrNA +func (AnonList9) LookupByNode(key pd1.Node) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (v AnonList9) LookupByIndex(i int64) (pd2.Node, error) { +func (v AnonList9) LookupByIndex(i int64) (pd1.Node, error) { if i < 0 || i >= v.Length() { - return nil, pd1.ErrBounds + return nil, pd3.ErrBounds } else { return v[i].Node(), nil } } -func (v AnonList9) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (v AnonList9) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { if i, err := seg.Index(); err != nil { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } else { return v.LookupByIndex(i) } } -func (AnonList9) MapIterator() pd2.MapIterator { +func (AnonList9) MapIterator() pd1.MapIterator { return nil } -func (v AnonList9) ListIterator() pd2.ListIterator { +func (v AnonList9) ListIterator() pd1.ListIterator { return &AnonList9_ListIterator{v, 0} } @@ -1679,30 +1710,30 @@ func (AnonList9) IsNull() bool { } func (v AnonList9) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (AnonList9) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (AnonList9) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (AnonList9) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (AnonList9) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (AnonList9) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (AnonList9) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (AnonList9) Prototype() pd2.NodePrototype { +func (AnonList9) Prototype() pd1.NodePrototype { return nil // not needed } @@ -1711,9 +1742,9 @@ type AnonList9_ListIterator struct { at int64 } -func (iter *AnonList9_ListIterator) Next() (int64, pd2.Node, error) { +func (iter *AnonList9_ListIterator) Next() (int64, pd1.Node, error) { if iter.Done() { - return -1, nil, pd1.ErrBounds + return -1, nil, pd3.ErrBounds } v := iter.list[iter.at] i := int64(iter.at) @@ -1731,16 +1762,16 @@ type GetP2PProvideResponse struct { ProvidersByKey AnonList9 } -func (x GetP2PProvideResponse) Node() pd2.Node { +func (x GetP2PProvideResponse) Node() pd1.Node { return x } -func (x *GetP2PProvideResponse) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA +func (x *GetP2PProvideResponse) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd1.ParseFunc{ + fieldMap := map[string]pd3.ParseFunc{ "ProvidersByKey": x.ProvidersByKey.Parse, } for !iter.Done() { @@ -1748,13 +1779,13 @@ func (x *GetP2PProvideResponse) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd3.Errorf("structure map key is not a string") + return pd2.Errorf("structure map key is not a string") } else { _ = vn switch k { case "ProvidersByKey": if _, notParsed := fieldMap["ProvidersByKey"]; !notParsed { - return pd3.Errorf("field %s already parsed", "ProvidersByKey") + return pd2.Errorf("field %s already parsed", "ProvidersByKey") } if err := x.ProvidersByKey.Parse(vn); err != nil { return err @@ -1766,7 +1797,7 @@ func (x *GetP2PProvideResponse) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -1778,74 +1809,74 @@ type GetP2PProvideResponse_MapIterator struct { s *GetP2PProvideResponse } -func (x *GetP2PProvideResponse_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *GetP2PProvideResponse_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd1.String("ProvidersByKey"), x.s.ProvidersByKey.Node(), nil + return pd3.String("ProvidersByKey"), x.s.ProvidersByKey.Node(), nil } - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } func (x *GetP2PProvideResponse_MapIterator) Done() bool { return x.i+1 >= 1 } -func (x GetP2PProvideResponse) Kind() pd2.Kind { - return pd2.Kind_Map +func (x GetP2PProvideResponse) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x GetP2PProvideResponse) LookupByString(key string) (pd2.Node, error) { +func (x GetP2PProvideResponse) LookupByString(key string) (pd1.Node, error) { switch key { case "ProvidersByKey": return x.ProvidersByKey.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x GetP2PProvideResponse) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x GetP2PProvideResponse) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x GetP2PProvideResponse) LookupByIndex(idx int64) (pd2.Node, error) { +func (x GetP2PProvideResponse) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.ProvidersByKey.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x GetP2PProvideResponse) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x GetP2PProvideResponse) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "ProvidersByKey": return x.ProvidersByKey.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x GetP2PProvideResponse) MapIterator() pd2.MapIterator { +func (x GetP2PProvideResponse) MapIterator() pd1.MapIterator { return &GetP2PProvideResponse_MapIterator{-1, &x} } -func (x GetP2PProvideResponse) ListIterator() pd2.ListIterator { +func (x GetP2PProvideResponse) ListIterator() pd1.ListIterator { return nil } @@ -1862,30 +1893,30 @@ func (x GetP2PProvideResponse) IsNull() bool { } func (x GetP2PProvideResponse) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x GetP2PProvideResponse) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x GetP2PProvideResponse) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x GetP2PProvideResponse) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x GetP2PProvideResponse) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x GetP2PProvideResponse) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x GetP2PProvideResponse) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x GetP2PProvideResponse) Prototype() pd2.NodePrototype { +func (x GetP2PProvideResponse) Prototype() pd1.NodePrototype { return nil } @@ -1896,16 +1927,16 @@ type ProvidersByKey struct { Provider Provider } -func (x ProvidersByKey) Node() pd2.Node { +func (x ProvidersByKey) Node() pd1.Node { return x } -func (x *ProvidersByKey) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA +func (x *ProvidersByKey) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd1.ParseFunc{ + fieldMap := map[string]pd3.ParseFunc{ "Key": x.Key.Parse, "Provider": x.Provider.Parse, } @@ -1914,13 +1945,13 @@ func (x *ProvidersByKey) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd3.Errorf("structure map key is not a string") + return pd2.Errorf("structure map key is not a string") } else { _ = vn switch k { case "Key": if _, notParsed := fieldMap["Key"]; !notParsed { - return pd3.Errorf("field %s already parsed", "Key") + return pd2.Errorf("field %s already parsed", "Key") } if err := x.Key.Parse(vn); err != nil { return err @@ -1928,7 +1959,7 @@ func (x *ProvidersByKey) Parse(n pd2.Node) error { delete(fieldMap, "Key") case "Provider": if _, notParsed := fieldMap["Provider"]; !notParsed { - return pd3.Errorf("field %s already parsed", "Provider") + return pd2.Errorf("field %s already parsed", "Provider") } if err := x.Provider.Parse(vn); err != nil { return err @@ -1940,7 +1971,7 @@ func (x *ProvidersByKey) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -1952,27 +1983,27 @@ type ProvidersByKey_MapIterator struct { s *ProvidersByKey } -func (x *ProvidersByKey_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *ProvidersByKey_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd1.String("Key"), x.s.Key.Node(), nil + return pd3.String("Key"), x.s.Key.Node(), nil case 1: - return pd1.String("Provider"), x.s.Provider.Node(), nil + return pd3.String("Provider"), x.s.Provider.Node(), nil } - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } func (x *ProvidersByKey_MapIterator) Done() bool { return x.i+1 >= 2 } -func (x ProvidersByKey) Kind() pd2.Kind { - return pd2.Kind_Map +func (x ProvidersByKey) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x ProvidersByKey) LookupByString(key string) (pd2.Node, error) { +func (x ProvidersByKey) LookupByString(key string) (pd1.Node, error) { switch key { case "Key": return x.Key.Node(), nil @@ -1980,28 +2011,28 @@ func (x ProvidersByKey) LookupByString(key string) (pd2.Node, error) { return x.Provider.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x ProvidersByKey) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x ProvidersByKey) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x ProvidersByKey) LookupByIndex(idx int64) (pd2.Node, error) { +func (x ProvidersByKey) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.Key.Node(), nil @@ -2009,10 +2040,10 @@ func (x ProvidersByKey) LookupByIndex(idx int64) (pd2.Node, error) { return x.Provider.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x ProvidersByKey) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x ProvidersByKey) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "Key": return x.Key.Node(), nil @@ -2020,14 +2051,14 @@ func (x ProvidersByKey) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.Provider.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x ProvidersByKey) MapIterator() pd2.MapIterator { +func (x ProvidersByKey) MapIterator() pd1.MapIterator { return &ProvidersByKey_MapIterator{-1, &x} } -func (x ProvidersByKey) ListIterator() pd2.ListIterator { +func (x ProvidersByKey) ListIterator() pd1.ListIterator { return nil } @@ -2044,49 +2075,49 @@ func (x ProvidersByKey) IsNull() bool { } func (x ProvidersByKey) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x ProvidersByKey) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x ProvidersByKey) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x ProvidersByKey) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x ProvidersByKey) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x ProvidersByKey) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x ProvidersByKey) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x ProvidersByKey) Prototype() pd2.NodePrototype { +func (x ProvidersByKey) Prototype() pd1.NodePrototype { return nil } // -- protocol type Multihash -- type Multihash struct { - Bytes pd1.Bytes + Bytes pd3.Bytes } -func (x Multihash) Node() pd2.Node { +func (x Multihash) Node() pd1.Node { return x } -func (x *Multihash) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA +func (x *Multihash) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd1.ParseFunc{ + fieldMap := map[string]pd3.ParseFunc{ "Bytes": x.Bytes.Parse, } for !iter.Done() { @@ -2094,13 +2125,13 @@ func (x *Multihash) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd3.Errorf("structure map key is not a string") + return pd2.Errorf("structure map key is not a string") } else { _ = vn switch k { case "Bytes": if _, notParsed := fieldMap["Bytes"]; !notParsed { - return pd3.Errorf("field %s already parsed", "Bytes") + return pd2.Errorf("field %s already parsed", "Bytes") } if err := x.Bytes.Parse(vn); err != nil { return err @@ -2112,7 +2143,7 @@ func (x *Multihash) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -2124,74 +2155,74 @@ type Multihash_MapIterator struct { s *Multihash } -func (x *Multihash_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *Multihash_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd1.String("Bytes"), x.s.Bytes.Node(), nil + return pd3.String("Bytes"), x.s.Bytes.Node(), nil } - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } func (x *Multihash_MapIterator) Done() bool { return x.i+1 >= 1 } -func (x Multihash) Kind() pd2.Kind { - return pd2.Kind_Map +func (x Multihash) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x Multihash) LookupByString(key string) (pd2.Node, error) { +func (x Multihash) LookupByString(key string) (pd1.Node, error) { switch key { case "Bytes": return x.Bytes.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Multihash) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x Multihash) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Multihash) LookupByIndex(idx int64) (pd2.Node, error) { +func (x Multihash) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.Bytes.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Multihash) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x Multihash) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "Bytes": return x.Bytes.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Multihash) MapIterator() pd2.MapIterator { +func (x Multihash) MapIterator() pd1.MapIterator { return &Multihash_MapIterator{-1, &x} } -func (x Multihash) ListIterator() pd2.ListIterator { +func (x Multihash) ListIterator() pd1.ListIterator { return nil } @@ -2208,30 +2239,30 @@ func (x Multihash) IsNull() bool { } func (x Multihash) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x Multihash) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x Multihash) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x Multihash) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x Multihash) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Multihash) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x Multihash) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x Multihash) Prototype() pd2.NodePrototype { +func (x Multihash) Prototype() pd1.NodePrototype { return nil } @@ -2239,23 +2270,23 @@ func (x Multihash) Prototype() pd2.NodePrototype { type AnonList13 []Node -func (v AnonList13) Node() pd2.Node { +func (v AnonList13) Node() pd1.Node { return v } -func (v *AnonList13) Parse(n pd2.Node) error { - if n.Kind() == pd2.Kind_Null { +func (v *AnonList13) Parse(n pd1.Node) error { + if n.Kind() == pd1.Kind_Null { *v = nil return nil } - if n.Kind() != pd2.Kind_List { - return pd1.ErrNA + if n.Kind() != pd1.Kind_List { + return pd3.ErrNA } else { *v = make(AnonList13, n.Length()) iter := n.ListIterator() for !iter.Done() { if i, n, err := iter.Next(); err != nil { - return pd1.ErrNA + return pd3.ErrNA } else if err = (*v)[i].Parse(n); err != nil { return err } @@ -2264,39 +2295,39 @@ func (v *AnonList13) Parse(n pd2.Node) error { } } -func (AnonList13) Kind() pd2.Kind { - return pd2.Kind_List +func (AnonList13) Kind() pd1.Kind { + return pd1.Kind_List } -func (AnonList13) LookupByString(string) (pd2.Node, error) { - return nil, pd1.ErrNA +func (AnonList13) LookupByString(string) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (AnonList13) LookupByNode(key pd2.Node) (pd2.Node, error) { - return nil, pd1.ErrNA +func (AnonList13) LookupByNode(key pd1.Node) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (v AnonList13) LookupByIndex(i int64) (pd2.Node, error) { +func (v AnonList13) LookupByIndex(i int64) (pd1.Node, error) { if i < 0 || i >= v.Length() { - return nil, pd1.ErrBounds + return nil, pd3.ErrBounds } else { return v[i].Node(), nil } } -func (v AnonList13) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (v AnonList13) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { if i, err := seg.Index(); err != nil { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } else { return v.LookupByIndex(i) } } -func (AnonList13) MapIterator() pd2.MapIterator { +func (AnonList13) MapIterator() pd1.MapIterator { return nil } -func (v AnonList13) ListIterator() pd2.ListIterator { +func (v AnonList13) ListIterator() pd1.ListIterator { return &AnonList13_ListIterator{v, 0} } @@ -2313,30 +2344,30 @@ func (AnonList13) IsNull() bool { } func (v AnonList13) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (AnonList13) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (AnonList13) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (AnonList13) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (AnonList13) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (AnonList13) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (AnonList13) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (AnonList13) Prototype() pd2.NodePrototype { +func (AnonList13) Prototype() pd1.NodePrototype { return nil // not needed } @@ -2345,9 +2376,9 @@ type AnonList13_ListIterator struct { at int64 } -func (iter *AnonList13_ListIterator) Next() (int64, pd2.Node, error) { +func (iter *AnonList13_ListIterator) Next() (int64, pd1.Node, error) { if iter.Done() { - return -1, nil, pd1.ErrBounds + return -1, nil, pd3.ErrBounds } v := iter.list[iter.at] i := int64(iter.at) @@ -2363,23 +2394,23 @@ func (iter *AnonList13_ListIterator) Done() bool { type AnonList14 []TransferProto -func (v AnonList14) Node() pd2.Node { +func (v AnonList14) Node() pd1.Node { return v } -func (v *AnonList14) Parse(n pd2.Node) error { - if n.Kind() == pd2.Kind_Null { +func (v *AnonList14) Parse(n pd1.Node) error { + if n.Kind() == pd1.Kind_Null { *v = nil return nil } - if n.Kind() != pd2.Kind_List { - return pd1.ErrNA + if n.Kind() != pd1.Kind_List { + return pd3.ErrNA } else { *v = make(AnonList14, n.Length()) iter := n.ListIterator() for !iter.Done() { if i, n, err := iter.Next(); err != nil { - return pd1.ErrNA + return pd3.ErrNA } else if err = (*v)[i].Parse(n); err != nil { return err } @@ -2388,39 +2419,39 @@ func (v *AnonList14) Parse(n pd2.Node) error { } } -func (AnonList14) Kind() pd2.Kind { - return pd2.Kind_List +func (AnonList14) Kind() pd1.Kind { + return pd1.Kind_List } -func (AnonList14) LookupByString(string) (pd2.Node, error) { - return nil, pd1.ErrNA +func (AnonList14) LookupByString(string) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (AnonList14) LookupByNode(key pd2.Node) (pd2.Node, error) { - return nil, pd1.ErrNA +func (AnonList14) LookupByNode(key pd1.Node) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (v AnonList14) LookupByIndex(i int64) (pd2.Node, error) { +func (v AnonList14) LookupByIndex(i int64) (pd1.Node, error) { if i < 0 || i >= v.Length() { - return nil, pd1.ErrBounds + return nil, pd3.ErrBounds } else { return v[i].Node(), nil } } -func (v AnonList14) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (v AnonList14) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { if i, err := seg.Index(); err != nil { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } else { return v.LookupByIndex(i) } } -func (AnonList14) MapIterator() pd2.MapIterator { +func (AnonList14) MapIterator() pd1.MapIterator { return nil } -func (v AnonList14) ListIterator() pd2.ListIterator { +func (v AnonList14) ListIterator() pd1.ListIterator { return &AnonList14_ListIterator{v, 0} } @@ -2437,30 +2468,30 @@ func (AnonList14) IsNull() bool { } func (v AnonList14) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (AnonList14) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (AnonList14) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (AnonList14) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (AnonList14) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (AnonList14) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (AnonList14) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (AnonList14) Prototype() pd2.NodePrototype { +func (AnonList14) Prototype() pd1.NodePrototype { return nil // not needed } @@ -2469,9 +2500,9 @@ type AnonList14_ListIterator struct { at int64 } -func (iter *AnonList14_ListIterator) Next() (int64, pd2.Node, error) { +func (iter *AnonList14_ListIterator) Next() (int64, pd1.Node, error) { if iter.Done() { - return -1, nil, pd1.ErrBounds + return -1, nil, pd3.ErrBounds } v := iter.list[iter.at] i := int64(iter.at) @@ -2490,16 +2521,16 @@ type Provider struct { Proto AnonList14 } -func (x Provider) Node() pd2.Node { +func (x Provider) Node() pd1.Node { return x } -func (x *Provider) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA +func (x *Provider) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd1.ParseFunc{ + fieldMap := map[string]pd3.ParseFunc{ "Nodes": x.Nodes.Parse, "Proto": x.Proto.Parse, } @@ -2508,13 +2539,13 @@ func (x *Provider) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd3.Errorf("structure map key is not a string") + return pd2.Errorf("structure map key is not a string") } else { _ = vn switch k { case "Nodes": if _, notParsed := fieldMap["Nodes"]; !notParsed { - return pd3.Errorf("field %s already parsed", "Nodes") + return pd2.Errorf("field %s already parsed", "Nodes") } if err := x.Nodes.Parse(vn); err != nil { return err @@ -2522,7 +2553,7 @@ func (x *Provider) Parse(n pd2.Node) error { delete(fieldMap, "Nodes") case "Proto": if _, notParsed := fieldMap["Proto"]; !notParsed { - return pd3.Errorf("field %s already parsed", "Proto") + return pd2.Errorf("field %s already parsed", "Proto") } if err := x.Proto.Parse(vn); err != nil { return err @@ -2534,7 +2565,7 @@ func (x *Provider) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -2546,27 +2577,27 @@ type Provider_MapIterator struct { s *Provider } -func (x *Provider_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *Provider_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd1.String("Nodes"), x.s.Nodes.Node(), nil + return pd3.String("Nodes"), x.s.Nodes.Node(), nil case 1: - return pd1.String("Proto"), x.s.Proto.Node(), nil + return pd3.String("Proto"), x.s.Proto.Node(), nil } - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } func (x *Provider_MapIterator) Done() bool { return x.i+1 >= 2 } -func (x Provider) Kind() pd2.Kind { - return pd2.Kind_Map +func (x Provider) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x Provider) LookupByString(key string) (pd2.Node, error) { +func (x Provider) LookupByString(key string) (pd1.Node, error) { switch key { case "Nodes": return x.Nodes.Node(), nil @@ -2574,28 +2605,28 @@ func (x Provider) LookupByString(key string) (pd2.Node, error) { return x.Proto.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Provider) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x Provider) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Provider) LookupByIndex(idx int64) (pd2.Node, error) { +func (x Provider) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.Nodes.Node(), nil @@ -2603,10 +2634,10 @@ func (x Provider) LookupByIndex(idx int64) (pd2.Node, error) { return x.Proto.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Provider) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x Provider) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "Nodes": return x.Nodes.Node(), nil @@ -2614,14 +2645,14 @@ func (x Provider) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.Proto.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Provider) MapIterator() pd2.MapIterator { +func (x Provider) MapIterator() pd1.MapIterator { return &Provider_MapIterator{-1, &x} } -func (x Provider) ListIterator() pd2.ListIterator { +func (x Provider) ListIterator() pd1.ListIterator { return nil } @@ -2638,30 +2669,30 @@ func (x Provider) IsNull() bool { } func (x Provider) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x Provider) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x Provider) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x Provider) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x Provider) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Provider) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x Provider) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x Provider) Prototype() pd2.NodePrototype { +func (x Provider) Prototype() pd1.NodePrototype { return nil } @@ -2671,10 +2702,10 @@ type Node struct { Peer *Peer } -func (x *Node) Parse(n pd2.Node) error { +func (x *Node) Parse(n pd1.Node) error { *x = Node{} - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() kn, vn, err := iter.Next() @@ -2683,7 +2714,7 @@ func (x *Node) Parse(n pd2.Node) error { } k, err := kn.AsString() if err != nil { - return pd3.Errorf("inductive map key is not a string") + return pd2.Errorf("inductive map key is not a string") } switch k { case "Peer": @@ -2696,7 +2727,7 @@ func (x *Node) Parse(n pd2.Node) error { } - return pd3.Errorf("inductive map has no applicable keys") + return pd2.Errorf("inductive map has no applicable keys") } @@ -2705,17 +2736,17 @@ type Node_MapIterator struct { s *Node } -func (x *Node_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *Node_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { if x.done { - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } else { x.done = true switch { case x.s.Peer != nil: - return pd1.String("Peer"), x.s.Peer.Node(), nil + return pd3.String("Peer"), x.s.Peer.Node(), nil default: - return nil, nil, pd3.Errorf("no inductive cases are set") + return nil, nil, pd2.Errorf("no inductive cases are set") } } } @@ -2724,26 +2755,26 @@ func (x *Node_MapIterator) Done() bool { return x.done } -func (x Node) Node() pd2.Node { +func (x Node) Node() pd1.Node { return x } -func (x Node) Kind() pd2.Kind { - return pd2.Kind_Map +func (x Node) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x Node) LookupByString(key string) (pd2.Node, error) { +func (x Node) LookupByString(key string) (pd1.Node, error) { switch { case x.Peer != nil && key == "Peer": return x.Peer.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Node) LookupByNode(key pd2.Node) (pd2.Node, error) { - if key.Kind() != pd2.Kind_String { - return nil, pd1.ErrNA +func (x Node) LookupByNode(key pd1.Node) (pd1.Node, error) { + if key.Kind() != pd1.Kind_String { + return nil, pd3.ErrNA } if s, err := key.AsString(); err != nil { return nil, err @@ -2752,24 +2783,24 @@ func (x Node) LookupByNode(key pd2.Node) (pd2.Node, error) { } } -func (x Node) LookupByIndex(idx int64) (pd2.Node, error) { - return nil, pd1.ErrNA +func (x Node) LookupByIndex(idx int64) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (x Node) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x Node) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "Peer": return x.Peer.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Node) MapIterator() pd2.MapIterator { +func (x Node) MapIterator() pd1.MapIterator { return &Node_MapIterator{false, &x} } -func (x Node) ListIterator() pd2.ListIterator { +func (x Node) ListIterator() pd1.ListIterator { return nil } @@ -2786,54 +2817,54 @@ func (x Node) IsNull() bool { } func (x Node) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x Node) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x Node) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x Node) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x Node) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Node) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x Node) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x Node) Prototype() pd2.NodePrototype { +func (x Node) Prototype() pd1.NodePrototype { return nil } // -- protocol type AnonList17 -- -type AnonList17 []pd1.Bytes +type AnonList17 []pd3.Bytes -func (v AnonList17) Node() pd2.Node { +func (v AnonList17) Node() pd1.Node { return v } -func (v *AnonList17) Parse(n pd2.Node) error { - if n.Kind() == pd2.Kind_Null { +func (v *AnonList17) Parse(n pd1.Node) error { + if n.Kind() == pd1.Kind_Null { *v = nil return nil } - if n.Kind() != pd2.Kind_List { - return pd1.ErrNA + if n.Kind() != pd1.Kind_List { + return pd3.ErrNA } else { *v = make(AnonList17, n.Length()) iter := n.ListIterator() for !iter.Done() { if i, n, err := iter.Next(); err != nil { - return pd1.ErrNA + return pd3.ErrNA } else if err = (*v)[i].Parse(n); err != nil { return err } @@ -2842,39 +2873,39 @@ func (v *AnonList17) Parse(n pd2.Node) error { } } -func (AnonList17) Kind() pd2.Kind { - return pd2.Kind_List +func (AnonList17) Kind() pd1.Kind { + return pd1.Kind_List } -func (AnonList17) LookupByString(string) (pd2.Node, error) { - return nil, pd1.ErrNA +func (AnonList17) LookupByString(string) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (AnonList17) LookupByNode(key pd2.Node) (pd2.Node, error) { - return nil, pd1.ErrNA +func (AnonList17) LookupByNode(key pd1.Node) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (v AnonList17) LookupByIndex(i int64) (pd2.Node, error) { +func (v AnonList17) LookupByIndex(i int64) (pd1.Node, error) { if i < 0 || i >= v.Length() { - return nil, pd1.ErrBounds + return nil, pd3.ErrBounds } else { return v[i].Node(), nil } } -func (v AnonList17) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (v AnonList17) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { if i, err := seg.Index(); err != nil { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } else { return v.LookupByIndex(i) } } -func (AnonList17) MapIterator() pd2.MapIterator { +func (AnonList17) MapIterator() pd1.MapIterator { return nil } -func (v AnonList17) ListIterator() pd2.ListIterator { +func (v AnonList17) ListIterator() pd1.ListIterator { return &AnonList17_ListIterator{v, 0} } @@ -2891,30 +2922,30 @@ func (AnonList17) IsNull() bool { } func (v AnonList17) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (AnonList17) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (AnonList17) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (AnonList17) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (AnonList17) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (AnonList17) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (AnonList17) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (AnonList17) Prototype() pd2.NodePrototype { +func (AnonList17) Prototype() pd1.NodePrototype { return nil // not needed } @@ -2923,9 +2954,9 @@ type AnonList17_ListIterator struct { at int64 } -func (iter *AnonList17_ListIterator) Next() (int64, pd2.Node, error) { +func (iter *AnonList17_ListIterator) Next() (int64, pd1.Node, error) { if iter.Done() { - return -1, nil, pd1.ErrBounds + return -1, nil, pd3.ErrBounds } v := iter.list[iter.at] i := int64(iter.at) @@ -2940,20 +2971,20 @@ func (iter *AnonList17_ListIterator) Done() bool { // -- protocol type Peer -- type Peer struct { - ID pd1.Bytes + ID pd3.Bytes Multiaddresses AnonList17 } -func (x Peer) Node() pd2.Node { +func (x Peer) Node() pd1.Node { return x } -func (x *Peer) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA +func (x *Peer) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd1.ParseFunc{ + fieldMap := map[string]pd3.ParseFunc{ "ID": x.ID.Parse, "Multiaddresses": x.Multiaddresses.Parse, } @@ -2962,13 +2993,13 @@ func (x *Peer) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd3.Errorf("structure map key is not a string") + return pd2.Errorf("structure map key is not a string") } else { _ = vn switch k { case "ID": if _, notParsed := fieldMap["ID"]; !notParsed { - return pd3.Errorf("field %s already parsed", "ID") + return pd2.Errorf("field %s already parsed", "ID") } if err := x.ID.Parse(vn); err != nil { return err @@ -2976,7 +3007,7 @@ func (x *Peer) Parse(n pd2.Node) error { delete(fieldMap, "ID") case "Multiaddresses": if _, notParsed := fieldMap["Multiaddresses"]; !notParsed { - return pd3.Errorf("field %s already parsed", "Multiaddresses") + return pd2.Errorf("field %s already parsed", "Multiaddresses") } if err := x.Multiaddresses.Parse(vn); err != nil { return err @@ -2988,7 +3019,7 @@ func (x *Peer) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -3000,27 +3031,27 @@ type Peer_MapIterator struct { s *Peer } -func (x *Peer_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *Peer_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd1.String("ID"), x.s.ID.Node(), nil + return pd3.String("ID"), x.s.ID.Node(), nil case 1: - return pd1.String("Multiaddresses"), x.s.Multiaddresses.Node(), nil + return pd3.String("Multiaddresses"), x.s.Multiaddresses.Node(), nil } - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } func (x *Peer_MapIterator) Done() bool { return x.i+1 >= 2 } -func (x Peer) Kind() pd2.Kind { - return pd2.Kind_Map +func (x Peer) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x Peer) LookupByString(key string) (pd2.Node, error) { +func (x Peer) LookupByString(key string) (pd1.Node, error) { switch key { case "ID": return x.ID.Node(), nil @@ -3028,28 +3059,28 @@ func (x Peer) LookupByString(key string) (pd2.Node, error) { return x.Multiaddresses.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Peer) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x Peer) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Peer) LookupByIndex(idx int64) (pd2.Node, error) { +func (x Peer) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.ID.Node(), nil @@ -3057,10 +3088,10 @@ func (x Peer) LookupByIndex(idx int64) (pd2.Node, error) { return x.Multiaddresses.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Peer) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x Peer) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "ID": return x.ID.Node(), nil @@ -3068,14 +3099,14 @@ func (x Peer) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.Multiaddresses.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Peer) MapIterator() pd2.MapIterator { +func (x Peer) MapIterator() pd1.MapIterator { return &Peer_MapIterator{-1, &x} } -func (x Peer) ListIterator() pd2.ListIterator { +func (x Peer) ListIterator() pd1.ListIterator { return nil } @@ -3092,30 +3123,30 @@ func (x Peer) IsNull() bool { } func (x Peer) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x Peer) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x Peer) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x Peer) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x Peer) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x Peer) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x Peer) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x Peer) Prototype() pd2.NodePrototype { +func (x Peer) Prototype() pd1.NodePrototype { return nil } @@ -3125,10 +3156,10 @@ type TransferProto struct { Bitswap *BitswapTransfer } -func (x *TransferProto) Parse(n pd2.Node) error { +func (x *TransferProto) Parse(n pd1.Node) error { *x = TransferProto{} - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() kn, vn, err := iter.Next() @@ -3137,7 +3168,7 @@ func (x *TransferProto) Parse(n pd2.Node) error { } k, err := kn.AsString() if err != nil { - return pd3.Errorf("inductive map key is not a string") + return pd2.Errorf("inductive map key is not a string") } switch k { case "Bitswap": @@ -3150,7 +3181,7 @@ func (x *TransferProto) Parse(n pd2.Node) error { } - return pd3.Errorf("inductive map has no applicable keys") + return pd2.Errorf("inductive map has no applicable keys") } @@ -3159,17 +3190,17 @@ type TransferProto_MapIterator struct { s *TransferProto } -func (x *TransferProto_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *TransferProto_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { if x.done { - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } else { x.done = true switch { case x.s.Bitswap != nil: - return pd1.String("Bitswap"), x.s.Bitswap.Node(), nil + return pd3.String("Bitswap"), x.s.Bitswap.Node(), nil default: - return nil, nil, pd3.Errorf("no inductive cases are set") + return nil, nil, pd2.Errorf("no inductive cases are set") } } } @@ -3178,26 +3209,26 @@ func (x *TransferProto_MapIterator) Done() bool { return x.done } -func (x TransferProto) Node() pd2.Node { +func (x TransferProto) Node() pd1.Node { return x } -func (x TransferProto) Kind() pd2.Kind { - return pd2.Kind_Map +func (x TransferProto) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x TransferProto) LookupByString(key string) (pd2.Node, error) { +func (x TransferProto) LookupByString(key string) (pd1.Node, error) { switch { case x.Bitswap != nil && key == "Bitswap": return x.Bitswap.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x TransferProto) LookupByNode(key pd2.Node) (pd2.Node, error) { - if key.Kind() != pd2.Kind_String { - return nil, pd1.ErrNA +func (x TransferProto) LookupByNode(key pd1.Node) (pd1.Node, error) { + if key.Kind() != pd1.Kind_String { + return nil, pd3.ErrNA } if s, err := key.AsString(); err != nil { return nil, err @@ -3206,24 +3237,24 @@ func (x TransferProto) LookupByNode(key pd2.Node) (pd2.Node, error) { } } -func (x TransferProto) LookupByIndex(idx int64) (pd2.Node, error) { - return nil, pd1.ErrNA +func (x TransferProto) LookupByIndex(idx int64) (pd1.Node, error) { + return nil, pd3.ErrNA } -func (x TransferProto) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x TransferProto) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "Bitswap": return x.Bitswap.Node(), nil } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x TransferProto) MapIterator() pd2.MapIterator { +func (x TransferProto) MapIterator() pd1.MapIterator { return &TransferProto_MapIterator{false, &x} } -func (x TransferProto) ListIterator() pd2.ListIterator { +func (x TransferProto) ListIterator() pd1.ListIterator { return nil } @@ -3240,30 +3271,30 @@ func (x TransferProto) IsNull() bool { } func (x TransferProto) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x TransferProto) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x TransferProto) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x TransferProto) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x TransferProto) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x TransferProto) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x TransferProto) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x TransferProto) Prototype() pd2.NodePrototype { +func (x TransferProto) Prototype() pd1.NodePrototype { return nil } @@ -3272,22 +3303,22 @@ func (x TransferProto) Prototype() pd2.NodePrototype { type BitswapTransfer struct { } -func (x BitswapTransfer) Node() pd2.Node { +func (x BitswapTransfer) Node() pd1.Node { return x } -func (x *BitswapTransfer) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd1.ErrNA +func (x *BitswapTransfer) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd3.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd1.ParseFunc{} + fieldMap := map[string]pd3.ParseFunc{} for !iter.Done() { if kn, vn, err := iter.Next(); err != nil { return err } else { if k, err := kn.AsString(); err != nil { - return pd3.Errorf("structure map key is not a string") + return pd2.Errorf("structure map key is not a string") } else { _ = vn switch k { @@ -3297,7 +3328,7 @@ func (x *BitswapTransfer) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -3309,66 +3340,66 @@ type BitswapTransfer_MapIterator struct { s *BitswapTransfer } -func (x *BitswapTransfer_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *BitswapTransfer_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { } - return nil, nil, pd1.ErrNA + return nil, nil, pd3.ErrNA } func (x *BitswapTransfer_MapIterator) Done() bool { return x.i+1 >= 0 } -func (x BitswapTransfer) Kind() pd2.Kind { - return pd2.Kind_Map +func (x BitswapTransfer) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x BitswapTransfer) LookupByString(key string) (pd2.Node, error) { +func (x BitswapTransfer) LookupByString(key string) (pd1.Node, error) { switch key { } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x BitswapTransfer) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x BitswapTransfer) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x BitswapTransfer) LookupByIndex(idx int64) (pd2.Node, error) { +func (x BitswapTransfer) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x BitswapTransfer) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x BitswapTransfer) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { } - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x BitswapTransfer) MapIterator() pd2.MapIterator { +func (x BitswapTransfer) MapIterator() pd1.MapIterator { return &BitswapTransfer_MapIterator{-1, &x} } -func (x BitswapTransfer) ListIterator() pd2.ListIterator { +func (x BitswapTransfer) ListIterator() pd1.ListIterator { return nil } @@ -3385,29 +3416,29 @@ func (x BitswapTransfer) IsNull() bool { } func (x BitswapTransfer) AsBool() (bool, error) { - return false, pd1.ErrNA + return false, pd3.ErrNA } func (x BitswapTransfer) AsInt() (int64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x BitswapTransfer) AsFloat() (float64, error) { - return 0, pd1.ErrNA + return 0, pd3.ErrNA } func (x BitswapTransfer) AsString() (string, error) { - return "", pd1.ErrNA + return "", pd3.ErrNA } func (x BitswapTransfer) AsBytes() ([]byte, error) { - return nil, pd1.ErrNA + return nil, pd3.ErrNA } -func (x BitswapTransfer) AsLink() (pd2.Link, error) { - return nil, pd1.ErrNA +func (x BitswapTransfer) AsLink() (pd1.Link, error) { + return nil, pd3.ErrNA } -func (x BitswapTransfer) Prototype() pd2.NodePrototype { +func (x BitswapTransfer) Prototype() pd1.NodePrototype { return nil } diff --git a/examples/greeting-service/api/api b/examples/greeting-service/api/api index 9886d6d..5d08c70 100755 Binary files a/examples/greeting-service/api/api and b/examples/greeting-service/api/api differ diff --git a/examples/greeting-service/api/proto/proto_edelweiss.go b/examples/greeting-service/api/proto/proto_edelweiss.go index 7bcc918..e862996 100644 --- a/examples/greeting-service/api/proto/proto_edelweiss.go +++ b/examples/greeting-service/api/proto/proto_edelweiss.go @@ -1,21 +1,21 @@ package proto import ( - pd8 "bytes" - pd10 "context" - pd12 "errors" - pd1 "fmt" - pd9 "io" + pd10 "bytes" + pd8 "context" + pd7 "errors" + pd3 "fmt" + pd4 "io" pd6 "net/http" - pd4 "net/url" - pd5 "sync" - - pd7 "github.com/ipfs/go-log" - pd14 "github.com/ipld/edelweiss/services" - pd3 "github.com/ipld/edelweiss/values" - pd11 "github.com/ipld/go-ipld-prime" - pd13 "github.com/ipld/go-ipld-prime/codec/dagjson" - pd2 "github.com/ipld/go-ipld-prime/datamodel" + pd11 "net/url" + pd12 "sync" + + pd14 "github.com/ipfs/go-log" + pd13 "github.com/ipld/edelweiss/services" + pd2 "github.com/ipld/edelweiss/values" + pd5 "github.com/ipld/go-ipld-prime" + pd9 "github.com/ipld/go-ipld-prime/codec/dagjson" + pd1 "github.com/ipld/go-ipld-prime/datamodel" ) // -- protocol type GreetingService_IdentifyArg -- @@ -23,22 +23,22 @@ import ( type GreetingService_IdentifyArg struct { } -func (x GreetingService_IdentifyArg) Node() pd2.Node { +func (x GreetingService_IdentifyArg) Node() pd1.Node { return x } -func (x *GreetingService_IdentifyArg) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd3.ErrNA +func (x *GreetingService_IdentifyArg) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd2.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd3.ParseFunc{} + fieldMap := map[string]pd2.ParseFunc{} for !iter.Done() { if kn, vn, err := iter.Next(); err != nil { return err } else { if k, err := kn.AsString(); err != nil { - return pd1.Errorf("structure map key is not a string") + return pd3.Errorf("structure map key is not a string") } else { _ = vn switch k { @@ -48,7 +48,7 @@ func (x *GreetingService_IdentifyArg) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -60,66 +60,66 @@ type GreetingService_IdentifyArg_MapIterator struct { s *GreetingService_IdentifyArg } -func (x *GreetingService_IdentifyArg_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *GreetingService_IdentifyArg_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { } - return nil, nil, pd3.ErrNA + return nil, nil, pd2.ErrNA } func (x *GreetingService_IdentifyArg_MapIterator) Done() bool { return x.i+1 >= 0 } -func (x GreetingService_IdentifyArg) Kind() pd2.Kind { - return pd2.Kind_Map +func (x GreetingService_IdentifyArg) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x GreetingService_IdentifyArg) LookupByString(key string) (pd2.Node, error) { +func (x GreetingService_IdentifyArg) LookupByString(key string) (pd1.Node, error) { switch key { } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_IdentifyArg) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x GreetingService_IdentifyArg) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_IdentifyArg) LookupByIndex(idx int64) (pd2.Node, error) { +func (x GreetingService_IdentifyArg) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_IdentifyArg) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x GreetingService_IdentifyArg) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_IdentifyArg) MapIterator() pd2.MapIterator { +func (x GreetingService_IdentifyArg) MapIterator() pd1.MapIterator { return &GreetingService_IdentifyArg_MapIterator{-1, &x} } -func (x GreetingService_IdentifyArg) ListIterator() pd2.ListIterator { +func (x GreetingService_IdentifyArg) ListIterator() pd1.ListIterator { return nil } @@ -136,54 +136,54 @@ func (x GreetingService_IdentifyArg) IsNull() bool { } func (x GreetingService_IdentifyArg) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (x GreetingService_IdentifyArg) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x GreetingService_IdentifyArg) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x GreetingService_IdentifyArg) AsString() (string, error) { - return "", pd3.ErrNA + return "", pd2.ErrNA } func (x GreetingService_IdentifyArg) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_IdentifyArg) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (x GreetingService_IdentifyArg) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (x GreetingService_IdentifyArg) Prototype() pd2.NodePrototype { +func (x GreetingService_IdentifyArg) Prototype() pd1.NodePrototype { return nil } // -- protocol type AnonList1 -- -type AnonList1 []pd3.String +type AnonList1 []pd2.String -func (v AnonList1) Node() pd2.Node { +func (v AnonList1) Node() pd1.Node { return v } -func (v *AnonList1) Parse(n pd2.Node) error { - if n.Kind() == pd2.Kind_Null { +func (v *AnonList1) Parse(n pd1.Node) error { + if n.Kind() == pd1.Kind_Null { *v = nil return nil } - if n.Kind() != pd2.Kind_List { - return pd3.ErrNA + if n.Kind() != pd1.Kind_List { + return pd2.ErrNA } else { *v = make(AnonList1, n.Length()) iter := n.ListIterator() for !iter.Done() { if i, n, err := iter.Next(); err != nil { - return pd3.ErrNA + return pd2.ErrNA } else if err = (*v)[i].Parse(n); err != nil { return err } @@ -192,39 +192,39 @@ func (v *AnonList1) Parse(n pd2.Node) error { } } -func (AnonList1) Kind() pd2.Kind { - return pd2.Kind_List +func (AnonList1) Kind() pd1.Kind { + return pd1.Kind_List } -func (AnonList1) LookupByString(string) (pd2.Node, error) { - return nil, pd3.ErrNA +func (AnonList1) LookupByString(string) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (AnonList1) LookupByNode(key pd2.Node) (pd2.Node, error) { - return nil, pd3.ErrNA +func (AnonList1) LookupByNode(key pd1.Node) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (v AnonList1) LookupByIndex(i int64) (pd2.Node, error) { +func (v AnonList1) LookupByIndex(i int64) (pd1.Node, error) { if i < 0 || i >= v.Length() { - return nil, pd3.ErrBounds + return nil, pd2.ErrBounds } else { return v[i].Node(), nil } } -func (v AnonList1) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (v AnonList1) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { if i, err := seg.Index(); err != nil { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } else { return v.LookupByIndex(i) } } -func (AnonList1) MapIterator() pd2.MapIterator { +func (AnonList1) MapIterator() pd1.MapIterator { return nil } -func (v AnonList1) ListIterator() pd2.ListIterator { +func (v AnonList1) ListIterator() pd1.ListIterator { return &AnonList1_ListIterator{v, 0} } @@ -241,30 +241,30 @@ func (AnonList1) IsNull() bool { } func (v AnonList1) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (AnonList1) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (AnonList1) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (AnonList1) AsString() (string, error) { - return "", pd3.ErrNA + return "", pd2.ErrNA } func (AnonList1) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (AnonList1) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (AnonList1) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (AnonList1) Prototype() pd2.NodePrototype { +func (AnonList1) Prototype() pd1.NodePrototype { return nil // not needed } @@ -273,9 +273,9 @@ type AnonList1_ListIterator struct { at int64 } -func (iter *AnonList1_ListIterator) Next() (int64, pd2.Node, error) { +func (iter *AnonList1_ListIterator) Next() (int64, pd1.Node, error) { if iter.Done() { - return -1, nil, pd3.ErrBounds + return -1, nil, pd2.ErrBounds } v := iter.list[iter.at] i := int64(iter.at) @@ -293,16 +293,16 @@ type GreetingService_IdentifyResult struct { Methods AnonList1 } -func (x GreetingService_IdentifyResult) Node() pd2.Node { +func (x GreetingService_IdentifyResult) Node() pd1.Node { return x } -func (x *GreetingService_IdentifyResult) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd3.ErrNA +func (x *GreetingService_IdentifyResult) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd2.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd3.ParseFunc{ + fieldMap := map[string]pd2.ParseFunc{ "Methods": x.Methods.Parse, } for !iter.Done() { @@ -310,13 +310,13 @@ func (x *GreetingService_IdentifyResult) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd1.Errorf("structure map key is not a string") + return pd3.Errorf("structure map key is not a string") } else { _ = vn switch k { case "Methods": if _, notParsed := fieldMap["Methods"]; !notParsed { - return pd1.Errorf("field %s already parsed", "Methods") + return pd3.Errorf("field %s already parsed", "Methods") } if err := x.Methods.Parse(vn); err != nil { return err @@ -328,7 +328,7 @@ func (x *GreetingService_IdentifyResult) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -340,74 +340,74 @@ type GreetingService_IdentifyResult_MapIterator struct { s *GreetingService_IdentifyResult } -func (x *GreetingService_IdentifyResult_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *GreetingService_IdentifyResult_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd3.String("Methods"), x.s.Methods.Node(), nil + return pd2.String("Methods"), x.s.Methods.Node(), nil } - return nil, nil, pd3.ErrNA + return nil, nil, pd2.ErrNA } func (x *GreetingService_IdentifyResult_MapIterator) Done() bool { return x.i+1 >= 1 } -func (x GreetingService_IdentifyResult) Kind() pd2.Kind { - return pd2.Kind_Map +func (x GreetingService_IdentifyResult) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x GreetingService_IdentifyResult) LookupByString(key string) (pd2.Node, error) { +func (x GreetingService_IdentifyResult) LookupByString(key string) (pd1.Node, error) { switch key { case "Methods": return x.Methods.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_IdentifyResult) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x GreetingService_IdentifyResult) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_IdentifyResult) LookupByIndex(idx int64) (pd2.Node, error) { +func (x GreetingService_IdentifyResult) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.Methods.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_IdentifyResult) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x GreetingService_IdentifyResult) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "Methods": return x.Methods.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_IdentifyResult) MapIterator() pd2.MapIterator { +func (x GreetingService_IdentifyResult) MapIterator() pd1.MapIterator { return &GreetingService_IdentifyResult_MapIterator{-1, &x} } -func (x GreetingService_IdentifyResult) ListIterator() pd2.ListIterator { +func (x GreetingService_IdentifyResult) ListIterator() pd1.ListIterator { return nil } @@ -424,49 +424,49 @@ func (x GreetingService_IdentifyResult) IsNull() bool { } func (x GreetingService_IdentifyResult) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (x GreetingService_IdentifyResult) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x GreetingService_IdentifyResult) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x GreetingService_IdentifyResult) AsString() (string, error) { - return "", pd3.ErrNA + return "", pd2.ErrNA } func (x GreetingService_IdentifyResult) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_IdentifyResult) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (x GreetingService_IdentifyResult) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (x GreetingService_IdentifyResult) Prototype() pd2.NodePrototype { +func (x GreetingService_IdentifyResult) Prototype() pd1.NodePrototype { return nil } // -- protocol type GreetingService_Error -- type GreetingService_Error struct { - Code pd3.String + Code pd2.String } -func (x GreetingService_Error) Node() pd2.Node { +func (x GreetingService_Error) Node() pd1.Node { return x } -func (x *GreetingService_Error) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd3.ErrNA +func (x *GreetingService_Error) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd2.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd3.ParseFunc{ + fieldMap := map[string]pd2.ParseFunc{ "Code": x.Code.Parse, } for !iter.Done() { @@ -474,13 +474,13 @@ func (x *GreetingService_Error) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd1.Errorf("structure map key is not a string") + return pd3.Errorf("structure map key is not a string") } else { _ = vn switch k { case "Code": if _, notParsed := fieldMap["Code"]; !notParsed { - return pd1.Errorf("field %s already parsed", "Code") + return pd3.Errorf("field %s already parsed", "Code") } if err := x.Code.Parse(vn); err != nil { return err @@ -492,7 +492,7 @@ func (x *GreetingService_Error) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -504,74 +504,74 @@ type GreetingService_Error_MapIterator struct { s *GreetingService_Error } -func (x *GreetingService_Error_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *GreetingService_Error_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd3.String("Code"), x.s.Code.Node(), nil + return pd2.String("Code"), x.s.Code.Node(), nil } - return nil, nil, pd3.ErrNA + return nil, nil, pd2.ErrNA } func (x *GreetingService_Error_MapIterator) Done() bool { return x.i+1 >= 1 } -func (x GreetingService_Error) Kind() pd2.Kind { - return pd2.Kind_Map +func (x GreetingService_Error) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x GreetingService_Error) LookupByString(key string) (pd2.Node, error) { +func (x GreetingService_Error) LookupByString(key string) (pd1.Node, error) { switch key { case "Code": return x.Code.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_Error) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x GreetingService_Error) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_Error) LookupByIndex(idx int64) (pd2.Node, error) { +func (x GreetingService_Error) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.Code.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_Error) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x GreetingService_Error) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "Code": return x.Code.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_Error) MapIterator() pd2.MapIterator { +func (x GreetingService_Error) MapIterator() pd1.MapIterator { return &GreetingService_Error_MapIterator{-1, &x} } -func (x GreetingService_Error) ListIterator() pd2.ListIterator { +func (x GreetingService_Error) ListIterator() pd1.ListIterator { return nil } @@ -588,30 +588,30 @@ func (x GreetingService_Error) IsNull() bool { } func (x GreetingService_Error) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (x GreetingService_Error) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x GreetingService_Error) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x GreetingService_Error) AsString() (string, error) { - return "", pd3.ErrNA + return "", pd2.ErrNA } func (x GreetingService_Error) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x GreetingService_Error) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (x GreetingService_Error) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (x GreetingService_Error) Prototype() pd2.NodePrototype { +func (x GreetingService_Error) Prototype() pd1.NodePrototype { return nil } @@ -622,10 +622,10 @@ type AnonInductive4 struct { Hello *HelloRequest } -func (x *AnonInductive4) Parse(n pd2.Node) error { +func (x *AnonInductive4) Parse(n pd1.Node) error { *x = AnonInductive4{} - if n.Kind() != pd2.Kind_Map { - return pd3.ErrNA + if n.Kind() != pd1.Kind_Map { + return pd2.ErrNA } iter := n.MapIterator() kn, vn, err := iter.Next() @@ -634,7 +634,7 @@ func (x *AnonInductive4) Parse(n pd2.Node) error { } k, err := kn.AsString() if err != nil { - return pd1.Errorf("inductive map key is not a string") + return pd3.Errorf("inductive map key is not a string") } switch k { case "IdentifyRequest": @@ -654,7 +654,7 @@ func (x *AnonInductive4) Parse(n pd2.Node) error { } - return pd1.Errorf("inductive map has no applicable keys") + return pd3.Errorf("inductive map has no applicable keys") } @@ -663,19 +663,19 @@ type AnonInductive4_MapIterator struct { s *AnonInductive4 } -func (x *AnonInductive4_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *AnonInductive4_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { if x.done { - return nil, nil, pd3.ErrNA + return nil, nil, pd2.ErrNA } else { x.done = true switch { case x.s.Identify != nil: - return pd3.String("IdentifyRequest"), x.s.Identify.Node(), nil + return pd2.String("IdentifyRequest"), x.s.Identify.Node(), nil case x.s.Hello != nil: - return pd3.String("HelloRequest"), x.s.Hello.Node(), nil + return pd2.String("HelloRequest"), x.s.Hello.Node(), nil default: - return nil, nil, pd1.Errorf("no inductive cases are set") + return nil, nil, pd3.Errorf("no inductive cases are set") } } } @@ -684,15 +684,15 @@ func (x *AnonInductive4_MapIterator) Done() bool { return x.done } -func (x AnonInductive4) Node() pd2.Node { +func (x AnonInductive4) Node() pd1.Node { return x } -func (x AnonInductive4) Kind() pd2.Kind { - return pd2.Kind_Map +func (x AnonInductive4) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x AnonInductive4) LookupByString(key string) (pd2.Node, error) { +func (x AnonInductive4) LookupByString(key string) (pd1.Node, error) { switch { case x.Identify != nil && key == "IdentifyRequest": return x.Identify.Node(), nil @@ -700,12 +700,12 @@ func (x AnonInductive4) LookupByString(key string) (pd2.Node, error) { return x.Hello.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x AnonInductive4) LookupByNode(key pd2.Node) (pd2.Node, error) { - if key.Kind() != pd2.Kind_String { - return nil, pd3.ErrNA +func (x AnonInductive4) LookupByNode(key pd1.Node) (pd1.Node, error) { + if key.Kind() != pd1.Kind_String { + return nil, pd2.ErrNA } if s, err := key.AsString(); err != nil { return nil, err @@ -714,11 +714,11 @@ func (x AnonInductive4) LookupByNode(key pd2.Node) (pd2.Node, error) { } } -func (x AnonInductive4) LookupByIndex(idx int64) (pd2.Node, error) { - return nil, pd3.ErrNA +func (x AnonInductive4) LookupByIndex(idx int64) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (x AnonInductive4) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x AnonInductive4) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "IdentifyRequest": return x.Identify.Node(), nil @@ -726,14 +726,14 @@ func (x AnonInductive4) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.Hello.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x AnonInductive4) MapIterator() pd2.MapIterator { +func (x AnonInductive4) MapIterator() pd1.MapIterator { return &AnonInductive4_MapIterator{false, &x} } -func (x AnonInductive4) ListIterator() pd2.ListIterator { +func (x AnonInductive4) ListIterator() pd1.ListIterator { return nil } @@ -750,30 +750,30 @@ func (x AnonInductive4) IsNull() bool { } func (x AnonInductive4) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (x AnonInductive4) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x AnonInductive4) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x AnonInductive4) AsString() (string, error) { - return "", pd3.ErrNA + return "", pd2.ErrNA } func (x AnonInductive4) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x AnonInductive4) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (x AnonInductive4) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (x AnonInductive4) Prototype() pd2.NodePrototype { +func (x AnonInductive4) Prototype() pd1.NodePrototype { return nil } @@ -785,10 +785,10 @@ type AnonInductive5 struct { Error *GreetingService_Error } -func (x *AnonInductive5) Parse(n pd2.Node) error { +func (x *AnonInductive5) Parse(n pd1.Node) error { *x = AnonInductive5{} - if n.Kind() != pd2.Kind_Map { - return pd3.ErrNA + if n.Kind() != pd1.Kind_Map { + return pd2.ErrNA } iter := n.MapIterator() kn, vn, err := iter.Next() @@ -797,7 +797,7 @@ func (x *AnonInductive5) Parse(n pd2.Node) error { } k, err := kn.AsString() if err != nil { - return pd1.Errorf("inductive map key is not a string") + return pd3.Errorf("inductive map key is not a string") } switch k { case "IdentifyResponse": @@ -824,7 +824,7 @@ func (x *AnonInductive5) Parse(n pd2.Node) error { } - return pd1.Errorf("inductive map has no applicable keys") + return pd3.Errorf("inductive map has no applicable keys") } @@ -833,21 +833,21 @@ type AnonInductive5_MapIterator struct { s *AnonInductive5 } -func (x *AnonInductive5_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *AnonInductive5_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { if x.done { - return nil, nil, pd3.ErrNA + return nil, nil, pd2.ErrNA } else { x.done = true switch { case x.s.Identify != nil: - return pd3.String("IdentifyResponse"), x.s.Identify.Node(), nil + return pd2.String("IdentifyResponse"), x.s.Identify.Node(), nil case x.s.Hello != nil: - return pd3.String("HelloResponse"), x.s.Hello.Node(), nil + return pd2.String("HelloResponse"), x.s.Hello.Node(), nil case x.s.Error != nil: - return pd3.String("Error"), x.s.Error.Node(), nil + return pd2.String("Error"), x.s.Error.Node(), nil default: - return nil, nil, pd1.Errorf("no inductive cases are set") + return nil, nil, pd3.Errorf("no inductive cases are set") } } } @@ -856,15 +856,15 @@ func (x *AnonInductive5_MapIterator) Done() bool { return x.done } -func (x AnonInductive5) Node() pd2.Node { +func (x AnonInductive5) Node() pd1.Node { return x } -func (x AnonInductive5) Kind() pd2.Kind { - return pd2.Kind_Map +func (x AnonInductive5) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x AnonInductive5) LookupByString(key string) (pd2.Node, error) { +func (x AnonInductive5) LookupByString(key string) (pd1.Node, error) { switch { case x.Identify != nil && key == "IdentifyResponse": return x.Identify.Node(), nil @@ -874,12 +874,12 @@ func (x AnonInductive5) LookupByString(key string) (pd2.Node, error) { return x.Error.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x AnonInductive5) LookupByNode(key pd2.Node) (pd2.Node, error) { - if key.Kind() != pd2.Kind_String { - return nil, pd3.ErrNA +func (x AnonInductive5) LookupByNode(key pd1.Node) (pd1.Node, error) { + if key.Kind() != pd1.Kind_String { + return nil, pd2.ErrNA } if s, err := key.AsString(); err != nil { return nil, err @@ -888,11 +888,11 @@ func (x AnonInductive5) LookupByNode(key pd2.Node) (pd2.Node, error) { } } -func (x AnonInductive5) LookupByIndex(idx int64) (pd2.Node, error) { - return nil, pd3.ErrNA +func (x AnonInductive5) LookupByIndex(idx int64) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (x AnonInductive5) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x AnonInductive5) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "IdentifyResponse": return x.Identify.Node(), nil @@ -902,14 +902,14 @@ func (x AnonInductive5) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.Error.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x AnonInductive5) MapIterator() pd2.MapIterator { +func (x AnonInductive5) MapIterator() pd1.MapIterator { return &AnonInductive5_MapIterator{false, &x} } -func (x AnonInductive5) ListIterator() pd2.ListIterator { +func (x AnonInductive5) ListIterator() pd1.ListIterator { return nil } @@ -926,43 +926,43 @@ func (x AnonInductive5) IsNull() bool { } func (x AnonInductive5) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (x AnonInductive5) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x AnonInductive5) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x AnonInductive5) AsString() (string, error) { - return "", pd3.ErrNA + return "", pd2.ErrNA } func (x AnonInductive5) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x AnonInductive5) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (x AnonInductive5) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (x AnonInductive5) Prototype() pd2.NodePrototype { +func (x AnonInductive5) Prototype() pd1.NodePrototype { return nil } -var logger_client_GreetingService = pd7.Logger("service/client/greetingservice") +var logger_client_GreetingService = pd14.Logger("service/client/greetingservice") type GreetingService_Client interface { - Identify(ctx pd10.Context, req *GreetingService_IdentifyArg) ([]*GreetingService_IdentifyResult, error) + Identify(ctx pd8.Context, req *GreetingService_IdentifyArg) ([]*GreetingService_IdentifyResult, error) - Hello(ctx pd10.Context, req *HelloRequest) ([]*HelloResponse, error) + Hello(ctx pd8.Context, req *HelloRequest) ([]*HelloResponse, error) - Identify_Async(ctx pd10.Context, req *GreetingService_IdentifyArg) (<-chan GreetingService_Identify_AsyncResult, error) + Identify_Async(ctx pd8.Context, req *GreetingService_IdentifyArg) (<-chan GreetingService_Identify_AsyncResult, error) - Hello_Async(ctx pd10.Context, req *HelloRequest) (<-chan GreetingService_Hello_AsyncResult, error) + Hello_Async(ctx pd8.Context, req *HelloRequest) (<-chan GreetingService_Hello_AsyncResult, error) } type GreetingService_Identify_AsyncResult struct { @@ -979,8 +979,8 @@ type GreetingService_ClientOption func(*client_GreetingService) error type client_GreetingService struct { httpClient *pd6.Client - endpoint *pd4.URL - ulk pd5.Mutex + endpoint *pd11.URL + ulk pd12.Mutex unsupported map[string]bool // cache of methods not supported by server } @@ -992,7 +992,7 @@ func GreetingService_Client_WithHTTPClient(hc *pd6.Client) GreetingService_Clien } func New_GreetingService_Client(endpoint string, opts ...GreetingService_ClientOption) (*client_GreetingService, error) { - u, err := pd4.Parse(endpoint) + u, err := pd11.Parse(endpoint) if err != nil { return nil, err } @@ -1005,8 +1005,8 @@ func New_GreetingService_Client(endpoint string, opts ...GreetingService_ClientO return c, nil } -func (c *client_GreetingService) Identify(ctx pd10.Context, req *GreetingService_IdentifyArg) ([]*GreetingService_IdentifyResult, error) { - ctx, cancel := pd10.WithCancel(ctx) +func (c *client_GreetingService) Identify(ctx pd8.Context, req *GreetingService_IdentifyArg) ([]*GreetingService_IdentifyResult, error) { + ctx, cancel := pd8.WithCancel(ctx) defer cancel() ch, err := c.Identify_Async(ctx, req) if err != nil { @@ -1034,30 +1034,30 @@ func (c *client_GreetingService) Identify(ctx pd10.Context, req *GreetingService } } -func (c *client_GreetingService) Identify_Async(ctx pd10.Context, req *GreetingService_IdentifyArg) (<-chan GreetingService_Identify_AsyncResult, error) { +func (c *client_GreetingService) Identify_Async(ctx pd8.Context, req *GreetingService_IdentifyArg) (<-chan GreetingService_Identify_AsyncResult, error) { // check if we have memoized that this method is not supported by the server c.ulk.Lock() notSupported := c.unsupported["Identify"] c.ulk.Unlock() if notSupported { - return nil, pd14.ErrSchema + return nil, pd13.ErrSchema } envelope := &AnonInductive4{ Identify: req, } - buf, err := pd11.Encode(envelope, pd13.Encode) + buf, err := pd5.Encode(envelope, pd9.Encode) if err != nil { - return nil, pd1.Errorf("unexpected serialization error (%v)", err) + return nil, pd3.Errorf("unexpected serialization error (%v)", err) } // encode request in URL u := *c.endpoint - q := pd4.Values{} + q := pd11.Values{} q.Set("q", string(buf)) u.RawQuery = q.Encode() - httpReq, err := pd6.NewRequestWithContext(ctx, "POST", u.String(), pd8.NewReader(buf)) + httpReq, err := pd6.NewRequestWithContext(ctx, "POST", u.String(), pd10.NewReader(buf)) if err != nil { return nil, err } @@ -1069,7 +1069,7 @@ func (c *client_GreetingService) Identify_Async(ctx pd10.Context, req *GreetingS resp, err := c.httpClient.Do(httpReq) if err != nil { - return nil, pd1.Errorf("sending HTTP request (%v)", err) + return nil, pd3.Errorf("sending HTTP request (%v)", err) } // HTTP codes 400 and 404 correspond to unrecognized method or request schema @@ -1079,7 +1079,22 @@ func (c *client_GreetingService) Identify_Async(ctx pd10.Context, req *GreetingS c.ulk.Lock() c.unsupported["Identify"] = true c.ulk.Unlock() - return nil, pd14.ErrSchema + return nil, pd13.ErrSchema + } + // HTTP codes other than 200 correspond to service implementation rejecting the call when it is received + // for reasons unrelated to protocol schema + if resp.StatusCode != 200 { + resp.Body.Close() + if resp.Header != nil { + if errValues, ok := resp.Header["Error"]; ok && len(errValues) == 1 { + err = pd13.ErrService{Cause: pd3.Errorf("%s", errValues[0])} + } else { + err = pd3.Errorf("service rejected the call, no cause provided") + } + } else { + err = pd3.Errorf("service rejected the call") + } + return nil, err } ch := make(chan GreetingService_Identify_AsyncResult, 1) @@ -1087,30 +1102,30 @@ func (c *client_GreetingService) Identify_Async(ctx pd10.Context, req *GreetingS return ch, nil } -func process_GreetingService_Identify_AsyncResult(ctx pd10.Context, ch chan<- GreetingService_Identify_AsyncResult, r pd9.Reader) { +func process_GreetingService_Identify_AsyncResult(ctx pd8.Context, ch chan<- GreetingService_Identify_AsyncResult, r pd4.Reader) { defer close(ch) for { if ctx.Err() != nil { - ch <- GreetingService_Identify_AsyncResult{Err: pd14.ErrContext{Cause: ctx.Err()}} // context cancelled + ch <- GreetingService_Identify_AsyncResult{Err: pd13.ErrContext{Cause: ctx.Err()}} // context cancelled return } - n, err := pd11.DecodeStreaming(r, pd13.Decode) - if pd12.Is(err, pd9.EOF) || pd12.Is(err, pd9.ErrUnexpectedEOF) { + n, err := pd5.DecodeStreaming(r, pd9.Decode) + if pd7.Is(err, pd4.EOF) || pd7.Is(err, pd4.ErrUnexpectedEOF) { return } if err != nil { - ch <- GreetingService_Identify_AsyncResult{Err: pd14.ErrProto{Cause: err}} // IPLD decode error + ch <- GreetingService_Identify_AsyncResult{Err: pd13.ErrProto{Cause: err}} // IPLD decode error return } env := &AnonInductive5{} if err = env.Parse(n); err != nil { - ch <- GreetingService_Identify_AsyncResult{Err: pd14.ErrProto{Cause: err}} // schema decode error + ch <- GreetingService_Identify_AsyncResult{Err: pd13.ErrProto{Cause: err}} // schema decode error return } if env.Error != nil { - ch <- GreetingService_Identify_AsyncResult{Err: pd14.ErrService{Cause: pd12.New(string(env.Error.Code))}} // service-level error + ch <- GreetingService_Identify_AsyncResult{Err: pd13.ErrService{Cause: pd7.New(string(env.Error.Code))}} // service-level error return } if env.Identify == nil { @@ -1120,8 +1135,8 @@ func process_GreetingService_Identify_AsyncResult(ctx pd10.Context, ch chan<- Gr } } -func (c *client_GreetingService) Hello(ctx pd10.Context, req *HelloRequest) ([]*HelloResponse, error) { - ctx, cancel := pd10.WithCancel(ctx) +func (c *client_GreetingService) Hello(ctx pd8.Context, req *HelloRequest) ([]*HelloResponse, error) { + ctx, cancel := pd8.WithCancel(ctx) defer cancel() ch, err := c.Hello_Async(ctx, req) if err != nil { @@ -1149,30 +1164,30 @@ func (c *client_GreetingService) Hello(ctx pd10.Context, req *HelloRequest) ([]* } } -func (c *client_GreetingService) Hello_Async(ctx pd10.Context, req *HelloRequest) (<-chan GreetingService_Hello_AsyncResult, error) { +func (c *client_GreetingService) Hello_Async(ctx pd8.Context, req *HelloRequest) (<-chan GreetingService_Hello_AsyncResult, error) { // check if we have memoized that this method is not supported by the server c.ulk.Lock() notSupported := c.unsupported["Hello"] c.ulk.Unlock() if notSupported { - return nil, pd14.ErrSchema + return nil, pd13.ErrSchema } envelope := &AnonInductive4{ Hello: req, } - buf, err := pd11.Encode(envelope, pd13.Encode) + buf, err := pd5.Encode(envelope, pd9.Encode) if err != nil { - return nil, pd1.Errorf("unexpected serialization error (%v)", err) + return nil, pd3.Errorf("unexpected serialization error (%v)", err) } // encode request in URL u := *c.endpoint - q := pd4.Values{} + q := pd11.Values{} q.Set("q", string(buf)) u.RawQuery = q.Encode() - httpReq, err := pd6.NewRequestWithContext(ctx, "POST", u.String(), pd8.NewReader(buf)) + httpReq, err := pd6.NewRequestWithContext(ctx, "POST", u.String(), pd10.NewReader(buf)) if err != nil { return nil, err } @@ -1184,7 +1199,7 @@ func (c *client_GreetingService) Hello_Async(ctx pd10.Context, req *HelloRequest resp, err := c.httpClient.Do(httpReq) if err != nil { - return nil, pd1.Errorf("sending HTTP request (%v)", err) + return nil, pd3.Errorf("sending HTTP request (%v)", err) } // HTTP codes 400 and 404 correspond to unrecognized method or request schema @@ -1194,7 +1209,22 @@ func (c *client_GreetingService) Hello_Async(ctx pd10.Context, req *HelloRequest c.ulk.Lock() c.unsupported["Hello"] = true c.ulk.Unlock() - return nil, pd14.ErrSchema + return nil, pd13.ErrSchema + } + // HTTP codes other than 200 correspond to service implementation rejecting the call when it is received + // for reasons unrelated to protocol schema + if resp.StatusCode != 200 { + resp.Body.Close() + if resp.Header != nil { + if errValues, ok := resp.Header["Error"]; ok && len(errValues) == 1 { + err = pd13.ErrService{Cause: pd3.Errorf("%s", errValues[0])} + } else { + err = pd3.Errorf("service rejected the call, no cause provided") + } + } else { + err = pd3.Errorf("service rejected the call") + } + return nil, err } ch := make(chan GreetingService_Hello_AsyncResult, 1) @@ -1202,30 +1232,30 @@ func (c *client_GreetingService) Hello_Async(ctx pd10.Context, req *HelloRequest return ch, nil } -func process_GreetingService_Hello_AsyncResult(ctx pd10.Context, ch chan<- GreetingService_Hello_AsyncResult, r pd9.Reader) { +func process_GreetingService_Hello_AsyncResult(ctx pd8.Context, ch chan<- GreetingService_Hello_AsyncResult, r pd4.Reader) { defer close(ch) for { if ctx.Err() != nil { - ch <- GreetingService_Hello_AsyncResult{Err: pd14.ErrContext{Cause: ctx.Err()}} // context cancelled + ch <- GreetingService_Hello_AsyncResult{Err: pd13.ErrContext{Cause: ctx.Err()}} // context cancelled return } - n, err := pd11.DecodeStreaming(r, pd13.Decode) - if pd12.Is(err, pd9.EOF) || pd12.Is(err, pd9.ErrUnexpectedEOF) { + n, err := pd5.DecodeStreaming(r, pd9.Decode) + if pd7.Is(err, pd4.EOF) || pd7.Is(err, pd4.ErrUnexpectedEOF) { return } if err != nil { - ch <- GreetingService_Hello_AsyncResult{Err: pd14.ErrProto{Cause: err}} // IPLD decode error + ch <- GreetingService_Hello_AsyncResult{Err: pd13.ErrProto{Cause: err}} // IPLD decode error return } env := &AnonInductive5{} if err = env.Parse(n); err != nil { - ch <- GreetingService_Hello_AsyncResult{Err: pd14.ErrProto{Cause: err}} // schema decode error + ch <- GreetingService_Hello_AsyncResult{Err: pd13.ErrProto{Cause: err}} // schema decode error return } if env.Error != nil { - ch <- GreetingService_Hello_AsyncResult{Err: pd14.ErrService{Cause: pd12.New(string(env.Error.Code))}} // service-level error + ch <- GreetingService_Hello_AsyncResult{Err: pd13.ErrService{Cause: pd7.New(string(env.Error.Code))}} // service-level error return } if env.Hello == nil { @@ -1235,17 +1265,17 @@ func process_GreetingService_Hello_AsyncResult(ctx pd10.Context, ch chan<- Greet } } -var logger_server_GreetingService = pd7.Logger("service/server/greetingservice") +var logger_server_GreetingService = pd14.Logger("service/server/greetingservice") type GreetingService_Server interface { - Hello(ctx pd10.Context, req *HelloRequest) (<-chan *GreetingService_Hello_AsyncResult, error) + Hello(ctx pd8.Context, req *HelloRequest) (<-chan *GreetingService_Hello_AsyncResult, error) } func GreetingService_AsyncHandler(s GreetingService_Server) pd6.HandlerFunc { return func(writer pd6.ResponseWriter, request *pd6.Request) { // parse request msg := request.URL.Query().Get("q") - n, err := pd11.Decode([]byte(msg), pd13.Decode) + n, err := pd5.Decode([]byte(msg), pd9.Decode) if err != nil { logger_server_GreetingService.Errorf("received request not decodeable (%v)", err) writer.WriteHeader(400) @@ -1266,21 +1296,22 @@ func GreetingService_AsyncHandler(s GreetingService_Server) pd6.HandlerFunc { switch { case env.Hello != nil: - ch, err := s.Hello(pd10.Background(), env.Hello) + ch, err := s.Hello(pd8.Background(), env.Hello) if err != nil { - logger_server_GreetingService.Errorf("get p2p provider rejected request (%v)", err) + logger_server_GreetingService.Errorf("service rejected request (%v)", err) + writer.Header()["Error"] = []string{err.Error()} writer.WriteHeader(500) return } for resp := range ch { var env *AnonInductive5 if resp.Err != nil { - env = &AnonInductive5{Error: &GreetingService_Error{Code: pd3.String(resp.Err.Error())}} + env = &AnonInductive5{Error: &GreetingService_Error{Code: pd2.String(resp.Err.Error())}} } else { env = &AnonInductive5{Hello: resp.Resp} } - var buf pd8.Buffer - if err = pd11.EncodeStreaming(&buf, env, pd13.Encode); err != nil { + var buf pd10.Buffer + if err = pd5.EncodeStreaming(&buf, env, pd9.Encode); err != nil { logger_server_GreetingService.Errorf("cannot encode response (%v)", err) continue } @@ -1292,13 +1323,13 @@ func GreetingService_AsyncHandler(s GreetingService_Server) pd6.HandlerFunc { var env *AnonInductive5 env = &AnonInductive5{ Identify: &GreetingService_IdentifyResult{ - Methods: []pd3.String{ + Methods: []pd2.String{ "Hello", }, }, } - var buf pd8.Buffer - if err = pd11.EncodeStreaming(&buf, env, pd13.Encode); err != nil { + var buf pd10.Buffer + if err = pd5.EncodeStreaming(&buf, env, pd9.Encode); err != nil { logger_server_GreetingService.Errorf("cannot encode identify response (%v)", err) writer.WriteHeader(500) return @@ -1316,20 +1347,20 @@ func GreetingService_AsyncHandler(s GreetingService_Server) pd6.HandlerFunc { // -- protocol type HelloRequest -- type HelloRequest struct { - Name pd3.String + Name pd2.String Address Address } -func (x HelloRequest) Node() pd2.Node { +func (x HelloRequest) Node() pd1.Node { return x } -func (x *HelloRequest) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd3.ErrNA +func (x *HelloRequest) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd2.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd3.ParseFunc{ + fieldMap := map[string]pd2.ParseFunc{ "Name": x.Name.Parse, "Address": x.Address.Parse, } @@ -1338,13 +1369,13 @@ func (x *HelloRequest) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd1.Errorf("structure map key is not a string") + return pd3.Errorf("structure map key is not a string") } else { _ = vn switch k { case "Name": if _, notParsed := fieldMap["Name"]; !notParsed { - return pd1.Errorf("field %s already parsed", "Name") + return pd3.Errorf("field %s already parsed", "Name") } if err := x.Name.Parse(vn); err != nil { return err @@ -1352,7 +1383,7 @@ func (x *HelloRequest) Parse(n pd2.Node) error { delete(fieldMap, "Name") case "Address": if _, notParsed := fieldMap["Address"]; !notParsed { - return pd1.Errorf("field %s already parsed", "Address") + return pd3.Errorf("field %s already parsed", "Address") } if err := x.Address.Parse(vn); err != nil { return err @@ -1364,7 +1395,7 @@ func (x *HelloRequest) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -1376,27 +1407,27 @@ type HelloRequest_MapIterator struct { s *HelloRequest } -func (x *HelloRequest_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *HelloRequest_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd3.String("Name"), x.s.Name.Node(), nil + return pd2.String("Name"), x.s.Name.Node(), nil case 1: - return pd3.String("Address"), x.s.Address.Node(), nil + return pd2.String("Address"), x.s.Address.Node(), nil } - return nil, nil, pd3.ErrNA + return nil, nil, pd2.ErrNA } func (x *HelloRequest_MapIterator) Done() bool { return x.i+1 >= 2 } -func (x HelloRequest) Kind() pd2.Kind { - return pd2.Kind_Map +func (x HelloRequest) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x HelloRequest) LookupByString(key string) (pd2.Node, error) { +func (x HelloRequest) LookupByString(key string) (pd1.Node, error) { switch key { case "Name": return x.Name.Node(), nil @@ -1404,28 +1435,28 @@ func (x HelloRequest) LookupByString(key string) (pd2.Node, error) { return x.Address.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x HelloRequest) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x HelloRequest) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x HelloRequest) LookupByIndex(idx int64) (pd2.Node, error) { +func (x HelloRequest) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.Name.Node(), nil @@ -1433,10 +1464,10 @@ func (x HelloRequest) LookupByIndex(idx int64) (pd2.Node, error) { return x.Address.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x HelloRequest) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x HelloRequest) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "Name": return x.Name.Node(), nil @@ -1444,14 +1475,14 @@ func (x HelloRequest) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.Address.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x HelloRequest) MapIterator() pd2.MapIterator { +func (x HelloRequest) MapIterator() pd1.MapIterator { return &HelloRequest_MapIterator{-1, &x} } -func (x HelloRequest) ListIterator() pd2.ListIterator { +func (x HelloRequest) ListIterator() pd1.ListIterator { return nil } @@ -1468,54 +1499,54 @@ func (x HelloRequest) IsNull() bool { } func (x HelloRequest) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (x HelloRequest) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x HelloRequest) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x HelloRequest) AsString() (string, error) { - return "", pd3.ErrNA + return "", pd2.ErrNA } func (x HelloRequest) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x HelloRequest) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (x HelloRequest) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (x HelloRequest) Prototype() pd2.NodePrototype { +func (x HelloRequest) Prototype() pd1.NodePrototype { return nil } // -- protocol type AddressLines -- -type AddressLines []pd3.String +type AddressLines []pd2.String -func (v AddressLines) Node() pd2.Node { +func (v AddressLines) Node() pd1.Node { return v } -func (v *AddressLines) Parse(n pd2.Node) error { - if n.Kind() == pd2.Kind_Null { +func (v *AddressLines) Parse(n pd1.Node) error { + if n.Kind() == pd1.Kind_Null { *v = nil return nil } - if n.Kind() != pd2.Kind_List { - return pd3.ErrNA + if n.Kind() != pd1.Kind_List { + return pd2.ErrNA } else { *v = make(AddressLines, n.Length()) iter := n.ListIterator() for !iter.Done() { if i, n, err := iter.Next(); err != nil { - return pd3.ErrNA + return pd2.ErrNA } else if err = (*v)[i].Parse(n); err != nil { return err } @@ -1524,39 +1555,39 @@ func (v *AddressLines) Parse(n pd2.Node) error { } } -func (AddressLines) Kind() pd2.Kind { - return pd2.Kind_List +func (AddressLines) Kind() pd1.Kind { + return pd1.Kind_List } -func (AddressLines) LookupByString(string) (pd2.Node, error) { - return nil, pd3.ErrNA +func (AddressLines) LookupByString(string) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (AddressLines) LookupByNode(key pd2.Node) (pd2.Node, error) { - return nil, pd3.ErrNA +func (AddressLines) LookupByNode(key pd1.Node) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (v AddressLines) LookupByIndex(i int64) (pd2.Node, error) { +func (v AddressLines) LookupByIndex(i int64) (pd1.Node, error) { if i < 0 || i >= v.Length() { - return nil, pd3.ErrBounds + return nil, pd2.ErrBounds } else { return v[i].Node(), nil } } -func (v AddressLines) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (v AddressLines) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { if i, err := seg.Index(); err != nil { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } else { return v.LookupByIndex(i) } } -func (AddressLines) MapIterator() pd2.MapIterator { +func (AddressLines) MapIterator() pd1.MapIterator { return nil } -func (v AddressLines) ListIterator() pd2.ListIterator { +func (v AddressLines) ListIterator() pd1.ListIterator { return &AddressLines_ListIterator{v, 0} } @@ -1573,30 +1604,30 @@ func (AddressLines) IsNull() bool { } func (v AddressLines) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (AddressLines) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (AddressLines) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (AddressLines) AsString() (string, error) { - return "", pd3.ErrNA + return "", pd2.ErrNA } func (AddressLines) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (AddressLines) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (AddressLines) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (AddressLines) Prototype() pd2.NodePrototype { +func (AddressLines) Prototype() pd1.NodePrototype { return nil // not needed } @@ -1605,9 +1636,9 @@ type AddressLines_ListIterator struct { at int64 } -func (iter *AddressLines_ListIterator) Next() (int64, pd2.Node, error) { +func (iter *AddressLines_ListIterator) Next() (int64, pd1.Node, error) { if iter.Done() { - return -1, nil, pd3.ErrBounds + return -1, nil, pd2.ErrBounds } v := iter.list[iter.at] i := int64(iter.at) @@ -1629,10 +1660,10 @@ type Address struct { OtherAddress *AddressLines } -func (x *Address) Parse(n pd2.Node) error { +func (x *Address) Parse(n pd1.Node) error { *x = Address{} - if n.Kind() != pd2.Kind_Map { - return pd3.ErrNA + if n.Kind() != pd1.Kind_Map { + return pd2.ErrNA } iter := n.MapIterator() kn, vn, err := iter.Next() @@ -1641,7 +1672,7 @@ func (x *Address) Parse(n pd2.Node) error { } k, err := kn.AsString() if err != nil { - return pd1.Errorf("inductive map key is not a string") + return pd3.Errorf("inductive map key is not a string") } switch k { case "US": @@ -1677,22 +1708,22 @@ type Address_MapIterator struct { s *Address } -func (x *Address_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *Address_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { if x.done { - return nil, nil, pd3.ErrNA + return nil, nil, pd2.ErrNA } else { x.done = true switch { case x.s.US != nil: - return pd3.String("US"), x.s.US.Node(), nil + return pd2.String("US"), x.s.US.Node(), nil case x.s.SK != nil: - return pd3.String("SouthKorea"), x.s.SK.Node(), nil + return pd2.String("SouthKorea"), x.s.SK.Node(), nil case x.s.OtherAddress != nil: - return pd3.String(x.s.OtherCountry), x.s.OtherAddress.Node(), nil + return pd2.String(x.s.OtherCountry), x.s.OtherAddress.Node(), nil default: - return nil, nil, pd1.Errorf("no inductive cases are set") + return nil, nil, pd3.Errorf("no inductive cases are set") } } } @@ -1701,15 +1732,15 @@ func (x *Address_MapIterator) Done() bool { return x.done } -func (x Address) Node() pd2.Node { +func (x Address) Node() pd1.Node { return x } -func (x Address) Kind() pd2.Kind { - return pd2.Kind_Map +func (x Address) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x Address) LookupByString(key string) (pd2.Node, error) { +func (x Address) LookupByString(key string) (pd1.Node, error) { switch { case x.US != nil && key == "US": return x.US.Node(), nil @@ -1720,12 +1751,12 @@ func (x Address) LookupByString(key string) (pd2.Node, error) { return x.OtherAddress.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x Address) LookupByNode(key pd2.Node) (pd2.Node, error) { - if key.Kind() != pd2.Kind_String { - return nil, pd3.ErrNA +func (x Address) LookupByNode(key pd1.Node) (pd1.Node, error) { + if key.Kind() != pd1.Kind_String { + return nil, pd2.ErrNA } if s, err := key.AsString(); err != nil { return nil, err @@ -1734,11 +1765,11 @@ func (x Address) LookupByNode(key pd2.Node) (pd2.Node, error) { } } -func (x Address) LookupByIndex(idx int64) (pd2.Node, error) { - return nil, pd3.ErrNA +func (x Address) LookupByIndex(idx int64) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (x Address) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x Address) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "US": return x.US.Node(), nil @@ -1749,14 +1780,14 @@ func (x Address) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.OtherAddress.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x Address) MapIterator() pd2.MapIterator { +func (x Address) MapIterator() pd1.MapIterator { return &Address_MapIterator{false, &x} } -func (x Address) ListIterator() pd2.ListIterator { +func (x Address) ListIterator() pd1.ListIterator { return nil } @@ -1773,52 +1804,52 @@ func (x Address) IsNull() bool { } func (x Address) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (x Address) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x Address) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x Address) AsString() (string, error) { - return "", pd3.ErrNA + return "", pd2.ErrNA } func (x Address) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x Address) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (x Address) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (x Address) Prototype() pd2.NodePrototype { +func (x Address) Prototype() pd1.NodePrototype { return nil } // -- protocol type USAddress -- type USAddress struct { - Street pd3.String - City pd3.String + Street pd2.String + City pd2.String State State - ZIP pd3.Int + ZIP pd2.Int } -func (x USAddress) Node() pd2.Node { +func (x USAddress) Node() pd1.Node { return x } -func (x *USAddress) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd3.ErrNA +func (x *USAddress) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd2.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd3.ParseFunc{ + fieldMap := map[string]pd2.ParseFunc{ "street": x.Street.Parse, "city": x.City.Parse, "state": x.State.Parse, @@ -1829,13 +1860,13 @@ func (x *USAddress) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd1.Errorf("structure map key is not a string") + return pd3.Errorf("structure map key is not a string") } else { _ = vn switch k { case "street": if _, notParsed := fieldMap["street"]; !notParsed { - return pd1.Errorf("field %s already parsed", "street") + return pd3.Errorf("field %s already parsed", "street") } if err := x.Street.Parse(vn); err != nil { return err @@ -1843,7 +1874,7 @@ func (x *USAddress) Parse(n pd2.Node) error { delete(fieldMap, "street") case "city": if _, notParsed := fieldMap["city"]; !notParsed { - return pd1.Errorf("field %s already parsed", "city") + return pd3.Errorf("field %s already parsed", "city") } if err := x.City.Parse(vn); err != nil { return err @@ -1851,7 +1882,7 @@ func (x *USAddress) Parse(n pd2.Node) error { delete(fieldMap, "city") case "state": if _, notParsed := fieldMap["state"]; !notParsed { - return pd1.Errorf("field %s already parsed", "state") + return pd3.Errorf("field %s already parsed", "state") } if err := x.State.Parse(vn); err != nil { return err @@ -1859,7 +1890,7 @@ func (x *USAddress) Parse(n pd2.Node) error { delete(fieldMap, "state") case "zip": if _, notParsed := fieldMap["zip"]; !notParsed { - return pd1.Errorf("field %s already parsed", "zip") + return pd3.Errorf("field %s already parsed", "zip") } if err := x.ZIP.Parse(vn); err != nil { return err @@ -1871,7 +1902,7 @@ func (x *USAddress) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -1883,31 +1914,31 @@ type USAddress_MapIterator struct { s *USAddress } -func (x *USAddress_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *USAddress_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd3.String("street"), x.s.Street.Node(), nil + return pd2.String("street"), x.s.Street.Node(), nil case 1: - return pd3.String("city"), x.s.City.Node(), nil + return pd2.String("city"), x.s.City.Node(), nil case 2: - return pd3.String("state"), x.s.State.Node(), nil + return pd2.String("state"), x.s.State.Node(), nil case 3: - return pd3.String("zip"), x.s.ZIP.Node(), nil + return pd2.String("zip"), x.s.ZIP.Node(), nil } - return nil, nil, pd3.ErrNA + return nil, nil, pd2.ErrNA } func (x *USAddress_MapIterator) Done() bool { return x.i+1 >= 4 } -func (x USAddress) Kind() pd2.Kind { - return pd2.Kind_Map +func (x USAddress) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x USAddress) LookupByString(key string) (pd2.Node, error) { +func (x USAddress) LookupByString(key string) (pd1.Node, error) { switch key { case "street": return x.Street.Node(), nil @@ -1919,28 +1950,28 @@ func (x USAddress) LookupByString(key string) (pd2.Node, error) { return x.ZIP.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x USAddress) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x USAddress) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x USAddress) LookupByIndex(idx int64) (pd2.Node, error) { +func (x USAddress) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.Street.Node(), nil @@ -1952,10 +1983,10 @@ func (x USAddress) LookupByIndex(idx int64) (pd2.Node, error) { return x.ZIP.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x USAddress) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x USAddress) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "street": return x.Street.Node(), nil @@ -1967,14 +1998,14 @@ func (x USAddress) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.ZIP.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x USAddress) MapIterator() pd2.MapIterator { +func (x USAddress) MapIterator() pd1.MapIterator { return &USAddress_MapIterator{-1, &x} } -func (x USAddress) ListIterator() pd2.ListIterator { +func (x USAddress) ListIterator() pd1.ListIterator { return nil } @@ -1991,30 +2022,30 @@ func (x USAddress) IsNull() bool { } func (x USAddress) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (x USAddress) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x USAddress) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x USAddress) AsString() (string, error) { - return "", pd3.ErrNA + return "", pd2.ErrNA } func (x USAddress) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x USAddress) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (x USAddress) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (x USAddress) Prototype() pd2.NodePrototype { +func (x USAddress) Prototype() pd1.NodePrototype { return nil } @@ -2022,49 +2053,49 @@ func (x USAddress) Prototype() pd2.NodePrototype { type StateCA struct{} -func (StateCA) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_String { - return pd3.ErrNA +func (StateCA) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_String { + return pd2.ErrNA } v, err := n.AsString() if err != nil { return err } if v != "CA" { - return pd3.ErrNA + return pd2.ErrNA } return nil } -func (v StateCA) Node() pd2.Node { +func (v StateCA) Node() pd1.Node { return v } -func (StateCA) Kind() pd2.Kind { - return pd2.Kind_String +func (StateCA) Kind() pd1.Kind { + return pd1.Kind_String } -func (StateCA) LookupByString(string) (pd2.Node, error) { - return nil, pd3.ErrNA +func (StateCA) LookupByString(string) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (StateCA) LookupByNode(key pd2.Node) (pd2.Node, error) { - return nil, pd3.ErrNA +func (StateCA) LookupByNode(key pd1.Node) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (StateCA) LookupByIndex(idx int64) (pd2.Node, error) { - return nil, pd3.ErrNA +func (StateCA) LookupByIndex(idx int64) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (StateCA) LookupBySegment(_ pd2.PathSegment) (pd2.Node, error) { - return nil, pd3.ErrNA +func (StateCA) LookupBySegment(_ pd1.PathSegment) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (StateCA) MapIterator() pd2.MapIterator { +func (StateCA) MapIterator() pd1.MapIterator { return nil } -func (StateCA) ListIterator() pd2.ListIterator { +func (StateCA) ListIterator() pd1.ListIterator { return nil } @@ -2081,15 +2112,15 @@ func (StateCA) IsNull() bool { } func (v StateCA) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (StateCA) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (StateCA) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (StateCA) AsString() (string, error) { @@ -2097,14 +2128,14 @@ func (StateCA) AsString() (string, error) { } func (StateCA) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (StateCA) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (StateCA) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (StateCA) Prototype() pd2.NodePrototype { +func (StateCA) Prototype() pd1.NodePrototype { return nil } @@ -2112,49 +2143,49 @@ func (StateCA) Prototype() pd2.NodePrototype { type StateNY struct{} -func (StateNY) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_String { - return pd3.ErrNA +func (StateNY) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_String { + return pd2.ErrNA } v, err := n.AsString() if err != nil { return err } if v != "NY" { - return pd3.ErrNA + return pd2.ErrNA } return nil } -func (v StateNY) Node() pd2.Node { +func (v StateNY) Node() pd1.Node { return v } -func (StateNY) Kind() pd2.Kind { - return pd2.Kind_String +func (StateNY) Kind() pd1.Kind { + return pd1.Kind_String } -func (StateNY) LookupByString(string) (pd2.Node, error) { - return nil, pd3.ErrNA +func (StateNY) LookupByString(string) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (StateNY) LookupByNode(key pd2.Node) (pd2.Node, error) { - return nil, pd3.ErrNA +func (StateNY) LookupByNode(key pd1.Node) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (StateNY) LookupByIndex(idx int64) (pd2.Node, error) { - return nil, pd3.ErrNA +func (StateNY) LookupByIndex(idx int64) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (StateNY) LookupBySegment(_ pd2.PathSegment) (pd2.Node, error) { - return nil, pd3.ErrNA +func (StateNY) LookupBySegment(_ pd1.PathSegment) (pd1.Node, error) { + return nil, pd2.ErrNA } -func (StateNY) MapIterator() pd2.MapIterator { +func (StateNY) MapIterator() pd1.MapIterator { return nil } -func (StateNY) ListIterator() pd2.ListIterator { +func (StateNY) ListIterator() pd1.ListIterator { return nil } @@ -2171,15 +2202,15 @@ func (StateNY) IsNull() bool { } func (v StateNY) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (StateNY) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (StateNY) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (StateNY) AsString() (string, error) { @@ -2187,14 +2218,14 @@ func (StateNY) AsString() (string, error) { } func (StateNY) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (StateNY) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (StateNY) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (StateNY) Prototype() pd2.NodePrototype { +func (StateNY) Prototype() pd1.NodePrototype { return nil } @@ -2203,10 +2234,10 @@ func (StateNY) Prototype() pd2.NodePrototype { type State struct { CA *StateCA NY *StateNY - Other *pd3.String + Other *pd2.String } -func (x *State) Parse(n pd2.Node) error { +func (x *State) Parse(n pd1.Node) error { *x = State{} var CA StateCA @@ -2221,16 +2252,16 @@ func (x *State) Parse(n pd2.Node) error { return nil } - var Other pd3.String + var Other pd2.String if err := Other.Parse(n); err == nil { x.Other = &Other return nil } - return pd1.Errorf("no union cases parses") + return pd3.Errorf("no union cases parses") } -func (x State) Node() pd2.Node { +func (x State) Node() pd1.Node { if x.CA != nil { return x.CA } @@ -2246,7 +2277,7 @@ func (x State) Node() pd2.Node { // proxy Node methods to active case -func (x State) Kind() pd2.Kind { +func (x State) Kind() pd1.Kind { if x.CA != nil { return x.CA.Kind() } @@ -2257,10 +2288,10 @@ func (x State) Kind() pd2.Kind { return x.Other.Kind() } - return pd2.Kind_Invalid + return pd1.Kind_Invalid } -func (x State) LookupByString(key string) (pd2.Node, error) { +func (x State) LookupByString(key string) (pd1.Node, error) { if x.CA != nil { return x.CA.LookupByString(key) } @@ -2271,10 +2302,10 @@ func (x State) LookupByString(key string) (pd2.Node, error) { return x.Other.LookupByString(key) } - return nil, pd1.Errorf("no active union case found") + return nil, pd3.Errorf("no active union case found") } -func (x State) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x State) LookupByNode(key pd1.Node) (pd1.Node, error) { if x.CA != nil { return x.CA.LookupByNode(key) } @@ -2285,10 +2316,10 @@ func (x State) LookupByNode(key pd2.Node) (pd2.Node, error) { return x.Other.LookupByNode(key) } - return nil, pd1.Errorf("no active union case found") + return nil, pd3.Errorf("no active union case found") } -func (x State) LookupByIndex(idx int64) (pd2.Node, error) { +func (x State) LookupByIndex(idx int64) (pd1.Node, error) { if x.CA != nil { return x.CA.LookupByIndex(idx) } @@ -2299,10 +2330,10 @@ func (x State) LookupByIndex(idx int64) (pd2.Node, error) { return x.Other.LookupByIndex(idx) } - return nil, pd1.Errorf("no active union case found") + return nil, pd3.Errorf("no active union case found") } -func (x State) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x State) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { if x.CA != nil { return x.CA.LookupBySegment(seg) } @@ -2313,10 +2344,10 @@ func (x State) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.Other.LookupBySegment(seg) } - return nil, pd1.Errorf("no active union case found") + return nil, pd3.Errorf("no active union case found") } -func (x State) MapIterator() pd2.MapIterator { +func (x State) MapIterator() pd1.MapIterator { if x.CA != nil { return x.CA.MapIterator() } @@ -2330,7 +2361,7 @@ func (x State) MapIterator() pd2.MapIterator { return nil } -func (x State) ListIterator() pd2.ListIterator { +func (x State) ListIterator() pd1.ListIterator { if x.CA != nil { return x.CA.ListIterator() } @@ -2397,7 +2428,7 @@ func (x State) AsBool() (bool, error) { return x.Other.AsBool() } - return false, pd1.Errorf("no active union case found") + return false, pd3.Errorf("no active union case found") } func (x State) AsInt() (int64, error) { @@ -2411,7 +2442,7 @@ func (x State) AsInt() (int64, error) { return x.Other.AsInt() } - return 0, pd1.Errorf("no active union case found") + return 0, pd3.Errorf("no active union case found") } func (x State) AsFloat() (float64, error) { @@ -2425,7 +2456,7 @@ func (x State) AsFloat() (float64, error) { return x.Other.AsFloat() } - return 0.0, pd1.Errorf("no active union case found") + return 0.0, pd3.Errorf("no active union case found") } func (x State) AsString() (string, error) { @@ -2439,7 +2470,7 @@ func (x State) AsString() (string, error) { return x.Other.AsString() } - return "", pd1.Errorf("no active union case found") + return "", pd3.Errorf("no active union case found") } func (x State) AsBytes() ([]byte, error) { @@ -2453,10 +2484,10 @@ func (x State) AsBytes() ([]byte, error) { return x.Other.AsBytes() } - return nil, pd1.Errorf("no active union case found") + return nil, pd3.Errorf("no active union case found") } -func (x State) AsLink() (pd2.Link, error) { +func (x State) AsLink() (pd1.Link, error) { if x.CA != nil { return x.CA.AsLink() } @@ -2467,32 +2498,32 @@ func (x State) AsLink() (pd2.Link, error) { return x.Other.AsLink() } - return nil, pd1.Errorf("no active union case found") + return nil, pd3.Errorf("no active union case found") } -func (x State) Prototype() pd2.NodePrototype { +func (x State) Prototype() pd1.NodePrototype { return nil } // -- protocol type SKAddress -- type SKAddress struct { - Street pd3.String - City pd3.String - Province pd3.String - PostalCode pd3.Int + Street pd2.String + City pd2.String + Province pd2.String + PostalCode pd2.Int } -func (x SKAddress) Node() pd2.Node { +func (x SKAddress) Node() pd1.Node { return x } -func (x *SKAddress) Parse(n pd2.Node) error { - if n.Kind() != pd2.Kind_Map { - return pd3.ErrNA +func (x *SKAddress) Parse(n pd1.Node) error { + if n.Kind() != pd1.Kind_Map { + return pd2.ErrNA } iter := n.MapIterator() - fieldMap := map[string]pd3.ParseFunc{ + fieldMap := map[string]pd2.ParseFunc{ "street": x.Street.Parse, "city": x.City.Parse, "province": x.Province.Parse, @@ -2503,13 +2534,13 @@ func (x *SKAddress) Parse(n pd2.Node) error { return err } else { if k, err := kn.AsString(); err != nil { - return pd1.Errorf("structure map key is not a string") + return pd3.Errorf("structure map key is not a string") } else { _ = vn switch k { case "street": if _, notParsed := fieldMap["street"]; !notParsed { - return pd1.Errorf("field %s already parsed", "street") + return pd3.Errorf("field %s already parsed", "street") } if err := x.Street.Parse(vn); err != nil { return err @@ -2517,7 +2548,7 @@ func (x *SKAddress) Parse(n pd2.Node) error { delete(fieldMap, "street") case "city": if _, notParsed := fieldMap["city"]; !notParsed { - return pd1.Errorf("field %s already parsed", "city") + return pd3.Errorf("field %s already parsed", "city") } if err := x.City.Parse(vn); err != nil { return err @@ -2525,7 +2556,7 @@ func (x *SKAddress) Parse(n pd2.Node) error { delete(fieldMap, "city") case "province": if _, notParsed := fieldMap["province"]; !notParsed { - return pd1.Errorf("field %s already parsed", "province") + return pd3.Errorf("field %s already parsed", "province") } if err := x.Province.Parse(vn); err != nil { return err @@ -2533,7 +2564,7 @@ func (x *SKAddress) Parse(n pd2.Node) error { delete(fieldMap, "province") case "postal_code": if _, notParsed := fieldMap["postal_code"]; !notParsed { - return pd1.Errorf("field %s already parsed", "postal_code") + return pd3.Errorf("field %s already parsed", "postal_code") } if err := x.PostalCode.Parse(vn); err != nil { return err @@ -2545,7 +2576,7 @@ func (x *SKAddress) Parse(n pd2.Node) error { } } for _, fieldParse := range fieldMap { - if err := fieldParse(pd2.Null); err != nil { + if err := fieldParse(pd1.Null); err != nil { return err } } @@ -2557,31 +2588,31 @@ type SKAddress_MapIterator struct { s *SKAddress } -func (x *SKAddress_MapIterator) Next() (key pd2.Node, value pd2.Node, err error) { +func (x *SKAddress_MapIterator) Next() (key pd1.Node, value pd1.Node, err error) { x.i++ switch x.i { case 0: - return pd3.String("street"), x.s.Street.Node(), nil + return pd2.String("street"), x.s.Street.Node(), nil case 1: - return pd3.String("city"), x.s.City.Node(), nil + return pd2.String("city"), x.s.City.Node(), nil case 2: - return pd3.String("province"), x.s.Province.Node(), nil + return pd2.String("province"), x.s.Province.Node(), nil case 3: - return pd3.String("postal_code"), x.s.PostalCode.Node(), nil + return pd2.String("postal_code"), x.s.PostalCode.Node(), nil } - return nil, nil, pd3.ErrNA + return nil, nil, pd2.ErrNA } func (x *SKAddress_MapIterator) Done() bool { return x.i+1 >= 4 } -func (x SKAddress) Kind() pd2.Kind { - return pd2.Kind_Map +func (x SKAddress) Kind() pd1.Kind { + return pd1.Kind_Map } -func (x SKAddress) LookupByString(key string) (pd2.Node, error) { +func (x SKAddress) LookupByString(key string) (pd1.Node, error) { switch key { case "street": return x.Street.Node(), nil @@ -2593,28 +2624,28 @@ func (x SKAddress) LookupByString(key string) (pd2.Node, error) { return x.PostalCode.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x SKAddress) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x SKAddress) LookupByNode(key pd1.Node) (pd1.Node, error) { switch key.Kind() { - case pd2.Kind_String: + case pd1.Kind_String: if s, err := key.AsString(); err != nil { return nil, err } else { return x.LookupByString(s) } - case pd2.Kind_Int: + case pd1.Kind_Int: if i, err := key.AsInt(); err != nil { return nil, err } else { return x.LookupByIndex(i) } } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x SKAddress) LookupByIndex(idx int64) (pd2.Node, error) { +func (x SKAddress) LookupByIndex(idx int64) (pd1.Node, error) { switch idx { case 0: return x.Street.Node(), nil @@ -2626,10 +2657,10 @@ func (x SKAddress) LookupByIndex(idx int64) (pd2.Node, error) { return x.PostalCode.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x SKAddress) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x SKAddress) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { switch seg.String() { case "0", "street": return x.Street.Node(), nil @@ -2641,14 +2672,14 @@ func (x SKAddress) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.PostalCode.Node(), nil } - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x SKAddress) MapIterator() pd2.MapIterator { +func (x SKAddress) MapIterator() pd1.MapIterator { return &SKAddress_MapIterator{-1, &x} } -func (x SKAddress) ListIterator() pd2.ListIterator { +func (x SKAddress) ListIterator() pd1.ListIterator { return nil } @@ -2665,59 +2696,59 @@ func (x SKAddress) IsNull() bool { } func (x SKAddress) AsBool() (bool, error) { - return false, pd3.ErrNA + return false, pd2.ErrNA } func (x SKAddress) AsInt() (int64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x SKAddress) AsFloat() (float64, error) { - return 0, pd3.ErrNA + return 0, pd2.ErrNA } func (x SKAddress) AsString() (string, error) { - return "", pd3.ErrNA + return "", pd2.ErrNA } func (x SKAddress) AsBytes() ([]byte, error) { - return nil, pd3.ErrNA + return nil, pd2.ErrNA } -func (x SKAddress) AsLink() (pd2.Link, error) { - return nil, pd3.ErrNA +func (x SKAddress) AsLink() (pd1.Link, error) { + return nil, pd2.ErrNA } -func (x SKAddress) Prototype() pd2.NodePrototype { +func (x SKAddress) Prototype() pd1.NodePrototype { return nil } // -- protocol type HelloResponse -- type HelloResponse struct { - English *pd3.String - Korean *pd3.String + English *pd2.String + Korean *pd2.String } -func (x *HelloResponse) Parse(n pd2.Node) error { +func (x *HelloResponse) Parse(n pd1.Node) error { *x = HelloResponse{} - var English pd3.String + var English pd2.String if err := English.Parse(n); err == nil { x.English = &English return nil } - var Korean pd3.String + var Korean pd2.String if err := Korean.Parse(n); err == nil { x.Korean = &Korean return nil } - return pd1.Errorf("no union cases parses") + return pd3.Errorf("no union cases parses") } -func (x HelloResponse) Node() pd2.Node { +func (x HelloResponse) Node() pd1.Node { if x.English != nil { return x.English } @@ -2730,7 +2761,7 @@ func (x HelloResponse) Node() pd2.Node { // proxy Node methods to active case -func (x HelloResponse) Kind() pd2.Kind { +func (x HelloResponse) Kind() pd1.Kind { if x.English != nil { return x.English.Kind() } @@ -2738,10 +2769,10 @@ func (x HelloResponse) Kind() pd2.Kind { return x.Korean.Kind() } - return pd2.Kind_Invalid + return pd1.Kind_Invalid } -func (x HelloResponse) LookupByString(key string) (pd2.Node, error) { +func (x HelloResponse) LookupByString(key string) (pd1.Node, error) { if x.English != nil { return x.English.LookupByString(key) } @@ -2749,10 +2780,10 @@ func (x HelloResponse) LookupByString(key string) (pd2.Node, error) { return x.Korean.LookupByString(key) } - return nil, pd1.Errorf("no active union case found") + return nil, pd3.Errorf("no active union case found") } -func (x HelloResponse) LookupByNode(key pd2.Node) (pd2.Node, error) { +func (x HelloResponse) LookupByNode(key pd1.Node) (pd1.Node, error) { if x.English != nil { return x.English.LookupByNode(key) } @@ -2760,10 +2791,10 @@ func (x HelloResponse) LookupByNode(key pd2.Node) (pd2.Node, error) { return x.Korean.LookupByNode(key) } - return nil, pd1.Errorf("no active union case found") + return nil, pd3.Errorf("no active union case found") } -func (x HelloResponse) LookupByIndex(idx int64) (pd2.Node, error) { +func (x HelloResponse) LookupByIndex(idx int64) (pd1.Node, error) { if x.English != nil { return x.English.LookupByIndex(idx) } @@ -2771,10 +2802,10 @@ func (x HelloResponse) LookupByIndex(idx int64) (pd2.Node, error) { return x.Korean.LookupByIndex(idx) } - return nil, pd1.Errorf("no active union case found") + return nil, pd3.Errorf("no active union case found") } -func (x HelloResponse) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { +func (x HelloResponse) LookupBySegment(seg pd1.PathSegment) (pd1.Node, error) { if x.English != nil { return x.English.LookupBySegment(seg) } @@ -2782,10 +2813,10 @@ func (x HelloResponse) LookupBySegment(seg pd2.PathSegment) (pd2.Node, error) { return x.Korean.LookupBySegment(seg) } - return nil, pd1.Errorf("no active union case found") + return nil, pd3.Errorf("no active union case found") } -func (x HelloResponse) MapIterator() pd2.MapIterator { +func (x HelloResponse) MapIterator() pd1.MapIterator { if x.English != nil { return x.English.MapIterator() } @@ -2796,7 +2827,7 @@ func (x HelloResponse) MapIterator() pd2.MapIterator { return nil } -func (x HelloResponse) ListIterator() pd2.ListIterator { +func (x HelloResponse) ListIterator() pd1.ListIterator { if x.English != nil { return x.English.ListIterator() } @@ -2848,7 +2879,7 @@ func (x HelloResponse) AsBool() (bool, error) { return x.Korean.AsBool() } - return false, pd1.Errorf("no active union case found") + return false, pd3.Errorf("no active union case found") } func (x HelloResponse) AsInt() (int64, error) { @@ -2859,7 +2890,7 @@ func (x HelloResponse) AsInt() (int64, error) { return x.Korean.AsInt() } - return 0, pd1.Errorf("no active union case found") + return 0, pd3.Errorf("no active union case found") } func (x HelloResponse) AsFloat() (float64, error) { @@ -2870,7 +2901,7 @@ func (x HelloResponse) AsFloat() (float64, error) { return x.Korean.AsFloat() } - return 0.0, pd1.Errorf("no active union case found") + return 0.0, pd3.Errorf("no active union case found") } func (x HelloResponse) AsString() (string, error) { @@ -2881,7 +2912,7 @@ func (x HelloResponse) AsString() (string, error) { return x.Korean.AsString() } - return "", pd1.Errorf("no active union case found") + return "", pd3.Errorf("no active union case found") } func (x HelloResponse) AsBytes() ([]byte, error) { @@ -2892,10 +2923,10 @@ func (x HelloResponse) AsBytes() ([]byte, error) { return x.Korean.AsBytes() } - return nil, pd1.Errorf("no active union case found") + return nil, pd3.Errorf("no active union case found") } -func (x HelloResponse) AsLink() (pd2.Link, error) { +func (x HelloResponse) AsLink() (pd1.Link, error) { if x.English != nil { return x.English.AsLink() } @@ -2903,9 +2934,9 @@ func (x HelloResponse) AsLink() (pd2.Link, error) { return x.Korean.AsLink() } - return nil, pd1.Errorf("no active union case found") + return nil, pd3.Errorf("no active union case found") } -func (x HelloResponse) Prototype() pd2.NodePrototype { +func (x HelloResponse) Prototype() pd1.NodePrototype { return nil } diff --git a/test/service_test.go b/test/service_test.go index 04f83e8..f6b7d34 100644 --- a/test/service_test.go +++ b/test/service_test.go @@ -6,7 +6,7 @@ import ( "github.com/ipld/edelweiss/defs" ) -func TestService(t *testing.T) { +func TestServiceWithoutErrors(t *testing.T) { defs := defs.Defs{ defs.Named{Name: "TestService1", Type: defs.Service{ @@ -118,3 +118,70 @@ func TestRoundtrip(t *testing.T) { }` RunGenTest(t, defs, testSrc) } + +func TestServiceWithErrors(t *testing.T) { + defs := defs.Defs{ + defs.Named{Name: "TestService1", + Type: defs.Service{ + Methods: defs.Methods{ + defs.Method{Name: "Method1", Type: defs.Fn{Arg: defs.Int{}, Return: defs.Bool{}}}, + defs.Method{Name: "Method2", Type: defs.Fn{Arg: defs.String{}, Return: defs.Float{}}}, + }, + }, + }, + } + testSrc := ` + +var testAsyncError = "async error" +var testSyncError = "sync error" + +type TestService1_ServerImpl struct{} + +func (TestService1_ServerImpl) Method1(ctx context.Context, req *values.Int) (<-chan *TestService1_Method1_AsyncResult, error) { + respCh := make(chan *TestService1_Method1_AsyncResult) + go func() { + defer close(respCh) + respCh <- &TestService1_Method1_AsyncResult{ Err: fmt.Errorf(testAsyncError) } + }() + return respCh, nil +} + +func (TestService1_ServerImpl) Method2(ctx context.Context, req *values.String) (<-chan *TestService1_Method2_AsyncResult, error) { + return nil, fmt.Errorf(testSyncError) +} + +func TestRoundtrip(t *testing.T) { + + s := httptest.NewServer(TestService1_AsyncHandler(TestService1_ServerImpl{})) + defer s.Close() + + c1, err := New_TestService1_Client(s.URL, TestService1_Client_WithHTTPClient(s.Client())) + if err != nil { + t.Fatal(err) + } + + ctx := context.Background() + + ch1, err := c1.Method1_Async(ctx, values.NewInt(5)) + if err != nil { + t.Fatalf("sync error not expected (%v)", err) + } + for asyncResult := range ch1 { + if asyncResult.Err == nil { + t.Errorf("async error expectded") + } + if asyncResult.Err.Error() != testAsyncError { + t.Errorf("expected %v, got %v", testAsyncError, asyncResult.Err.Error()) + } + } + + _, err = c1.Method2_Async(ctx, values.NewString("5")) + if err == nil { + t.Fatalf("sync error expected") + } + if err.Error() != testSyncError { + t.Fatalf("expected %v, got %v", testSyncError, err.Error()) + } +}` + RunGenTest(t, defs, testSrc) +}