From c03db7d1781a3e9586aad2cfab8c1a2017f5f9f2 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Mon, 21 Sep 2020 17:47:26 -0700 Subject: [PATCH] feat(deps): update ipld-prime near master update to lastest needed sha for filecoin, reinstitute generated node tests --- go.mod | 5 +- go.sum | 18 +- testutil/chaintypes/gen/main.go | 51 +- testutil/chaintypes/minima.go | 30 + testutil/chaintypes/tBlock.go | 920 +++++++++++++++++++++++++++++++ testutil/chaintypes/tBytes.go | 225 ++++++++ testutil/chaintypes/tLink.go | 225 ++++++++ testutil/chaintypes/tMessages.go | 578 +++++++++++++++++++ testutil/chaintypes/tParents.go | 578 +++++++++++++++++++ testutil/chaintypes/tString.go | 229 ++++++++ testutil/chaintypes/typeTable.go | 28 + testutil/testchain.go | 22 +- 12 files changed, 2850 insertions(+), 59 deletions(-) create mode 100644 testutil/chaintypes/minima.go create mode 100644 testutil/chaintypes/tBlock.go create mode 100644 testutil/chaintypes/tBytes.go create mode 100644 testutil/chaintypes/tLink.go create mode 100644 testutil/chaintypes/tMessages.go create mode 100644 testutil/chaintypes/tParents.go create mode 100644 testutil/chaintypes/tString.go create mode 100644 testutil/chaintypes/typeTable.go diff --git a/go.mod b/go.mod index b85f2261..0a99b593 100644 --- a/go.mod +++ b/go.mod @@ -26,8 +26,8 @@ require ( github.com/ipfs/go-merkledag v0.3.1 github.com/ipfs/go-peertaskqueue v0.2.0 github.com/ipfs/go-unixfs v0.2.4 - github.com/ipld/go-ipld-prime v0.5.0 - github.com/ipld/go-ipld-prime-proto v0.0.0-20200908180311-da0ab5c81760 + github.com/ipld/go-ipld-prime v0.5.1-0.20200828233916-988837377a7f + github.com/ipld/go-ipld-prime-proto v0.0.0-20200922000432-18d8669296eb github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c github.com/jbenet/goprocess v0.1.4 // indirect github.com/libp2p/go-libp2p v0.6.0 @@ -39,7 +39,6 @@ require ( github.com/multiformats/go-multihash v0.0.13 github.com/polydawn/refmt v0.0.0-20190809202753-05966cbd336a // indirect github.com/smartystreets/assertions v1.0.1 // indirect - github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect github.com/stretchr/testify v1.5.1 github.com/whyrusleeping/cbor-gen v0.0.0-20200710004633-5379fc63235d go.uber.org/multierr v1.4.0 // indirect diff --git a/go.sum b/go.sum index 0b694bca..d195bc1e 100644 --- a/go.sum +++ b/go.sum @@ -229,16 +229,10 @@ github.com/ipfs/go-unixfs v0.2.4 h1:6NwppOXefWIyysZ4LR/qUBPvXd5//8J3jiMdvpbw6Lo= github.com/ipfs/go-unixfs v0.2.4/go.mod h1:SUdisfUjNoSDzzhGVxvCL9QO/nKdwXdr+gbMUdqcbYw= github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2E= github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0= -github.com/ipld/go-ipld-prime v0.0.2-0.20200428162820-8b59dc292b8e h1:ZISbJlM0urTANR9KRfRaqlBmyOj5uUtxs2r4Up9IXsA= -github.com/ipld/go-ipld-prime v0.0.2-0.20200428162820-8b59dc292b8e/go.mod h1:uVIwe/u0H4VdKv3kaN1ck7uCb6yD9cFLS9/ELyXbsw8= -github.com/ipld/go-ipld-prime v0.0.4-0.20200828224805-5ff8c8b0b6ef h1:/yPelt/0CuzZsmRkYzBBnJ499JnAOGaIaAXHujx96ic= -github.com/ipld/go-ipld-prime v0.0.4-0.20200828224805-5ff8c8b0b6ef/go.mod h1:uVIwe/u0H4VdKv3kaN1ck7uCb6yD9cFLS9/ELyXbsw8= -github.com/ipld/go-ipld-prime v0.5.0 h1:kr3nB6/JcFpc3Yj7vveXYuiVyZJzWUkJyLMjQbnoswE= -github.com/ipld/go-ipld-prime v0.5.0/go.mod h1:uVIwe/u0H4VdKv3kaN1ck7uCb6yD9cFLS9/ELyXbsw8= -github.com/ipld/go-ipld-prime-proto v0.0.0-20200828231332-ae0aea07222b h1:ZtlW6pubN17TDaStlxgrwEXXwwUfJaXu9RobwczXato= -github.com/ipld/go-ipld-prime-proto v0.0.0-20200828231332-ae0aea07222b/go.mod h1:OAV6xBmuTLsPZ+epzKkPB1e25FHk/vCtyatkdHcArLs= -github.com/ipld/go-ipld-prime-proto v0.0.0-20200908180311-da0ab5c81760 h1:U616lpfmDGbaRaKvnecuAEj9T05zmW/IkoaYrWaaU0s= -github.com/ipld/go-ipld-prime-proto v0.0.0-20200908180311-da0ab5c81760/go.mod h1:tDYA+DyZ5+imKlOj/2YqJS5cMAFjWKN4aUBQUw8FvqM= +github.com/ipld/go-ipld-prime v0.5.1-0.20200828233916-988837377a7f h1:XpOuNQ5GbXxUcSukbQcW9jkE7REpaFGJU2/T00fo9kA= +github.com/ipld/go-ipld-prime v0.5.1-0.20200828233916-988837377a7f/go.mod h1:0xEgdD6MKbZ1vF0GC+YcR/C4SQCAlRuOjIJ2i0HxqzM= +github.com/ipld/go-ipld-prime-proto v0.0.0-20200922000432-18d8669296eb h1:pNGpxNHva+TCo3SyLe3s4YrBp0PJbbFoOswFoS1A4H8= +github.com/ipld/go-ipld-prime-proto v0.0.0-20200922000432-18d8669296eb/go.mod h1:3pHYooM9Ea65jewRwrb2u5uHZCNkNTe9ABsVB+SrkH0= github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc= github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA= github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= @@ -549,8 +543,8 @@ github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUr github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2RVY1rIf+2J2o/IM9+vPq9RzmHDSseB7FoXiSNIUsoU= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8= -github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smola/gocompat v0.2.0/go.mod h1:1B0MlxbmoZNo3h8guHp8HztB3BSYR5itql9qtVc0ypY= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a h1:/eS3yfGjQKG+9kayBkj0ip1BGhq6zJ3eaVksphxAaek= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= diff --git a/testutil/chaintypes/gen/main.go b/testutil/chaintypes/gen/main.go index 61cfd9c6..9ca672cd 100644 --- a/testutil/chaintypes/gen/main.go +++ b/testutil/chaintypes/gen/main.go @@ -1,47 +1,32 @@ package main import ( - "os" + "os/exec" "github.com/ipld/go-ipld-prime/schema" gengo "github.com/ipld/go-ipld-prime/schema/gen/go" ) func main() { - openOrPanic := func(filename string) *os.File { - y, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) - if err != nil { - panic(err) - } - return y - } - - tLink := schema.SpawnLink("Link") - tBytes := schema.SpawnBytes("Bytes") - tString := schema.SpawnString("String") - tParents := schema.SpawnList("Parents", tLink, false) - tMessages := schema.SpawnList("Messages", tBytes, false) - tBlock := schema.SpawnStruct("Block", - []schema.StructField{ - schema.SpawnStructField("Parents", tParents, false, false), - schema.SpawnStructField("Messages", tMessages, false, false), - }, - schema.StructRepresentation_Map{}, - ) + ts := schema.TypeSystem{} + ts.Init() adjCfg := &gengo.AdjunctCfg{} - pkgName := "chaintypes" - f := openOrPanic("testchain_minima.go") - gengo.EmitInternalEnums(pkgName, f) - - f = openOrPanic("testchain_gen.go") - gengo.EmitFileHeader(pkgName, f) - gengo.EmitEntireType(gengo.NewBytesReprBytesGenerator(pkgName, tBytes, adjCfg), f) - gengo.EmitEntireType(gengo.NewLinkReprLinkGenerator(pkgName, tLink, adjCfg), f) - gengo.EmitEntireType(gengo.NewStringReprStringGenerator(pkgName, tString, adjCfg), f) - gengo.EmitEntireType(gengo.NewListReprListGenerator(pkgName, tParents, adjCfg), f) - gengo.EmitEntireType(gengo.NewListReprListGenerator(pkgName, tMessages, adjCfg), f) - gengo.EmitEntireType(gengo.NewStructReprMapGenerator(pkgName, tBlock, adjCfg), f) + pkgName := "chaintypes" + ts.Accumulate(schema.SpawnLink("Link")) + ts.Accumulate(schema.SpawnBytes("Bytes")) + ts.Accumulate(schema.SpawnString("String")) + ts.Accumulate(schema.SpawnList("Parents", "Link", false)) + ts.Accumulate(schema.SpawnList("Messages", "Bytes", false)) + ts.Accumulate(schema.SpawnStruct("Block", + []schema.StructField{ + schema.SpawnStructField("Parents", "Parents", false, false), + schema.SpawnStructField("Messages", "Messages", false, false), + }, + schema.SpawnStructRepresentationMap(nil), + )) + gengo.Generate(".", pkgName, ts, adjCfg) + exec.Command("go", "fmt").Run() } diff --git a/testutil/chaintypes/minima.go b/testutil/chaintypes/minima.go new file mode 100644 index 00000000..a2f24229 --- /dev/null +++ b/testutil/chaintypes/minima.go @@ -0,0 +1,30 @@ +package chaintypes + +// Code generated by go-ipld-prime gengo. DO NOT EDIT. + +import ( + "github.com/ipld/go-ipld-prime/schema" +) + +const ( + midvalue = schema.Maybe(4) + allowNull = schema.Maybe(5) +) + +type maState uint8 + +const ( + maState_initial maState = iota + maState_midKey + maState_expectValue + maState_midValue + maState_finished +) + +type laState uint8 + +const ( + laState_initial laState = iota + laState_midValue + laState_finished +) diff --git a/testutil/chaintypes/tBlock.go b/testutil/chaintypes/tBlock.go new file mode 100644 index 00000000..a68bfd5e --- /dev/null +++ b/testutil/chaintypes/tBlock.go @@ -0,0 +1,920 @@ +package chaintypes + +// Code generated by go-ipld-prime gengo. DO NOT EDIT. + +import ( + ipld "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/node/mixins" + "github.com/ipld/go-ipld-prime/schema" +) + +type _Block struct { + Parents _Parents + Messages _Messages +} +type Block = *_Block + +func (n _Block) FieldParents() Parents { + return &n.Parents +} +func (n _Block) FieldMessages() Messages { + return &n.Messages +} + +type _Block__Maybe struct { + m schema.Maybe + v Block +} +type MaybeBlock = *_Block__Maybe + +func (m MaybeBlock) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeBlock) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeBlock) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeBlock) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeBlock) Must() Block { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var ( + fieldName__Block_Parents = _String{"Parents"} + fieldName__Block_Messages = _String{"Messages"} +) +var _ ipld.Node = (Block)(&_Block{}) +var _ schema.TypedNode = (Block)(&_Block{}) + +func (Block) ReprKind() ipld.ReprKind { + return ipld.ReprKind_Map +} +func (n Block) LookupByString(key string) (ipld.Node, error) { + switch key { + case "Parents": + return &n.Parents, nil + case "Messages": + return &n.Messages, nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} + } +} +func (n Block) LookupByNode(key ipld.Node) (ipld.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (Block) LookupByIndex(idx int) (ipld.Node, error) { + return mixins.Map{"chaintypes.Block"}.LookupByIndex(0) +} +func (n Block) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return n.LookupByString(seg.String()) +} +func (n Block) MapIterator() ipld.MapIterator { + return &_Block__MapItr{n, 0} +} + +type _Block__MapItr struct { + n Block + idx int +} + +func (itr *_Block__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) { + if itr.idx >= 2 { + return nil, nil, ipld.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__Block_Parents + v = &itr.n.Parents + case 1: + k = &fieldName__Block_Messages + v = &itr.n.Messages + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_Block__MapItr) Done() bool { + return itr.idx >= 2 +} + +func (Block) ListIterator() ipld.ListIterator { + return nil +} +func (Block) Length() int { + return 2 +} +func (Block) IsAbsent() bool { + return false +} +func (Block) IsNull() bool { + return false +} +func (Block) AsBool() (bool, error) { + return mixins.Map{"chaintypes.Block"}.AsBool() +} +func (Block) AsInt() (int, error) { + return mixins.Map{"chaintypes.Block"}.AsInt() +} +func (Block) AsFloat() (float64, error) { + return mixins.Map{"chaintypes.Block"}.AsFloat() +} +func (Block) AsString() (string, error) { + return mixins.Map{"chaintypes.Block"}.AsString() +} +func (Block) AsBytes() ([]byte, error) { + return mixins.Map{"chaintypes.Block"}.AsBytes() +} +func (Block) AsLink() (ipld.Link, error) { + return mixins.Map{"chaintypes.Block"}.AsLink() +} +func (Block) Prototype() ipld.NodePrototype { + return _Block__Prototype{} +} + +type _Block__Prototype struct{} + +func (_Block__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _Block__Builder + nb.Reset() + return &nb +} + +type _Block__Builder struct { + _Block__Assembler +} + +func (nb *_Block__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_Block__Builder) Reset() { + var w _Block + var m schema.Maybe + *nb = _Block__Builder{_Block__Assembler{w: &w, m: &m}} +} + +type _Block__Assembler struct { + w *_Block + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_Parents _Parents__Assembler + ca_Messages _Messages__Assembler +} + +func (na *_Block__Assembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_Parents.reset() + na.ca_Messages.reset() +} + +var ( + fieldBit__Block_Parents = 1 << 0 + fieldBit__Block_Messages = 1 << 1 + fieldBits__Block_sufficient = 0 + 1<<0 + 1<<1 +) + +func (na *_Block__Assembler) BeginMap(int) (ipld.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_Block{} + } + return na, nil +} +func (_Block__Assembler) BeginList(sizeHint int) (ipld.ListAssembler, error) { + return mixins.MapAssembler{"chaintypes.Block"}.BeginList(0) +} +func (na *_Block__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{"chaintypes.Block"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_Block__Assembler) AssignBool(bool) error { + return mixins.MapAssembler{"chaintypes.Block"}.AssignBool(false) +} +func (_Block__Assembler) AssignInt(int) error { + return mixins.MapAssembler{"chaintypes.Block"}.AssignInt(0) +} +func (_Block__Assembler) AssignFloat(float64) error { + return mixins.MapAssembler{"chaintypes.Block"}.AssignFloat(0) +} +func (_Block__Assembler) AssignString(string) error { + return mixins.MapAssembler{"chaintypes.Block"}.AssignString("") +} +func (_Block__Assembler) AssignBytes([]byte) error { + return mixins.MapAssembler{"chaintypes.Block"}.AssignBytes(nil) +} +func (_Block__Assembler) AssignLink(ipld.Link) error { + return mixins.MapAssembler{"chaintypes.Block"}.AssignLink(nil) +} +func (na *_Block__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_Block); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.ReprKind() != ipld.ReprKind_Map { + return ipld.ErrWrongKind{TypeName: "chaintypes.Block", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: v.ReprKind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_Block__Assembler) Prototype() ipld.NodePrototype { + return _Block__Prototype{} +} +func (ma *_Block__Assembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.cm { + case schema.Maybe_Value: + ma.ca_Parents.w = nil + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.cm { + case schema.Maybe_Value: + ma.ca_Messages.w = nil + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_Block__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "Parents": + if ma.s&fieldBit__Block_Parents != 0 { + return nil, ipld.ErrRepeatedMapKey{&fieldName__Block_Parents} + } + ma.s += fieldBit__Block_Parents + ma.state = maState_midValue + ma.f = 0 + ma.ca_Parents.w = &ma.w.Parents + ma.ca_Parents.m = &ma.cm + return &ma.ca_Parents, nil + case "Messages": + if ma.s&fieldBit__Block_Messages != 0 { + return nil, ipld.ErrRepeatedMapKey{&fieldName__Block_Messages} + } + ma.s += fieldBit__Block_Messages + ma.state = maState_midValue + ma.f = 1 + ma.ca_Messages.w = &ma.w.Messages + ma.ca_Messages.m = &ma.cm + return &ma.ca_Messages, nil + default: + return nil, ipld.ErrInvalidKey{TypeName: "chaintypes.Block", Key: &_String{k}} + } +} +func (ma *_Block__Assembler) AssembleKey() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_Block__KeyAssembler)(ma) +} +func (ma *_Block__Assembler) AssembleValue() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_Parents.w = &ma.w.Parents + ma.ca_Parents.m = &ma.cm + return &ma.ca_Parents + case 1: + ma.ca_Messages.w = &ma.w.Messages + ma.ca_Messages.m = &ma.cm + return &ma.ca_Messages + default: + panic("unreachable") + } +} +func (ma *_Block__Assembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + //FIXME check if all required fields are set + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_Block__Assembler) KeyPrototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (ma *_Block__Assembler) ValuePrototype(k string) ipld.NodePrototype { + panic("todo structbuilder mapassembler valueprototype") +} + +type _Block__KeyAssembler _Block__Assembler + +func (_Block__KeyAssembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) { + return mixins.StringAssembler{"chaintypes.Block.KeyAssembler"}.BeginMap(0) +} +func (_Block__KeyAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) { + return mixins.StringAssembler{"chaintypes.Block.KeyAssembler"}.BeginList(0) +} +func (na *_Block__KeyAssembler) AssignNull() error { + return mixins.StringAssembler{"chaintypes.Block.KeyAssembler"}.AssignNull() +} +func (_Block__KeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{"chaintypes.Block.KeyAssembler"}.AssignBool(false) +} +func (_Block__KeyAssembler) AssignInt(int) error { + return mixins.StringAssembler{"chaintypes.Block.KeyAssembler"}.AssignInt(0) +} +func (_Block__KeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{"chaintypes.Block.KeyAssembler"}.AssignFloat(0) +} +func (ka *_Block__KeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "Parents": + if ka.s&fieldBit__Block_Parents != 0 { + return ipld.ErrRepeatedMapKey{&fieldName__Block_Parents} + } + ka.s += fieldBit__Block_Parents + ka.state = maState_expectValue + ka.f = 0 + case "Messages": + if ka.s&fieldBit__Block_Messages != 0 { + return ipld.ErrRepeatedMapKey{&fieldName__Block_Messages} + } + ka.s += fieldBit__Block_Messages + ka.state = maState_expectValue + ka.f = 1 + default: + return ipld.ErrInvalidKey{TypeName: "chaintypes.Block", Key: &_String{k}} + } + return nil +} +func (_Block__KeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{"chaintypes.Block.KeyAssembler"}.AssignBytes(nil) +} +func (_Block__KeyAssembler) AssignLink(ipld.Link) error { + return mixins.StringAssembler{"chaintypes.Block.KeyAssembler"}.AssignLink(nil) +} +func (ka *_Block__KeyAssembler) AssignNode(v ipld.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_Block__KeyAssembler) Prototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (Block) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n Block) Representation() ipld.Node { + return (*_Block__Repr)(n) +} + +type _Block__Repr _Block + +var ( + fieldName__Block_Parents_serial = _String{"Parents"} + fieldName__Block_Messages_serial = _String{"Messages"} +) +var _ ipld.Node = &_Block__Repr{} + +func (_Block__Repr) ReprKind() ipld.ReprKind { + return ipld.ReprKind_Map +} +func (n *_Block__Repr) LookupByString(key string) (ipld.Node, error) { + switch key { + case "Parents": + return n.Parents.Representation(), nil + case "Messages": + return n.Messages.Representation(), nil + default: + return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)} + } +} +func (n *_Block__Repr) LookupByNode(key ipld.Node) (ipld.Node, error) { + ks, err := key.AsString() + if err != nil { + return nil, err + } + return n.LookupByString(ks) +} +func (_Block__Repr) LookupByIndex(idx int) (ipld.Node, error) { + return mixins.Map{"chaintypes.Block.Repr"}.LookupByIndex(0) +} +func (n _Block__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return n.LookupByString(seg.String()) +} +func (n *_Block__Repr) MapIterator() ipld.MapIterator { + return &_Block__ReprMapItr{n, 0} +} + +type _Block__ReprMapItr struct { + n *_Block__Repr + idx int +} + +func (itr *_Block__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) { + if itr.idx >= 2 { + return nil, nil, ipld.ErrIteratorOverread{} + } + switch itr.idx { + case 0: + k = &fieldName__Block_Parents_serial + v = itr.n.Parents.Representation() + case 1: + k = &fieldName__Block_Messages_serial + v = itr.n.Messages.Representation() + default: + panic("unreachable") + } + itr.idx++ + return +} +func (itr *_Block__ReprMapItr) Done() bool { + return itr.idx >= 2 +} +func (_Block__Repr) ListIterator() ipld.ListIterator { + return nil +} +func (rn *_Block__Repr) Length() int { + l := 2 + return l +} +func (_Block__Repr) IsAbsent() bool { + return false +} +func (_Block__Repr) IsNull() bool { + return false +} +func (_Block__Repr) AsBool() (bool, error) { + return mixins.Map{"chaintypes.Block.Repr"}.AsBool() +} +func (_Block__Repr) AsInt() (int, error) { + return mixins.Map{"chaintypes.Block.Repr"}.AsInt() +} +func (_Block__Repr) AsFloat() (float64, error) { + return mixins.Map{"chaintypes.Block.Repr"}.AsFloat() +} +func (_Block__Repr) AsString() (string, error) { + return mixins.Map{"chaintypes.Block.Repr"}.AsString() +} +func (_Block__Repr) AsBytes() ([]byte, error) { + return mixins.Map{"chaintypes.Block.Repr"}.AsBytes() +} +func (_Block__Repr) AsLink() (ipld.Link, error) { + return mixins.Map{"chaintypes.Block.Repr"}.AsLink() +} +func (_Block__Repr) Prototype() ipld.NodePrototype { + return _Block__ReprPrototype{} +} + +type _Block__ReprPrototype struct{} + +func (_Block__ReprPrototype) NewBuilder() ipld.NodeBuilder { + var nb _Block__ReprBuilder + nb.Reset() + return &nb +} + +type _Block__ReprBuilder struct { + _Block__ReprAssembler +} + +func (nb *_Block__ReprBuilder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_Block__ReprBuilder) Reset() { + var w _Block + var m schema.Maybe + *nb = _Block__ReprBuilder{_Block__ReprAssembler{w: &w, m: &m}} +} + +type _Block__ReprAssembler struct { + w *_Block + m *schema.Maybe + state maState + s int + f int + + cm schema.Maybe + ca_Parents _Parents__ReprAssembler + ca_Messages _Messages__ReprAssembler +} + +func (na *_Block__ReprAssembler) reset() { + na.state = maState_initial + na.s = 0 + na.ca_Parents.reset() + na.ca_Messages.reset() +} +func (na *_Block__ReprAssembler) BeginMap(int) (ipld.MapAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if na.w == nil { + na.w = &_Block{} + } + return na, nil +} +func (_Block__ReprAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) { + return mixins.MapAssembler{"chaintypes.Block.Repr"}.BeginList(0) +} +func (na *_Block__ReprAssembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.MapAssembler{"chaintypes.Block.Repr.Repr"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_Block__ReprAssembler) AssignBool(bool) error { + return mixins.MapAssembler{"chaintypes.Block.Repr"}.AssignBool(false) +} +func (_Block__ReprAssembler) AssignInt(int) error { + return mixins.MapAssembler{"chaintypes.Block.Repr"}.AssignInt(0) +} +func (_Block__ReprAssembler) AssignFloat(float64) error { + return mixins.MapAssembler{"chaintypes.Block.Repr"}.AssignFloat(0) +} +func (_Block__ReprAssembler) AssignString(string) error { + return mixins.MapAssembler{"chaintypes.Block.Repr"}.AssignString("") +} +func (_Block__ReprAssembler) AssignBytes([]byte) error { + return mixins.MapAssembler{"chaintypes.Block.Repr"}.AssignBytes(nil) +} +func (_Block__ReprAssembler) AssignLink(ipld.Link) error { + return mixins.MapAssembler{"chaintypes.Block.Repr"}.AssignLink(nil) +} +func (na *_Block__ReprAssembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_Block); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.ReprKind() != ipld.ReprKind_Map { + return ipld.ErrWrongKind{TypeName: "chaintypes.Block.Repr", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: v.ReprKind()} + } + itr := v.MapIterator() + for !itr.Done() { + k, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleKey().AssignNode(k); err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_Block__ReprAssembler) Prototype() ipld.NodePrototype { + return _Block__ReprPrototype{} +} +func (ma *_Block__ReprAssembler) valueFinishTidy() bool { + switch ma.f { + case 0: + switch ma.cm { + case schema.Maybe_Value: + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } + case 1: + switch ma.cm { + case schema.Maybe_Value: + ma.cm = schema.Maybe_Absent + ma.state = maState_initial + return true + default: + return false + } + default: + panic("unreachable") + } +} +func (ma *_Block__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, error) { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleEntry cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleEntry cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished") + } + switch k { + case "Parents": + if ma.s&fieldBit__Block_Parents != 0 { + return nil, ipld.ErrRepeatedMapKey{&fieldName__Block_Parents_serial} + } + ma.s += fieldBit__Block_Parents + ma.state = maState_midValue + ma.ca_Parents.w = &ma.w.Parents + ma.ca_Parents.m = &ma.cm + return &ma.ca_Parents, nil + case "Messages": + if ma.s&fieldBit__Block_Messages != 0 { + return nil, ipld.ErrRepeatedMapKey{&fieldName__Block_Messages_serial} + } + ma.s += fieldBit__Block_Messages + ma.state = maState_midValue + ma.ca_Messages.w = &ma.w.Messages + ma.ca_Messages.m = &ma.cm + return &ma.ca_Messages, nil + default: + return nil, ipld.ErrInvalidKey{TypeName: "chaintypes.Block.Repr", Key: &_String{k}} + } +} +func (ma *_Block__ReprAssembler) AssembleKey() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: AssembleKey cannot be called when in the middle of assembling another key") + case maState_expectValue: + panic("invalid state: AssembleKey cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: AssembleKey cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: AssembleKey cannot be called on an assembler that's already finished") + } + ma.state = maState_midKey + return (*_Block__ReprKeyAssembler)(ma) +} +func (ma *_Block__ReprAssembler) AssembleValue() ipld.NodeAssembler { + switch ma.state { + case maState_initial: + panic("invalid state: AssembleValue cannot be called when no key is primed") + case maState_midKey: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key") + case maState_expectValue: + // carry on + case maState_midValue: + panic("invalid state: AssembleValue cannot be called when in the middle of assembling another value") + case maState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + ma.state = maState_midValue + switch ma.f { + case 0: + ma.ca_Parents.w = &ma.w.Parents + ma.ca_Parents.m = &ma.cm + return &ma.ca_Parents + case 1: + ma.ca_Messages.w = &ma.w.Messages + ma.ca_Messages.m = &ma.cm + return &ma.ca_Messages + default: + panic("unreachable") + } +} +func (ma *_Block__ReprAssembler) Finish() error { + switch ma.state { + case maState_initial: + // carry on + case maState_midKey: + panic("invalid state: Finish cannot be called when in the middle of assembling a key") + case maState_expectValue: + panic("invalid state: Finish cannot be called when expecting start of value assembly") + case maState_midValue: + if !ma.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case maState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + //FIXME check if all required fields are set + ma.state = maState_finished + *ma.m = schema.Maybe_Value + return nil +} +func (ma *_Block__ReprAssembler) KeyPrototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (ma *_Block__ReprAssembler) ValuePrototype(k string) ipld.NodePrototype { + panic("todo structbuilder mapassembler repr valueprototype") +} + +type _Block__ReprKeyAssembler _Block__ReprAssembler + +func (_Block__ReprKeyAssembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) { + return mixins.StringAssembler{"chaintypes.Block.Repr.KeyAssembler"}.BeginMap(0) +} +func (_Block__ReprKeyAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) { + return mixins.StringAssembler{"chaintypes.Block.Repr.KeyAssembler"}.BeginList(0) +} +func (na *_Block__ReprKeyAssembler) AssignNull() error { + return mixins.StringAssembler{"chaintypes.Block.Repr.KeyAssembler"}.AssignNull() +} +func (_Block__ReprKeyAssembler) AssignBool(bool) error { + return mixins.StringAssembler{"chaintypes.Block.Repr.KeyAssembler"}.AssignBool(false) +} +func (_Block__ReprKeyAssembler) AssignInt(int) error { + return mixins.StringAssembler{"chaintypes.Block.Repr.KeyAssembler"}.AssignInt(0) +} +func (_Block__ReprKeyAssembler) AssignFloat(float64) error { + return mixins.StringAssembler{"chaintypes.Block.Repr.KeyAssembler"}.AssignFloat(0) +} +func (ka *_Block__ReprKeyAssembler) AssignString(k string) error { + if ka.state != maState_midKey { + panic("misuse: KeyAssembler held beyond its valid lifetime") + } + switch k { + case "Parents": + if ka.s&fieldBit__Block_Parents != 0 { + return ipld.ErrRepeatedMapKey{&fieldName__Block_Parents_serial} + } + ka.s += fieldBit__Block_Parents + ka.state = maState_expectValue + ka.f = 0 + case "Messages": + if ka.s&fieldBit__Block_Messages != 0 { + return ipld.ErrRepeatedMapKey{&fieldName__Block_Messages_serial} + } + ka.s += fieldBit__Block_Messages + ka.state = maState_expectValue + ka.f = 1 + default: + return ipld.ErrInvalidKey{TypeName: "chaintypes.Block.Repr", Key: &_String{k}} + } + return nil +} +func (_Block__ReprKeyAssembler) AssignBytes([]byte) error { + return mixins.StringAssembler{"chaintypes.Block.Repr.KeyAssembler"}.AssignBytes(nil) +} +func (_Block__ReprKeyAssembler) AssignLink(ipld.Link) error { + return mixins.StringAssembler{"chaintypes.Block.Repr.KeyAssembler"}.AssignLink(nil) +} +func (ka *_Block__ReprKeyAssembler) AssignNode(v ipld.Node) error { + if v2, err := v.AsString(); err != nil { + return err + } else { + return ka.AssignString(v2) + } +} +func (_Block__ReprKeyAssembler) Prototype() ipld.NodePrototype { + return _String__Prototype{} +} diff --git a/testutil/chaintypes/tBytes.go b/testutil/chaintypes/tBytes.go new file mode 100644 index 00000000..68c7b4d1 --- /dev/null +++ b/testutil/chaintypes/tBytes.go @@ -0,0 +1,225 @@ +package chaintypes + +// Code generated by go-ipld-prime gengo. DO NOT EDIT. + +import ( + ipld "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/node/mixins" + "github.com/ipld/go-ipld-prime/schema" +) + +type _Bytes struct{ x []byte } +type Bytes = *_Bytes + +func (n Bytes) Bytes() []byte { + return n.x +} +func (_Bytes__Prototype) FromBytes(v []byte) (Bytes, error) { + n := _Bytes{v} + return &n, nil +} + +type _Bytes__Maybe struct { + m schema.Maybe + v Bytes +} +type MaybeBytes = *_Bytes__Maybe + +func (m MaybeBytes) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeBytes) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeBytes) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeBytes) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeBytes) Must() Bytes { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var _ ipld.Node = (Bytes)(&_Bytes{}) +var _ schema.TypedNode = (Bytes)(&_Bytes{}) + +func (Bytes) ReprKind() ipld.ReprKind { + return ipld.ReprKind_Bytes +} +func (Bytes) LookupByString(string) (ipld.Node, error) { + return mixins.Bytes{"chaintypes.Bytes"}.LookupByString("") +} +func (Bytes) LookupByNode(ipld.Node) (ipld.Node, error) { + return mixins.Bytes{"chaintypes.Bytes"}.LookupByNode(nil) +} +func (Bytes) LookupByIndex(idx int) (ipld.Node, error) { + return mixins.Bytes{"chaintypes.Bytes"}.LookupByIndex(0) +} +func (Bytes) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return mixins.Bytes{"chaintypes.Bytes"}.LookupBySegment(seg) +} +func (Bytes) MapIterator() ipld.MapIterator { + return nil +} +func (Bytes) ListIterator() ipld.ListIterator { + return nil +} +func (Bytes) Length() int { + return -1 +} +func (Bytes) IsAbsent() bool { + return false +} +func (Bytes) IsNull() bool { + return false +} +func (Bytes) AsBool() (bool, error) { + return mixins.Bytes{"chaintypes.Bytes"}.AsBool() +} +func (Bytes) AsInt() (int, error) { + return mixins.Bytes{"chaintypes.Bytes"}.AsInt() +} +func (Bytes) AsFloat() (float64, error) { + return mixins.Bytes{"chaintypes.Bytes"}.AsFloat() +} +func (Bytes) AsString() (string, error) { + return mixins.Bytes{"chaintypes.Bytes"}.AsString() +} +func (n Bytes) AsBytes() ([]byte, error) { + return n.x, nil +} +func (Bytes) AsLink() (ipld.Link, error) { + return mixins.Bytes{"chaintypes.Bytes"}.AsLink() +} +func (Bytes) Prototype() ipld.NodePrototype { + return _Bytes__Prototype{} +} + +type _Bytes__Prototype struct{} + +func (_Bytes__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _Bytes__Builder + nb.Reset() + return &nb +} + +type _Bytes__Builder struct { + _Bytes__Assembler +} + +func (nb *_Bytes__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_Bytes__Builder) Reset() { + var w _Bytes + var m schema.Maybe + *nb = _Bytes__Builder{_Bytes__Assembler{w: &w, m: &m}} +} + +type _Bytes__Assembler struct { + w *_Bytes + m *schema.Maybe +} + +func (na *_Bytes__Assembler) reset() {} +func (_Bytes__Assembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) { + return mixins.BytesAssembler{"chaintypes.Bytes"}.BeginMap(0) +} +func (_Bytes__Assembler) BeginList(sizeHint int) (ipld.ListAssembler, error) { + return mixins.BytesAssembler{"chaintypes.Bytes"}.BeginList(0) +} +func (na *_Bytes__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.BytesAssembler{"chaintypes.Bytes"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + panic("unreachable") +} +func (_Bytes__Assembler) AssignBool(bool) error { + return mixins.BytesAssembler{"chaintypes.Bytes"}.AssignBool(false) +} +func (_Bytes__Assembler) AssignInt(int) error { + return mixins.BytesAssembler{"chaintypes.Bytes"}.AssignInt(0) +} +func (_Bytes__Assembler) AssignFloat(float64) error { + return mixins.BytesAssembler{"chaintypes.Bytes"}.AssignFloat(0) +} +func (_Bytes__Assembler) AssignString(string) error { + return mixins.BytesAssembler{"chaintypes.Bytes"}.AssignString("") +} +func (na *_Bytes__Assembler) AssignBytes(v []byte) error { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if na.w == nil { + na.w = &_Bytes{} + } + na.w.x = v + *na.m = schema.Maybe_Value + return nil +} +func (_Bytes__Assembler) AssignLink(ipld.Link) error { + return mixins.BytesAssembler{"chaintypes.Bytes"}.AssignLink(nil) +} +func (na *_Bytes__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_Bytes); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v2, err := v.AsBytes(); err != nil { + return err + } else { + return na.AssignBytes(v2) + } +} +func (_Bytes__Assembler) Prototype() ipld.NodePrototype { + return _Bytes__Prototype{} +} +func (Bytes) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n Bytes) Representation() ipld.Node { + return (*_Bytes__Repr)(n) +} + +type _Bytes__Repr = _Bytes + +var _ ipld.Node = &_Bytes__Repr{} + +type _Bytes__ReprPrototype = _Bytes__Prototype +type _Bytes__ReprAssembler = _Bytes__Assembler diff --git a/testutil/chaintypes/tLink.go b/testutil/chaintypes/tLink.go new file mode 100644 index 00000000..132bc868 --- /dev/null +++ b/testutil/chaintypes/tLink.go @@ -0,0 +1,225 @@ +package chaintypes + +// Code generated by go-ipld-prime gengo. DO NOT EDIT. + +import ( + ipld "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/node/mixins" + "github.com/ipld/go-ipld-prime/schema" +) + +type _Link struct{ x ipld.Link } +type Link = *_Link + +func (n Link) Link() ipld.Link { + return n.x +} +func (_Link__Prototype) FromLink(v ipld.Link) (Link, error) { + n := _Link{v} + return &n, nil +} + +type _Link__Maybe struct { + m schema.Maybe + v Link +} +type MaybeLink = *_Link__Maybe + +func (m MaybeLink) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeLink) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeLink) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeLink) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeLink) Must() Link { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var _ ipld.Node = (Link)(&_Link{}) +var _ schema.TypedNode = (Link)(&_Link{}) + +func (Link) ReprKind() ipld.ReprKind { + return ipld.ReprKind_Link +} +func (Link) LookupByString(string) (ipld.Node, error) { + return mixins.Link{"chaintypes.Link"}.LookupByString("") +} +func (Link) LookupByNode(ipld.Node) (ipld.Node, error) { + return mixins.Link{"chaintypes.Link"}.LookupByNode(nil) +} +func (Link) LookupByIndex(idx int) (ipld.Node, error) { + return mixins.Link{"chaintypes.Link"}.LookupByIndex(0) +} +func (Link) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return mixins.Link{"chaintypes.Link"}.LookupBySegment(seg) +} +func (Link) MapIterator() ipld.MapIterator { + return nil +} +func (Link) ListIterator() ipld.ListIterator { + return nil +} +func (Link) Length() int { + return -1 +} +func (Link) IsAbsent() bool { + return false +} +func (Link) IsNull() bool { + return false +} +func (Link) AsBool() (bool, error) { + return mixins.Link{"chaintypes.Link"}.AsBool() +} +func (Link) AsInt() (int, error) { + return mixins.Link{"chaintypes.Link"}.AsInt() +} +func (Link) AsFloat() (float64, error) { + return mixins.Link{"chaintypes.Link"}.AsFloat() +} +func (Link) AsString() (string, error) { + return mixins.Link{"chaintypes.Link"}.AsString() +} +func (Link) AsBytes() ([]byte, error) { + return mixins.Link{"chaintypes.Link"}.AsBytes() +} +func (n Link) AsLink() (ipld.Link, error) { + return n.x, nil +} +func (Link) Prototype() ipld.NodePrototype { + return _Link__Prototype{} +} + +type _Link__Prototype struct{} + +func (_Link__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _Link__Builder + nb.Reset() + return &nb +} + +type _Link__Builder struct { + _Link__Assembler +} + +func (nb *_Link__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_Link__Builder) Reset() { + var w _Link + var m schema.Maybe + *nb = _Link__Builder{_Link__Assembler{w: &w, m: &m}} +} + +type _Link__Assembler struct { + w *_Link + m *schema.Maybe +} + +func (na *_Link__Assembler) reset() {} +func (_Link__Assembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) { + return mixins.LinkAssembler{"chaintypes.Link"}.BeginMap(0) +} +func (_Link__Assembler) BeginList(sizeHint int) (ipld.ListAssembler, error) { + return mixins.LinkAssembler{"chaintypes.Link"}.BeginList(0) +} +func (na *_Link__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.LinkAssembler{"chaintypes.Link"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + panic("unreachable") +} +func (_Link__Assembler) AssignBool(bool) error { + return mixins.LinkAssembler{"chaintypes.Link"}.AssignBool(false) +} +func (_Link__Assembler) AssignInt(int) error { + return mixins.LinkAssembler{"chaintypes.Link"}.AssignInt(0) +} +func (_Link__Assembler) AssignFloat(float64) error { + return mixins.LinkAssembler{"chaintypes.Link"}.AssignFloat(0) +} +func (_Link__Assembler) AssignString(string) error { + return mixins.LinkAssembler{"chaintypes.Link"}.AssignString("") +} +func (_Link__Assembler) AssignBytes([]byte) error { + return mixins.LinkAssembler{"chaintypes.Link"}.AssignBytes(nil) +} +func (na *_Link__Assembler) AssignLink(v ipld.Link) error { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if na.w == nil { + na.w = &_Link{} + } + na.w.x = v + *na.m = schema.Maybe_Value + return nil +} +func (na *_Link__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_Link); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v2, err := v.AsLink(); err != nil { + return err + } else { + return na.AssignLink(v2) + } +} +func (_Link__Assembler) Prototype() ipld.NodePrototype { + return _Link__Prototype{} +} +func (Link) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n Link) Representation() ipld.Node { + return (*_Link__Repr)(n) +} + +type _Link__Repr = _Link + +var _ ipld.Node = &_Link__Repr{} + +type _Link__ReprPrototype = _Link__Prototype +type _Link__ReprAssembler = _Link__Assembler diff --git a/testutil/chaintypes/tMessages.go b/testutil/chaintypes/tMessages.go new file mode 100644 index 00000000..b5908787 --- /dev/null +++ b/testutil/chaintypes/tMessages.go @@ -0,0 +1,578 @@ +package chaintypes + +// Code generated by go-ipld-prime gengo. DO NOT EDIT. + +import ( + ipld "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/node/mixins" + "github.com/ipld/go-ipld-prime/schema" +) + +type _Messages struct { + x []_Bytes +} +type Messages = *_Messages +type _Messages__Maybe struct { + m schema.Maybe + v Messages +} +type MaybeMessages = *_Messages__Maybe + +func (m MaybeMessages) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeMessages) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeMessages) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeMessages) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeMessages) Must() Messages { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var _ ipld.Node = (Messages)(&_Messages{}) +var _ schema.TypedNode = (Messages)(&_Messages{}) + +func (Messages) ReprKind() ipld.ReprKind { + return ipld.ReprKind_List +} +func (Messages) LookupByString(string) (ipld.Node, error) { + return mixins.List{"chaintypes.Messages"}.LookupByString("") +} +func (n Messages) LookupByNode(k ipld.Node) (ipld.Node, error) { + idx, err := k.AsInt() + if err != nil { + return nil, err + } + return n.LookupByIndex(idx) +} +func (n Messages) LookupByIndex(idx int) (ipld.Node, error) { + if n.Length() <= idx { + return nil, ipld.ErrNotExists{ipld.PathSegmentOfInt(idx)} + } + v := &n.x[idx] + return v, nil +} +func (n Messages) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, ipld.ErrInvalidSegmentForList{TypeName: "chaintypes.Messages", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) +} +func (Messages) MapIterator() ipld.MapIterator { + return nil +} +func (n Messages) ListIterator() ipld.ListIterator { + return &_Messages__ListItr{n, 0} +} + +type _Messages__ListItr struct { + n Messages + idx int +} + +func (itr *_Messages__ListItr) Next() (idx int, v ipld.Node, _ error) { + if itr.idx >= len(itr.n.x) { + return -1, nil, ipld.ErrIteratorOverread{} + } + idx = itr.idx + x := &itr.n.x[itr.idx] + v = x + itr.idx++ + return +} +func (itr *_Messages__ListItr) Done() bool { + return itr.idx >= len(itr.n.x) +} + +func (n Messages) Length() int { + return len(n.x) +} +func (Messages) IsAbsent() bool { + return false +} +func (Messages) IsNull() bool { + return false +} +func (Messages) AsBool() (bool, error) { + return mixins.List{"chaintypes.Messages"}.AsBool() +} +func (Messages) AsInt() (int, error) { + return mixins.List{"chaintypes.Messages"}.AsInt() +} +func (Messages) AsFloat() (float64, error) { + return mixins.List{"chaintypes.Messages"}.AsFloat() +} +func (Messages) AsString() (string, error) { + return mixins.List{"chaintypes.Messages"}.AsString() +} +func (Messages) AsBytes() ([]byte, error) { + return mixins.List{"chaintypes.Messages"}.AsBytes() +} +func (Messages) AsLink() (ipld.Link, error) { + return mixins.List{"chaintypes.Messages"}.AsLink() +} +func (Messages) Prototype() ipld.NodePrototype { + return _Messages__Prototype{} +} + +type _Messages__Prototype struct{} + +func (_Messages__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _Messages__Builder + nb.Reset() + return &nb +} + +type _Messages__Builder struct { + _Messages__Assembler +} + +func (nb *_Messages__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_Messages__Builder) Reset() { + var w _Messages + var m schema.Maybe + *nb = _Messages__Builder{_Messages__Assembler{w: &w, m: &m}} +} + +type _Messages__Assembler struct { + w *_Messages + m *schema.Maybe + state laState + + cm schema.Maybe + va _Bytes__Assembler +} + +func (na *_Messages__Assembler) reset() { + na.state = laState_initial + na.va.reset() +} +func (_Messages__Assembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) { + return mixins.ListAssembler{"chaintypes.Messages"}.BeginMap(0) +} +func (na *_Messages__Assembler) BeginList(sizeHint int) (ipld.ListAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if sizeHint < 0 { + sizeHint = 0 + } + if na.w == nil { + na.w = &_Messages{} + } + if sizeHint > 0 { + na.w.x = make([]_Bytes, 0, sizeHint) + } + return na, nil +} +func (na *_Messages__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.ListAssembler{"chaintypes.Messages"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_Messages__Assembler) AssignBool(bool) error { + return mixins.ListAssembler{"chaintypes.Messages"}.AssignBool(false) +} +func (_Messages__Assembler) AssignInt(int) error { + return mixins.ListAssembler{"chaintypes.Messages"}.AssignInt(0) +} +func (_Messages__Assembler) AssignFloat(float64) error { + return mixins.ListAssembler{"chaintypes.Messages"}.AssignFloat(0) +} +func (_Messages__Assembler) AssignString(string) error { + return mixins.ListAssembler{"chaintypes.Messages"}.AssignString("") +} +func (_Messages__Assembler) AssignBytes([]byte) error { + return mixins.ListAssembler{"chaintypes.Messages"}.AssignBytes(nil) +} +func (_Messages__Assembler) AssignLink(ipld.Link) error { + return mixins.ListAssembler{"chaintypes.Messages"}.AssignLink(nil) +} +func (na *_Messages__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_Messages); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.ReprKind() != ipld.ReprKind_List { + return ipld.ErrWrongKind{TypeName: "chaintypes.Messages", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: v.ReprKind()} + } + itr := v.ListIterator() + for !itr.Done() { + _, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_Messages__Assembler) Prototype() ipld.NodePrototype { + return _Messages__Prototype{} +} +func (la *_Messages__Assembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true + default: + return false + } +} +func (la *_Messages__Assembler) AssembleValue() ipld.NodeAssembler { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + la.w.x = append(la.w.x, _Bytes{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va +} +func (la *_Messages__Assembler) Finish() error { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil +} +func (la *_Messages__Assembler) ValuePrototype(_ int) ipld.NodePrototype { + return _Bytes__Prototype{} +} +func (Messages) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n Messages) Representation() ipld.Node { + return (*_Messages__Repr)(n) +} + +type _Messages__Repr _Messages + +var _ ipld.Node = &_Messages__Repr{} + +func (_Messages__Repr) ReprKind() ipld.ReprKind { + return ipld.ReprKind_List +} +func (_Messages__Repr) LookupByString(string) (ipld.Node, error) { + return mixins.List{"chaintypes.Messages.Repr"}.LookupByString("") +} +func (nr *_Messages__Repr) LookupByNode(k ipld.Node) (ipld.Node, error) { + v, err := (Messages)(nr).LookupByNode(k) + if err != nil || v == ipld.Null { + return v, err + } + return v.(Bytes).Representation(), nil +} +func (nr *_Messages__Repr) LookupByIndex(idx int) (ipld.Node, error) { + v, err := (Messages)(nr).LookupByIndex(idx) + if err != nil || v == ipld.Null { + return v, err + } + return v.(Bytes).Representation(), nil +} +func (n _Messages__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, ipld.ErrInvalidSegmentForList{TypeName: "chaintypes.Messages.Repr", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) +} +func (_Messages__Repr) MapIterator() ipld.MapIterator { + return nil +} +func (nr *_Messages__Repr) ListIterator() ipld.ListIterator { + return &_Messages__ReprListItr{(Messages)(nr), 0} +} + +type _Messages__ReprListItr _Messages__ListItr + +func (itr *_Messages__ReprListItr) Next() (idx int, v ipld.Node, err error) { + idx, v, err = (*_Messages__ListItr)(itr).Next() + if err != nil || v == ipld.Null { + return + } + return idx, v.(Bytes).Representation(), nil +} +func (itr *_Messages__ReprListItr) Done() bool { + return (*_Messages__ListItr)(itr).Done() +} + +func (rn *_Messages__Repr) Length() int { + return len(rn.x) +} +func (_Messages__Repr) IsAbsent() bool { + return false +} +func (_Messages__Repr) IsNull() bool { + return false +} +func (_Messages__Repr) AsBool() (bool, error) { + return mixins.List{"chaintypes.Messages.Repr"}.AsBool() +} +func (_Messages__Repr) AsInt() (int, error) { + return mixins.List{"chaintypes.Messages.Repr"}.AsInt() +} +func (_Messages__Repr) AsFloat() (float64, error) { + return mixins.List{"chaintypes.Messages.Repr"}.AsFloat() +} +func (_Messages__Repr) AsString() (string, error) { + return mixins.List{"chaintypes.Messages.Repr"}.AsString() +} +func (_Messages__Repr) AsBytes() ([]byte, error) { + return mixins.List{"chaintypes.Messages.Repr"}.AsBytes() +} +func (_Messages__Repr) AsLink() (ipld.Link, error) { + return mixins.List{"chaintypes.Messages.Repr"}.AsLink() +} +func (_Messages__Repr) Prototype() ipld.NodePrototype { + return _Messages__ReprPrototype{} +} + +type _Messages__ReprPrototype struct{} + +func (_Messages__ReprPrototype) NewBuilder() ipld.NodeBuilder { + var nb _Messages__ReprBuilder + nb.Reset() + return &nb +} + +type _Messages__ReprBuilder struct { + _Messages__ReprAssembler +} + +func (nb *_Messages__ReprBuilder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_Messages__ReprBuilder) Reset() { + var w _Messages + var m schema.Maybe + *nb = _Messages__ReprBuilder{_Messages__ReprAssembler{w: &w, m: &m}} +} + +type _Messages__ReprAssembler struct { + w *_Messages + m *schema.Maybe + state laState + + cm schema.Maybe + va _Bytes__ReprAssembler +} + +func (na *_Messages__ReprAssembler) reset() { + na.state = laState_initial + na.va.reset() +} +func (_Messages__ReprAssembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) { + return mixins.ListAssembler{"chaintypes.Messages.Repr"}.BeginMap(0) +} +func (na *_Messages__ReprAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if sizeHint < 0 { + sizeHint = 0 + } + if na.w == nil { + na.w = &_Messages{} + } + if sizeHint > 0 { + na.w.x = make([]_Bytes, 0, sizeHint) + } + return na, nil +} +func (na *_Messages__ReprAssembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.ListAssembler{"chaintypes.Messages.Repr.Repr"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_Messages__ReprAssembler) AssignBool(bool) error { + return mixins.ListAssembler{"chaintypes.Messages.Repr"}.AssignBool(false) +} +func (_Messages__ReprAssembler) AssignInt(int) error { + return mixins.ListAssembler{"chaintypes.Messages.Repr"}.AssignInt(0) +} +func (_Messages__ReprAssembler) AssignFloat(float64) error { + return mixins.ListAssembler{"chaintypes.Messages.Repr"}.AssignFloat(0) +} +func (_Messages__ReprAssembler) AssignString(string) error { + return mixins.ListAssembler{"chaintypes.Messages.Repr"}.AssignString("") +} +func (_Messages__ReprAssembler) AssignBytes([]byte) error { + return mixins.ListAssembler{"chaintypes.Messages.Repr"}.AssignBytes(nil) +} +func (_Messages__ReprAssembler) AssignLink(ipld.Link) error { + return mixins.ListAssembler{"chaintypes.Messages.Repr"}.AssignLink(nil) +} +func (na *_Messages__ReprAssembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_Messages); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.ReprKind() != ipld.ReprKind_List { + return ipld.ErrWrongKind{TypeName: "chaintypes.Messages.Repr", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: v.ReprKind()} + } + itr := v.ListIterator() + for !itr.Done() { + _, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_Messages__ReprAssembler) Prototype() ipld.NodePrototype { + return _Messages__ReprPrototype{} +} +func (la *_Messages__ReprAssembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true + default: + return false + } +} +func (la *_Messages__ReprAssembler) AssembleValue() ipld.NodeAssembler { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + la.w.x = append(la.w.x, _Bytes{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va +} +func (la *_Messages__ReprAssembler) Finish() error { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil +} +func (la *_Messages__ReprAssembler) ValuePrototype(_ int) ipld.NodePrototype { + return _Bytes__ReprPrototype{} +} diff --git a/testutil/chaintypes/tParents.go b/testutil/chaintypes/tParents.go new file mode 100644 index 00000000..4f0109f1 --- /dev/null +++ b/testutil/chaintypes/tParents.go @@ -0,0 +1,578 @@ +package chaintypes + +// Code generated by go-ipld-prime gengo. DO NOT EDIT. + +import ( + ipld "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/node/mixins" + "github.com/ipld/go-ipld-prime/schema" +) + +type _Parents struct { + x []_Link +} +type Parents = *_Parents +type _Parents__Maybe struct { + m schema.Maybe + v Parents +} +type MaybeParents = *_Parents__Maybe + +func (m MaybeParents) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeParents) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeParents) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeParents) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeParents) Must() Parents { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var _ ipld.Node = (Parents)(&_Parents{}) +var _ schema.TypedNode = (Parents)(&_Parents{}) + +func (Parents) ReprKind() ipld.ReprKind { + return ipld.ReprKind_List +} +func (Parents) LookupByString(string) (ipld.Node, error) { + return mixins.List{"chaintypes.Parents"}.LookupByString("") +} +func (n Parents) LookupByNode(k ipld.Node) (ipld.Node, error) { + idx, err := k.AsInt() + if err != nil { + return nil, err + } + return n.LookupByIndex(idx) +} +func (n Parents) LookupByIndex(idx int) (ipld.Node, error) { + if n.Length() <= idx { + return nil, ipld.ErrNotExists{ipld.PathSegmentOfInt(idx)} + } + v := &n.x[idx] + return v, nil +} +func (n Parents) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, ipld.ErrInvalidSegmentForList{TypeName: "chaintypes.Parents", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) +} +func (Parents) MapIterator() ipld.MapIterator { + return nil +} +func (n Parents) ListIterator() ipld.ListIterator { + return &_Parents__ListItr{n, 0} +} + +type _Parents__ListItr struct { + n Parents + idx int +} + +func (itr *_Parents__ListItr) Next() (idx int, v ipld.Node, _ error) { + if itr.idx >= len(itr.n.x) { + return -1, nil, ipld.ErrIteratorOverread{} + } + idx = itr.idx + x := &itr.n.x[itr.idx] + v = x + itr.idx++ + return +} +func (itr *_Parents__ListItr) Done() bool { + return itr.idx >= len(itr.n.x) +} + +func (n Parents) Length() int { + return len(n.x) +} +func (Parents) IsAbsent() bool { + return false +} +func (Parents) IsNull() bool { + return false +} +func (Parents) AsBool() (bool, error) { + return mixins.List{"chaintypes.Parents"}.AsBool() +} +func (Parents) AsInt() (int, error) { + return mixins.List{"chaintypes.Parents"}.AsInt() +} +func (Parents) AsFloat() (float64, error) { + return mixins.List{"chaintypes.Parents"}.AsFloat() +} +func (Parents) AsString() (string, error) { + return mixins.List{"chaintypes.Parents"}.AsString() +} +func (Parents) AsBytes() ([]byte, error) { + return mixins.List{"chaintypes.Parents"}.AsBytes() +} +func (Parents) AsLink() (ipld.Link, error) { + return mixins.List{"chaintypes.Parents"}.AsLink() +} +func (Parents) Prototype() ipld.NodePrototype { + return _Parents__Prototype{} +} + +type _Parents__Prototype struct{} + +func (_Parents__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _Parents__Builder + nb.Reset() + return &nb +} + +type _Parents__Builder struct { + _Parents__Assembler +} + +func (nb *_Parents__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_Parents__Builder) Reset() { + var w _Parents + var m schema.Maybe + *nb = _Parents__Builder{_Parents__Assembler{w: &w, m: &m}} +} + +type _Parents__Assembler struct { + w *_Parents + m *schema.Maybe + state laState + + cm schema.Maybe + va _Link__Assembler +} + +func (na *_Parents__Assembler) reset() { + na.state = laState_initial + na.va.reset() +} +func (_Parents__Assembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) { + return mixins.ListAssembler{"chaintypes.Parents"}.BeginMap(0) +} +func (na *_Parents__Assembler) BeginList(sizeHint int) (ipld.ListAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if sizeHint < 0 { + sizeHint = 0 + } + if na.w == nil { + na.w = &_Parents{} + } + if sizeHint > 0 { + na.w.x = make([]_Link, 0, sizeHint) + } + return na, nil +} +func (na *_Parents__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.ListAssembler{"chaintypes.Parents"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_Parents__Assembler) AssignBool(bool) error { + return mixins.ListAssembler{"chaintypes.Parents"}.AssignBool(false) +} +func (_Parents__Assembler) AssignInt(int) error { + return mixins.ListAssembler{"chaintypes.Parents"}.AssignInt(0) +} +func (_Parents__Assembler) AssignFloat(float64) error { + return mixins.ListAssembler{"chaintypes.Parents"}.AssignFloat(0) +} +func (_Parents__Assembler) AssignString(string) error { + return mixins.ListAssembler{"chaintypes.Parents"}.AssignString("") +} +func (_Parents__Assembler) AssignBytes([]byte) error { + return mixins.ListAssembler{"chaintypes.Parents"}.AssignBytes(nil) +} +func (_Parents__Assembler) AssignLink(ipld.Link) error { + return mixins.ListAssembler{"chaintypes.Parents"}.AssignLink(nil) +} +func (na *_Parents__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_Parents); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.ReprKind() != ipld.ReprKind_List { + return ipld.ErrWrongKind{TypeName: "chaintypes.Parents", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: v.ReprKind()} + } + itr := v.ListIterator() + for !itr.Done() { + _, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_Parents__Assembler) Prototype() ipld.NodePrototype { + return _Parents__Prototype{} +} +func (la *_Parents__Assembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true + default: + return false + } +} +func (la *_Parents__Assembler) AssembleValue() ipld.NodeAssembler { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + la.w.x = append(la.w.x, _Link{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va +} +func (la *_Parents__Assembler) Finish() error { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil +} +func (la *_Parents__Assembler) ValuePrototype(_ int) ipld.NodePrototype { + return _Link__Prototype{} +} +func (Parents) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n Parents) Representation() ipld.Node { + return (*_Parents__Repr)(n) +} + +type _Parents__Repr _Parents + +var _ ipld.Node = &_Parents__Repr{} + +func (_Parents__Repr) ReprKind() ipld.ReprKind { + return ipld.ReprKind_List +} +func (_Parents__Repr) LookupByString(string) (ipld.Node, error) { + return mixins.List{"chaintypes.Parents.Repr"}.LookupByString("") +} +func (nr *_Parents__Repr) LookupByNode(k ipld.Node) (ipld.Node, error) { + v, err := (Parents)(nr).LookupByNode(k) + if err != nil || v == ipld.Null { + return v, err + } + return v.(Link).Representation(), nil +} +func (nr *_Parents__Repr) LookupByIndex(idx int) (ipld.Node, error) { + v, err := (Parents)(nr).LookupByIndex(idx) + if err != nil || v == ipld.Null { + return v, err + } + return v.(Link).Representation(), nil +} +func (n _Parents__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + i, err := seg.Index() + if err != nil { + return nil, ipld.ErrInvalidSegmentForList{TypeName: "chaintypes.Parents.Repr", TroubleSegment: seg, Reason: err} + } + return n.LookupByIndex(i) +} +func (_Parents__Repr) MapIterator() ipld.MapIterator { + return nil +} +func (nr *_Parents__Repr) ListIterator() ipld.ListIterator { + return &_Parents__ReprListItr{(Parents)(nr), 0} +} + +type _Parents__ReprListItr _Parents__ListItr + +func (itr *_Parents__ReprListItr) Next() (idx int, v ipld.Node, err error) { + idx, v, err = (*_Parents__ListItr)(itr).Next() + if err != nil || v == ipld.Null { + return + } + return idx, v.(Link).Representation(), nil +} +func (itr *_Parents__ReprListItr) Done() bool { + return (*_Parents__ListItr)(itr).Done() +} + +func (rn *_Parents__Repr) Length() int { + return len(rn.x) +} +func (_Parents__Repr) IsAbsent() bool { + return false +} +func (_Parents__Repr) IsNull() bool { + return false +} +func (_Parents__Repr) AsBool() (bool, error) { + return mixins.List{"chaintypes.Parents.Repr"}.AsBool() +} +func (_Parents__Repr) AsInt() (int, error) { + return mixins.List{"chaintypes.Parents.Repr"}.AsInt() +} +func (_Parents__Repr) AsFloat() (float64, error) { + return mixins.List{"chaintypes.Parents.Repr"}.AsFloat() +} +func (_Parents__Repr) AsString() (string, error) { + return mixins.List{"chaintypes.Parents.Repr"}.AsString() +} +func (_Parents__Repr) AsBytes() ([]byte, error) { + return mixins.List{"chaintypes.Parents.Repr"}.AsBytes() +} +func (_Parents__Repr) AsLink() (ipld.Link, error) { + return mixins.List{"chaintypes.Parents.Repr"}.AsLink() +} +func (_Parents__Repr) Prototype() ipld.NodePrototype { + return _Parents__ReprPrototype{} +} + +type _Parents__ReprPrototype struct{} + +func (_Parents__ReprPrototype) NewBuilder() ipld.NodeBuilder { + var nb _Parents__ReprBuilder + nb.Reset() + return &nb +} + +type _Parents__ReprBuilder struct { + _Parents__ReprAssembler +} + +func (nb *_Parents__ReprBuilder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_Parents__ReprBuilder) Reset() { + var w _Parents + var m schema.Maybe + *nb = _Parents__ReprBuilder{_Parents__ReprAssembler{w: &w, m: &m}} +} + +type _Parents__ReprAssembler struct { + w *_Parents + m *schema.Maybe + state laState + + cm schema.Maybe + va _Link__ReprAssembler +} + +func (na *_Parents__ReprAssembler) reset() { + na.state = laState_initial + na.va.reset() +} +func (_Parents__ReprAssembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) { + return mixins.ListAssembler{"chaintypes.Parents.Repr"}.BeginMap(0) +} +func (na *_Parents__ReprAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: it makes no sense to 'begin' twice on the same assembler!") + } + *na.m = midvalue + if sizeHint < 0 { + sizeHint = 0 + } + if na.w == nil { + na.w = &_Parents{} + } + if sizeHint > 0 { + na.w.x = make([]_Link, 0, sizeHint) + } + return na, nil +} +func (na *_Parents__ReprAssembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.ListAssembler{"chaintypes.Parents.Repr.Repr"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + panic("unreachable") +} +func (_Parents__ReprAssembler) AssignBool(bool) error { + return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignBool(false) +} +func (_Parents__ReprAssembler) AssignInt(int) error { + return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignInt(0) +} +func (_Parents__ReprAssembler) AssignFloat(float64) error { + return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignFloat(0) +} +func (_Parents__ReprAssembler) AssignString(string) error { + return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignString("") +} +func (_Parents__ReprAssembler) AssignBytes([]byte) error { + return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignBytes(nil) +} +func (_Parents__ReprAssembler) AssignLink(ipld.Link) error { + return mixins.ListAssembler{"chaintypes.Parents.Repr"}.AssignLink(nil) +} +func (na *_Parents__ReprAssembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_Parents); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + case midvalue: + panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v.ReprKind() != ipld.ReprKind_List { + return ipld.ErrWrongKind{TypeName: "chaintypes.Parents.Repr", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustList, ActualKind: v.ReprKind()} + } + itr := v.ListIterator() + for !itr.Done() { + _, v, err := itr.Next() + if err != nil { + return err + } + if err := na.AssembleValue().AssignNode(v); err != nil { + return err + } + } + return na.Finish() +} +func (_Parents__ReprAssembler) Prototype() ipld.NodePrototype { + return _Parents__ReprPrototype{} +} +func (la *_Parents__ReprAssembler) valueFinishTidy() bool { + switch la.cm { + case schema.Maybe_Value: + la.va.w = nil + la.cm = schema.Maybe_Absent + la.state = laState_initial + la.va.reset() + return true + default: + return false + } +} +func (la *_Parents__ReprAssembler) AssembleValue() ipld.NodeAssembler { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: AssembleValue cannot be called on an assembler that's already finished") + } + la.w.x = append(la.w.x, _Link{}) + la.state = laState_midValue + row := &la.w.x[len(la.w.x)-1] + la.va.w = row + la.va.m = &la.cm + return &la.va +} +func (la *_Parents__ReprAssembler) Finish() error { + switch la.state { + case laState_initial: + // carry on + case laState_midValue: + if !la.valueFinishTidy() { + panic("invalid state: Finish cannot be called when in the middle of assembling a value") + } // if tidy success: carry on + case laState_finished: + panic("invalid state: Finish cannot be called on an assembler that's already finished") + } + la.state = laState_finished + *la.m = schema.Maybe_Value + return nil +} +func (la *_Parents__ReprAssembler) ValuePrototype(_ int) ipld.NodePrototype { + return _Link__ReprPrototype{} +} diff --git a/testutil/chaintypes/tString.go b/testutil/chaintypes/tString.go new file mode 100644 index 00000000..f580e19e --- /dev/null +++ b/testutil/chaintypes/tString.go @@ -0,0 +1,229 @@ +package chaintypes + +// Code generated by go-ipld-prime gengo. DO NOT EDIT. + +import ( + ipld "github.com/ipld/go-ipld-prime" + "github.com/ipld/go-ipld-prime/node/mixins" + "github.com/ipld/go-ipld-prime/schema" +) + +type _String struct{ x string } +type String = *_String + +func (n String) String() string { + return n.x +} +func (_String__Prototype) fromString(w *_String, v string) error { + *w = _String{v} + return nil +} +func (_String__Prototype) FromString(v string) (String, error) { + n := _String{v} + return &n, nil +} + +type _String__Maybe struct { + m schema.Maybe + v String +} +type MaybeString = *_String__Maybe + +func (m MaybeString) IsNull() bool { + return m.m == schema.Maybe_Null +} +func (m MaybeString) IsAbsent() bool { + return m.m == schema.Maybe_Absent +} +func (m MaybeString) Exists() bool { + return m.m == schema.Maybe_Value +} +func (m MaybeString) AsNode() ipld.Node { + switch m.m { + case schema.Maybe_Absent: + return ipld.Absent + case schema.Maybe_Null: + return ipld.Null + case schema.Maybe_Value: + return m.v + default: + panic("unreachable") + } +} +func (m MaybeString) Must() String { + if !m.Exists() { + panic("unbox of a maybe rejected") + } + return m.v +} + +var _ ipld.Node = (String)(&_String{}) +var _ schema.TypedNode = (String)(&_String{}) + +func (String) ReprKind() ipld.ReprKind { + return ipld.ReprKind_String +} +func (String) LookupByString(string) (ipld.Node, error) { + return mixins.String{"chaintypes.String"}.LookupByString("") +} +func (String) LookupByNode(ipld.Node) (ipld.Node, error) { + return mixins.String{"chaintypes.String"}.LookupByNode(nil) +} +func (String) LookupByIndex(idx int) (ipld.Node, error) { + return mixins.String{"chaintypes.String"}.LookupByIndex(0) +} +func (String) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) { + return mixins.String{"chaintypes.String"}.LookupBySegment(seg) +} +func (String) MapIterator() ipld.MapIterator { + return nil +} +func (String) ListIterator() ipld.ListIterator { + return nil +} +func (String) Length() int { + return -1 +} +func (String) IsAbsent() bool { + return false +} +func (String) IsNull() bool { + return false +} +func (String) AsBool() (bool, error) { + return mixins.String{"chaintypes.String"}.AsBool() +} +func (String) AsInt() (int, error) { + return mixins.String{"chaintypes.String"}.AsInt() +} +func (String) AsFloat() (float64, error) { + return mixins.String{"chaintypes.String"}.AsFloat() +} +func (n String) AsString() (string, error) { + return n.x, nil +} +func (String) AsBytes() ([]byte, error) { + return mixins.String{"chaintypes.String"}.AsBytes() +} +func (String) AsLink() (ipld.Link, error) { + return mixins.String{"chaintypes.String"}.AsLink() +} +func (String) Prototype() ipld.NodePrototype { + return _String__Prototype{} +} + +type _String__Prototype struct{} + +func (_String__Prototype) NewBuilder() ipld.NodeBuilder { + var nb _String__Builder + nb.Reset() + return &nb +} + +type _String__Builder struct { + _String__Assembler +} + +func (nb *_String__Builder) Build() ipld.Node { + if *nb.m != schema.Maybe_Value { + panic("invalid state: cannot call Build on an assembler that's not finished") + } + return nb.w +} +func (nb *_String__Builder) Reset() { + var w _String + var m schema.Maybe + *nb = _String__Builder{_String__Assembler{w: &w, m: &m}} +} + +type _String__Assembler struct { + w *_String + m *schema.Maybe +} + +func (na *_String__Assembler) reset() {} +func (_String__Assembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) { + return mixins.StringAssembler{"chaintypes.String"}.BeginMap(0) +} +func (_String__Assembler) BeginList(sizeHint int) (ipld.ListAssembler, error) { + return mixins.StringAssembler{"chaintypes.String"}.BeginList(0) +} +func (na *_String__Assembler) AssignNull() error { + switch *na.m { + case allowNull: + *na.m = schema.Maybe_Null + return nil + case schema.Maybe_Absent: + return mixins.StringAssembler{"chaintypes.String"}.AssignNull() + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + panic("unreachable") +} +func (_String__Assembler) AssignBool(bool) error { + return mixins.StringAssembler{"chaintypes.String"}.AssignBool(false) +} +func (_String__Assembler) AssignInt(int) error { + return mixins.StringAssembler{"chaintypes.String"}.AssignInt(0) +} +func (_String__Assembler) AssignFloat(float64) error { + return mixins.StringAssembler{"chaintypes.String"}.AssignFloat(0) +} +func (na *_String__Assembler) AssignString(v string) error { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if na.w == nil { + na.w = &_String{} + } + na.w.x = v + *na.m = schema.Maybe_Value + return nil +} +func (_String__Assembler) AssignBytes([]byte) error { + return mixins.StringAssembler{"chaintypes.String"}.AssignBytes(nil) +} +func (_String__Assembler) AssignLink(ipld.Link) error { + return mixins.StringAssembler{"chaintypes.String"}.AssignLink(nil) +} +func (na *_String__Assembler) AssignNode(v ipld.Node) error { + if v.IsNull() { + return na.AssignNull() + } + if v2, ok := v.(*_String); ok { + switch *na.m { + case schema.Maybe_Value, schema.Maybe_Null: + panic("invalid state: cannot assign into assembler that's already finished") + } + if na.w == nil { + na.w = v2 + *na.m = schema.Maybe_Value + return nil + } + *na.w = *v2 + *na.m = schema.Maybe_Value + return nil + } + if v2, err := v.AsString(); err != nil { + return err + } else { + return na.AssignString(v2) + } +} +func (_String__Assembler) Prototype() ipld.NodePrototype { + return _String__Prototype{} +} +func (String) Type() schema.Type { + return nil /*TODO:typelit*/ +} +func (n String) Representation() ipld.Node { + return (*_String__Repr)(n) +} + +type _String__Repr = _String + +var _ ipld.Node = &_String__Repr{} + +type _String__ReprPrototype = _String__Prototype +type _String__ReprAssembler = _String__Assembler diff --git a/testutil/chaintypes/typeTable.go b/testutil/chaintypes/typeTable.go new file mode 100644 index 00000000..0c51a513 --- /dev/null +++ b/testutil/chaintypes/typeTable.go @@ -0,0 +1,28 @@ +package chaintypes + +// Type is a struct embeding a NodePrototype/Type for every Node implementation in this package. +// One of its major uses is to start the construction of a value. +// You can use it like this: +// +// chaintypes.Type.YourTypeName.NewBuilder().BeginMap() //... +// +// and: +// +// chaintypes.Type.OtherTypeName.NewBuilder().AssignString("x") // ... +// +var Type typeSlab + +type typeSlab struct { + Block _Block__Prototype + Block__Repr _Block__ReprPrototype + Bytes _Bytes__Prototype + Bytes__Repr _Bytes__ReprPrototype + Link _Link__Prototype + Link__Repr _Link__ReprPrototype + Messages _Messages__Prototype + Messages__Repr _Messages__ReprPrototype + Parents _Parents__Prototype + Parents__Repr _Parents__ReprPrototype + String _String__Prototype + String__Repr _String__ReprPrototype +} diff --git a/testutil/testchain.go b/testutil/testchain.go index ba1113e5..fae1e237 100644 --- a/testutil/testchain.go +++ b/testutil/testchain.go @@ -15,6 +15,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ipfs/go-graphsync" + "github.com/ipfs/go-graphsync/testutil/chaintypes" ) // TestingT covers the interface methods we need from either *testing.T or @@ -42,7 +43,7 @@ type TestBlockChain struct { } func createBlock(parents []ipld.Link, size uint64) (ipld.Node, error) { - blknb := basicnode.Prototype.Map.NewBuilder() + blknb := chaintypes.Type.Block.NewBuilder() blknbmnb, err := blknb.BeginMap(2) if err != nil { return nil, err @@ -169,20 +170,20 @@ func (tbc *TestBlockChain) checkResponses(responses []graphsync.ResponseProgress for i, response := range responses { require.Equal(tbc.t, expectedPath, response.Path.String(), "response has correct path") if i%2 == 0 { - // if verifyTypes { - // _, ok := response.Node.(chaintypes.Block) - // require.True(tbc.t, ok, "nodes in response should have correct type") - // } + if verifyTypes { + _, ok := response.Node.(chaintypes.Block) + require.True(tbc.t, ok, "nodes in response should have correct type") + } if expectedPath == "" { expectedPath = "Parents" } else { expectedPath = expectedPath + "/Parents" } } else { - // if verifyTypes { - // _, ok := response.Node.(chaintypes.Parents) - // require.True(tbc.t, ok, "nodes in response should have correct type") - // } + if verifyTypes { + _, ok := response.Node.(chaintypes.Parents) + require.True(tbc.t, ok, "nodes in response should have correct type") + } expectedPath = expectedPath + "/0" } if response.LastBlock.Path.String() != response.Path.String() { @@ -271,6 +272,5 @@ func (tbc *TestBlockChain) RemainderBlocks(from int) []blocks.Block { // Chooser is a NodeBuilderChooser function that always returns the block chain func (tbc *TestBlockChain) Chooser(ipld.Link, ipld.LinkContext) (ipld.NodePrototype, error) { - return basicnode.Prototype.Any, nil - //return chaintypes.Block__NodeBuilder(), nil + return chaintypes.Type.Block, nil }