tMsg3.go 27.4 KB
Newer Older
1
package gendemo
2

Eric Myhre's avatar
Eric Myhre committed
3 4
// Code generated by go-ipld-prime gengo.  DO NOT EDIT.

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
import (
	ipld "github.com/ipld/go-ipld-prime"
	"github.com/ipld/go-ipld-prime/node/mixins"
	"github.com/ipld/go-ipld-prime/schema"
)

type _Msg3 struct {
	whee _Int
	woot _Int
	waga _Int
}
type Msg3 = *_Msg3

func (n _Msg3) FieldWhee() Int {
	return &n.whee
}
func (n _Msg3) FieldWoot() Int {
	return &n.woot
}
func (n _Msg3) FieldWaga() Int {
	return &n.waga
}

28 29 30 31 32 33 34 35 36
type _Msg3__Maybe struct {
	m schema.Maybe
	v Msg3
}
type MaybeMsg3 = *_Msg3__Maybe

func (m MaybeMsg3) IsNull() bool {
	return m.m == schema.Maybe_Null
}
37
func (m MaybeMsg3) IsAbsent() bool {
38 39 40 41 42 43 44 45
	return m.m == schema.Maybe_Absent
}
func (m MaybeMsg3) Exists() bool {
	return m.m == schema.Maybe_Value
}
func (m MaybeMsg3) AsNode() ipld.Node {
	switch m.m {
	case schema.Maybe_Absent:
46
		return ipld.Absent
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
	case schema.Maybe_Null:
		return ipld.Null
	case schema.Maybe_Value:
		return m.v
	default:
		panic("unreachable")
	}
}
func (m MaybeMsg3) Must() Msg3 {
	if !m.Exists() {
		panic("unbox of a maybe rejected")
	}
	return m.v
}

62 63 64 65 66 67 68 69 70 71 72
var (
	fieldName__Msg3_Whee = _String{"whee"}
	fieldName__Msg3_Woot = _String{"woot"}
	fieldName__Msg3_Waga = _String{"waga"}
)
var _ ipld.Node = (Msg3)(&_Msg3{})
var _ schema.TypedNode = (Msg3)(&_Msg3{})

func (Msg3) ReprKind() ipld.ReprKind {
	return ipld.ReprKind_Map
}
73
func (n Msg3) LookupByString(key string) (ipld.Node, error) {
74 75 76 77 78 79 80 81
	switch key {
	case "whee":
		return &n.whee, nil
	case "woot":
		return &n.woot, nil
	case "waga":
		return &n.waga, nil
	default:
82
		return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)}
83 84
	}
}
85
func (n Msg3) LookupByNode(key ipld.Node) (ipld.Node, error) {
86 87 88 89
	ks, err := key.AsString()
	if err != nil {
		return nil, err
	}
90
	return n.LookupByString(ks)
91
}
92 93
func (Msg3) LookupByIndex(idx int) (ipld.Node, error) {
	return mixins.Map{"gendemo.Msg3"}.LookupByIndex(0)
94
}
95 96
func (n Msg3) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) {
	return n.LookupByString(seg.String())
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
}
func (n Msg3) MapIterator() ipld.MapIterator {
	return &_Msg3__MapItr{n, 0}
}

type _Msg3__MapItr struct {
	n   Msg3
	idx int
}

func (itr *_Msg3__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) {
	if itr.idx >= 3 {
		return nil, nil, ipld.ErrIteratorOverread{}
	}
	switch itr.idx {
	case 0:
		k = &fieldName__Msg3_Whee
		v = &itr.n.whee
	case 1:
		k = &fieldName__Msg3_Woot
		v = &itr.n.woot
	case 2:
		k = &fieldName__Msg3_Waga
		v = &itr.n.waga
	default:
		panic("unreachable")
	}
	itr.idx++
	return
}
func (itr *_Msg3__MapItr) Done() bool {
	return itr.idx >= 3
}

func (Msg3) ListIterator() ipld.ListIterator {
	return nil
}
func (Msg3) Length() int {
	return 3
}
137
func (Msg3) IsAbsent() bool {
138 139 140 141 142 143
	return false
}
func (Msg3) IsNull() bool {
	return false
}
func (Msg3) AsBool() (bool, error) {
144
	return mixins.Map{"gendemo.Msg3"}.AsBool()
145 146
}
func (Msg3) AsInt() (int, error) {
147
	return mixins.Map{"gendemo.Msg3"}.AsInt()
148 149
}
func (Msg3) AsFloat() (float64, error) {
150
	return mixins.Map{"gendemo.Msg3"}.AsFloat()
151 152
}
func (Msg3) AsString() (string, error) {
153
	return mixins.Map{"gendemo.Msg3"}.AsString()
154 155
}
func (Msg3) AsBytes() ([]byte, error) {
156
	return mixins.Map{"gendemo.Msg3"}.AsBytes()
157 158
}
func (Msg3) AsLink() (ipld.Link, error) {
159
	return mixins.Map{"gendemo.Msg3"}.AsLink()
160
}
161 162
func (Msg3) Prototype() ipld.NodePrototype {
	return _Msg3__Prototype{}
163 164
}

165
type _Msg3__Prototype struct{}
166

167
func (_Msg3__Prototype) NewBuilder() ipld.NodeBuilder {
168 169 170 171 172 173 174 175 176 177
	var nb _Msg3__Builder
	nb.Reset()
	return &nb
}

type _Msg3__Builder struct {
	_Msg3__Assembler
}

func (nb *_Msg3__Builder) Build() ipld.Node {
Eric Myhre's avatar
Eric Myhre committed
178 179
	if *nb.m != schema.Maybe_Value {
		panic("invalid state: cannot call Build on an assembler that's not finished")
180 181 182 183 184
	}
	return nb.w
}
func (nb *_Msg3__Builder) Reset() {
	var w _Msg3
185
	var m schema.Maybe
Eric Myhre's avatar
Eric Myhre committed
186
	*nb = _Msg3__Builder{_Msg3__Assembler{w: &w, m: &m}}
187 188 189 190
}

type _Msg3__Assembler struct {
	w     *_Msg3
191
	m     *schema.Maybe
192 193 194 195
	state maState
	s     int
	f     int

196
	cm      schema.Maybe
197 198 199 200 201
	ca_whee _Int__Assembler
	ca_woot _Int__Assembler
	ca_waga _Int__Assembler
}

202 203 204 205 206 207 208 209
func (na *_Msg3__Assembler) reset() {
	na.state = maState_initial
	na.s = 0
	na.ca_whee.reset()
	na.ca_woot.reset()
	na.ca_waga.reset()
}

210 211 212 213 214 215 216 217
var (
	fieldBit__Msg3_Whee        = 1 << 0
	fieldBit__Msg3_Woot        = 1 << 1
	fieldBit__Msg3_Waga        = 1 << 2
	fieldBits__Msg3_sufficient = 0 + 1<<0 + 1<<1 + 1<<2
)

func (na *_Msg3__Assembler) BeginMap(int) (ipld.MapAssembler, error) {
218 219 220 221 222 223 224 225 226 227
	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 = &_Msg3{}
	}
228 229 230
	return na, nil
}
func (_Msg3__Assembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
231
	return mixins.MapAssembler{"gendemo.Msg3"}.BeginList(0)
232 233
}
func (na *_Msg3__Assembler) AssignNull() error {
234 235 236 237 238
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
239
		return mixins.MapAssembler{"gendemo.Msg3"}.AssignNull()
240 241 242 243
	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!")
244
	}
245
	panic("unreachable")
246 247
}
func (_Msg3__Assembler) AssignBool(bool) error {
248
	return mixins.MapAssembler{"gendemo.Msg3"}.AssignBool(false)
249 250
}
func (_Msg3__Assembler) AssignInt(int) error {
251
	return mixins.MapAssembler{"gendemo.Msg3"}.AssignInt(0)
252 253
}
func (_Msg3__Assembler) AssignFloat(float64) error {
254
	return mixins.MapAssembler{"gendemo.Msg3"}.AssignFloat(0)
255 256
}
func (_Msg3__Assembler) AssignString(string) error {
257
	return mixins.MapAssembler{"gendemo.Msg3"}.AssignString("")
258 259
}
func (_Msg3__Assembler) AssignBytes([]byte) error {
260
	return mixins.MapAssembler{"gendemo.Msg3"}.AssignBytes(nil)
261 262
}
func (_Msg3__Assembler) AssignLink(ipld.Link) error {
263
	return mixins.MapAssembler{"gendemo.Msg3"}.AssignLink(nil)
264 265
}
func (na *_Msg3__Assembler) AssignNode(v ipld.Node) error {
266
	if v.IsNull() {
267 268 269
		return na.AssignNull()
	}
	if v2, ok := v.(*_Msg3); ok {
270 271 272 273 274 275 276 277 278
		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
279 280
			return nil
		}
281 282 283
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
284 285
	}
	if v.ReprKind() != ipld.ReprKind_Map {
286
		return ipld.ErrWrongKind{TypeName: "gendemo.Msg3", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: v.ReprKind()}
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
	}
	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()
}
303 304
func (_Msg3__Assembler) Prototype() ipld.NodePrototype {
	return _Msg3__Prototype{}
305
}
306 307 308 309 310
func (ma *_Msg3__Assembler) valueFinishTidy() bool {
	switch ma.f {
	case 0:
		switch ma.cm {
		case schema.Maybe_Value:
311
			ma.ca_whee.w = nil
312 313 314 315 316 317 318 319 320
			ma.cm = schema.Maybe_Absent
			ma.state = maState_initial
			return true
		default:
			return false
		}
	case 1:
		switch ma.cm {
		case schema.Maybe_Value:
321
			ma.ca_woot.w = nil
322 323 324 325 326 327 328 329 330
			ma.cm = schema.Maybe_Absent
			ma.state = maState_initial
			return true
		default:
			return false
		}
	case 2:
		switch ma.cm {
		case schema.Maybe_Value:
331
			ma.ca_waga.w = nil
332 333 334 335 336 337 338 339 340 341
			ma.cm = schema.Maybe_Absent
			ma.state = maState_initial
			return true
		default:
			return false
		}
	default:
		panic("unreachable")
	}
}
342
func (ma *_Msg3__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, error) {
343 344 345 346 347 348 349 350 351 352 353 354 355
	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")
356 357 358 359 360 361 362 363
	}
	switch k {
	case "whee":
		if ma.s&fieldBit__Msg3_Whee != 0 {
			return nil, ipld.ErrRepeatedMapKey{&fieldName__Msg3_Whee}
		}
		ma.s += fieldBit__Msg3_Whee
		ma.state = maState_midValue
364
		ma.f = 0
365
		ma.ca_whee.w = &ma.w.whee
366
		ma.ca_whee.m = &ma.cm
367 368 369 370 371 372 373
		return &ma.ca_whee, nil
	case "woot":
		if ma.s&fieldBit__Msg3_Woot != 0 {
			return nil, ipld.ErrRepeatedMapKey{&fieldName__Msg3_Woot}
		}
		ma.s += fieldBit__Msg3_Woot
		ma.state = maState_midValue
374
		ma.f = 1
375
		ma.ca_woot.w = &ma.w.woot
376
		ma.ca_woot.m = &ma.cm
377 378 379 380 381 382 383
		return &ma.ca_woot, nil
	case "waga":
		if ma.s&fieldBit__Msg3_Waga != 0 {
			return nil, ipld.ErrRepeatedMapKey{&fieldName__Msg3_Waga}
		}
		ma.s += fieldBit__Msg3_Waga
		ma.state = maState_midValue
384
		ma.f = 2
385
		ma.ca_waga.w = &ma.w.waga
386
		ma.ca_waga.m = &ma.cm
387 388
		return &ma.ca_waga, nil
	default:
389
		return nil, ipld.ErrInvalidKey{TypeName: "gendemo.Msg3", Key: &_String{k}}
390 391 392
	}
}
func (ma *_Msg3__Assembler) AssembleKey() ipld.NodeAssembler {
393 394 395 396 397 398 399 400 401 402 403 404 405
	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")
406 407 408 409 410
	}
	ma.state = maState_midKey
	return (*_Msg3__KeyAssembler)(ma)
}
func (ma *_Msg3__Assembler) AssembleValue() ipld.NodeAssembler {
411 412 413 414 415 416 417 418 419 420 421
	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")
422 423 424 425 426
	}
	ma.state = maState_midValue
	switch ma.f {
	case 0:
		ma.ca_whee.w = &ma.w.whee
427
		ma.ca_whee.m = &ma.cm
428 429 430
		return &ma.ca_whee
	case 1:
		ma.ca_woot.w = &ma.w.woot
431
		ma.ca_woot.m = &ma.cm
432 433 434
		return &ma.ca_woot
	case 2:
		ma.ca_waga.w = &ma.w.waga
435
		ma.ca_waga.m = &ma.cm
436 437 438 439 440 441
		return &ma.ca_waga
	default:
		panic("unreachable")
	}
}
func (ma *_Msg3__Assembler) Finish() error {
442 443 444 445 446 447 448 449 450 451 452 453 454
	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")
455 456 457
	}
	//FIXME check if all required fields are set
	ma.state = maState_finished
458 459
	*ma.m = schema.Maybe_Value
	return nil
460
}
461 462
func (ma *_Msg3__Assembler) KeyPrototype() ipld.NodePrototype {
	return _String__Prototype{}
463
}
464 465
func (ma *_Msg3__Assembler) ValuePrototype(k string) ipld.NodePrototype {
	panic("todo structbuilder mapassembler valueprototype")
466 467 468 469 470
}

type _Msg3__KeyAssembler _Msg3__Assembler

func (_Msg3__KeyAssembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) {
471
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.BeginMap(0)
472 473
}
func (_Msg3__KeyAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
474
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.BeginList(0)
475 476
}
func (na *_Msg3__KeyAssembler) AssignNull() error {
477
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.AssignNull()
478 479
}
func (_Msg3__KeyAssembler) AssignBool(bool) error {
480
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.AssignBool(false)
481 482
}
func (_Msg3__KeyAssembler) AssignInt(int) error {
483
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.AssignInt(0)
484 485
}
func (_Msg3__KeyAssembler) AssignFloat(float64) error {
486
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.AssignFloat(0)
487 488 489
}
func (ka *_Msg3__KeyAssembler) AssignString(k string) error {
	if ka.state != maState_midKey {
490
		panic("misuse: KeyAssembler held beyond its valid lifetime")
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
	}
	switch k {
	case "whee":
		if ka.s&fieldBit__Msg3_Whee != 0 {
			return ipld.ErrRepeatedMapKey{&fieldName__Msg3_Whee}
		}
		ka.s += fieldBit__Msg3_Whee
		ka.state = maState_expectValue
		ka.f = 0
	case "woot":
		if ka.s&fieldBit__Msg3_Woot != 0 {
			return ipld.ErrRepeatedMapKey{&fieldName__Msg3_Woot}
		}
		ka.s += fieldBit__Msg3_Woot
		ka.state = maState_expectValue
		ka.f = 1
	case "waga":
		if ka.s&fieldBit__Msg3_Waga != 0 {
			return ipld.ErrRepeatedMapKey{&fieldName__Msg3_Waga}
		}
		ka.s += fieldBit__Msg3_Waga
		ka.state = maState_expectValue
		ka.f = 2
	default:
515
		return ipld.ErrInvalidKey{TypeName: "gendemo.Msg3", Key: &_String{k}}
516 517 518 519
	}
	return nil
}
func (_Msg3__KeyAssembler) AssignBytes([]byte) error {
520
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.AssignBytes(nil)
521 522
}
func (_Msg3__KeyAssembler) AssignLink(ipld.Link) error {
523
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.AssignLink(nil)
524 525 526 527 528 529 530 531
}
func (ka *_Msg3__KeyAssembler) AssignNode(v ipld.Node) error {
	if v2, err := v.AsString(); err != nil {
		return err
	} else {
		return ka.AssignString(v2)
	}
}
532 533
func (_Msg3__KeyAssembler) Prototype() ipld.NodePrototype {
	return _String__Prototype{}
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
}
func (Msg3) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Msg3) Representation() ipld.Node {
	return (*_Msg3__Repr)(n)
}

type _Msg3__Repr _Msg3

var (
	fieldName__Msg3_Whee_serial = _String{"whee"}
	fieldName__Msg3_Woot_serial = _String{"woot"}
	fieldName__Msg3_Waga_serial = _String{"waga"}
)
var _ ipld.Node = &_Msg3__Repr{}

func (_Msg3__Repr) ReprKind() ipld.ReprKind {
	return ipld.ReprKind_Map
}
554
func (n *_Msg3__Repr) LookupByString(key string) (ipld.Node, error) {
555 556
	switch key {
	case "whee":
557
		return n.whee.Representation(), nil
558
	case "woot":
559
		return n.woot.Representation(), nil
560
	case "waga":
561
		return n.waga.Representation(), nil
562
	default:
563
		return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: ipld.PathSegmentOfString(key)}
564 565
	}
}
566
func (n *_Msg3__Repr) LookupByNode(key ipld.Node) (ipld.Node, error) {
567 568 569 570
	ks, err := key.AsString()
	if err != nil {
		return nil, err
	}
571
	return n.LookupByString(ks)
572
}
573 574
func (_Msg3__Repr) LookupByIndex(idx int) (ipld.Node, error) {
	return mixins.Map{"gendemo.Msg3.Repr"}.LookupByIndex(0)
575
}
576 577
func (n _Msg3__Repr) LookupBySegment(seg ipld.PathSegment) (ipld.Node, error) {
	return n.LookupByString(seg.String())
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
}
func (n *_Msg3__Repr) MapIterator() ipld.MapIterator {
	return &_Msg3__ReprMapItr{n, 0}
}

type _Msg3__ReprMapItr struct {
	n   *_Msg3__Repr
	idx int
}

func (itr *_Msg3__ReprMapItr) Next() (k ipld.Node, v ipld.Node, _ error) {
	if itr.idx >= 3 {
		return nil, nil, ipld.ErrIteratorOverread{}
	}
	switch itr.idx {
	case 0:
		k = &fieldName__Msg3_Whee_serial
595
		v = itr.n.whee.Representation()
596 597
	case 1:
		k = &fieldName__Msg3_Woot_serial
598
		v = itr.n.woot.Representation()
599 600
	case 2:
		k = &fieldName__Msg3_Waga_serial
601
		v = itr.n.waga.Representation()
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
	default:
		panic("unreachable")
	}
	itr.idx++
	return
}
func (itr *_Msg3__ReprMapItr) Done() bool {
	return itr.idx >= 3
}
func (_Msg3__Repr) ListIterator() ipld.ListIterator {
	return nil
}
func (rn *_Msg3__Repr) Length() int {
	l := 3
	return l
}
618
func (_Msg3__Repr) IsAbsent() bool {
619 620 621 622 623 624
	return false
}
func (_Msg3__Repr) IsNull() bool {
	return false
}
func (_Msg3__Repr) AsBool() (bool, error) {
625
	return mixins.Map{"gendemo.Msg3.Repr"}.AsBool()
626 627
}
func (_Msg3__Repr) AsInt() (int, error) {
628
	return mixins.Map{"gendemo.Msg3.Repr"}.AsInt()
629 630
}
func (_Msg3__Repr) AsFloat() (float64, error) {
631
	return mixins.Map{"gendemo.Msg3.Repr"}.AsFloat()
632 633
}
func (_Msg3__Repr) AsString() (string, error) {
634
	return mixins.Map{"gendemo.Msg3.Repr"}.AsString()
635 636
}
func (_Msg3__Repr) AsBytes() ([]byte, error) {
637
	return mixins.Map{"gendemo.Msg3.Repr"}.AsBytes()
638 639
}
func (_Msg3__Repr) AsLink() (ipld.Link, error) {
640
	return mixins.Map{"gendemo.Msg3.Repr"}.AsLink()
641
}
642 643
func (_Msg3__Repr) Prototype() ipld.NodePrototype {
	return _Msg3__ReprPrototype{}
644 645
}

646
type _Msg3__ReprPrototype struct{}
647

648
func (_Msg3__ReprPrototype) NewBuilder() ipld.NodeBuilder {
649 650 651 652 653 654 655 656 657 658
	var nb _Msg3__ReprBuilder
	nb.Reset()
	return &nb
}

type _Msg3__ReprBuilder struct {
	_Msg3__ReprAssembler
}

func (nb *_Msg3__ReprBuilder) Build() ipld.Node {
Eric Myhre's avatar
Eric Myhre committed
659 660
	if *nb.m != schema.Maybe_Value {
		panic("invalid state: cannot call Build on an assembler that's not finished")
661 662 663 664 665
	}
	return nb.w
}
func (nb *_Msg3__ReprBuilder) Reset() {
	var w _Msg3
666
	var m schema.Maybe
Eric Myhre's avatar
Eric Myhre committed
667
	*nb = _Msg3__ReprBuilder{_Msg3__ReprAssembler{w: &w, m: &m}}
668 669 670 671
}

type _Msg3__ReprAssembler struct {
	w     *_Msg3
672
	m     *schema.Maybe
673 674 675 676
	state maState
	s     int
	f     int

677
	cm      schema.Maybe
678 679 680 681 682
	ca_whee _Int__ReprAssembler
	ca_woot _Int__ReprAssembler
	ca_waga _Int__ReprAssembler
}

683 684 685 686 687 688 689
func (na *_Msg3__ReprAssembler) reset() {
	na.state = maState_initial
	na.s = 0
	na.ca_whee.reset()
	na.ca_woot.reset()
	na.ca_waga.reset()
}
690
func (na *_Msg3__ReprAssembler) BeginMap(int) (ipld.MapAssembler, error) {
691 692 693 694 695 696 697 698 699 700
	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 = &_Msg3{}
	}
701 702 703
	return na, nil
}
func (_Msg3__ReprAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
704
	return mixins.MapAssembler{"gendemo.Msg3.Repr"}.BeginList(0)
705 706
}
func (na *_Msg3__ReprAssembler) AssignNull() error {
707 708 709 710 711
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
712
		return mixins.MapAssembler{"gendemo.Msg3.Repr.Repr"}.AssignNull()
713 714 715 716
	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!")
717
	}
718
	panic("unreachable")
719 720
}
func (_Msg3__ReprAssembler) AssignBool(bool) error {
721
	return mixins.MapAssembler{"gendemo.Msg3.Repr"}.AssignBool(false)
722 723
}
func (_Msg3__ReprAssembler) AssignInt(int) error {
724
	return mixins.MapAssembler{"gendemo.Msg3.Repr"}.AssignInt(0)
725 726
}
func (_Msg3__ReprAssembler) AssignFloat(float64) error {
727
	return mixins.MapAssembler{"gendemo.Msg3.Repr"}.AssignFloat(0)
728 729
}
func (_Msg3__ReprAssembler) AssignString(string) error {
730
	return mixins.MapAssembler{"gendemo.Msg3.Repr"}.AssignString("")
731 732
}
func (_Msg3__ReprAssembler) AssignBytes([]byte) error {
733
	return mixins.MapAssembler{"gendemo.Msg3.Repr"}.AssignBytes(nil)
734 735
}
func (_Msg3__ReprAssembler) AssignLink(ipld.Link) error {
736
	return mixins.MapAssembler{"gendemo.Msg3.Repr"}.AssignLink(nil)
737 738
}
func (na *_Msg3__ReprAssembler) AssignNode(v ipld.Node) error {
739
	if v.IsNull() {
740 741 742
		return na.AssignNull()
	}
	if v2, ok := v.(*_Msg3); ok {
743 744 745 746 747 748 749 750 751
		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
752 753
			return nil
		}
754 755 756
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
757 758
	}
	if v.ReprKind() != ipld.ReprKind_Map {
759
		return ipld.ErrWrongKind{TypeName: "gendemo.Msg3.Repr", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: v.ReprKind()}
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
	}
	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()
}
776 777
func (_Msg3__ReprAssembler) Prototype() ipld.NodePrototype {
	return _Msg3__ReprPrototype{}
778
}
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
func (ma *_Msg3__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
		}
	case 2:
		switch ma.cm {
		case schema.Maybe_Value:
			ma.cm = schema.Maybe_Absent
			ma.state = maState_initial
			return true
		default:
			return false
		}
	default:
		panic("unreachable")
	}
}
812
func (ma *_Msg3__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, error) {
813 814 815 816 817 818 819 820 821 822 823 824 825
	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")
826 827 828 829 830 831 832 833
	}
	switch k {
	case "whee":
		if ma.s&fieldBit__Msg3_Whee != 0 {
			return nil, ipld.ErrRepeatedMapKey{&fieldName__Msg3_Whee_serial}
		}
		ma.s += fieldBit__Msg3_Whee
		ma.state = maState_midValue
834
		ma.f = 0
835
		ma.ca_whee.w = &ma.w.whee
836
		ma.ca_whee.m = &ma.cm
837 838 839 840 841 842 843
		return &ma.ca_whee, nil
	case "woot":
		if ma.s&fieldBit__Msg3_Woot != 0 {
			return nil, ipld.ErrRepeatedMapKey{&fieldName__Msg3_Woot_serial}
		}
		ma.s += fieldBit__Msg3_Woot
		ma.state = maState_midValue
844
		ma.f = 1
845
		ma.ca_woot.w = &ma.w.woot
846
		ma.ca_woot.m = &ma.cm
847 848 849 850 851 852 853
		return &ma.ca_woot, nil
	case "waga":
		if ma.s&fieldBit__Msg3_Waga != 0 {
			return nil, ipld.ErrRepeatedMapKey{&fieldName__Msg3_Waga_serial}
		}
		ma.s += fieldBit__Msg3_Waga
		ma.state = maState_midValue
854
		ma.f = 2
855
		ma.ca_waga.w = &ma.w.waga
856
		ma.ca_waga.m = &ma.cm
857 858
		return &ma.ca_waga, nil
	default:
859
		return nil, ipld.ErrInvalidKey{TypeName: "gendemo.Msg3.Repr", Key: &_String{k}}
860 861 862
	}
}
func (ma *_Msg3__ReprAssembler) AssembleKey() ipld.NodeAssembler {
863 864 865 866 867 868 869 870 871 872 873 874 875
	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")
876 877 878 879 880
	}
	ma.state = maState_midKey
	return (*_Msg3__ReprKeyAssembler)(ma)
}
func (ma *_Msg3__ReprAssembler) AssembleValue() ipld.NodeAssembler {
881 882 883 884 885 886 887 888 889 890 891
	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")
892 893 894 895 896
	}
	ma.state = maState_midValue
	switch ma.f {
	case 0:
		ma.ca_whee.w = &ma.w.whee
897
		ma.ca_whee.m = &ma.cm
898 899 900
		return &ma.ca_whee
	case 1:
		ma.ca_woot.w = &ma.w.woot
901
		ma.ca_woot.m = &ma.cm
902 903 904
		return &ma.ca_woot
	case 2:
		ma.ca_waga.w = &ma.w.waga
905
		ma.ca_waga.m = &ma.cm
906 907 908 909 910 911
		return &ma.ca_waga
	default:
		panic("unreachable")
	}
}
func (ma *_Msg3__ReprAssembler) Finish() error {
912 913 914 915 916 917 918 919 920 921 922 923 924
	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")
925 926 927
	}
	//FIXME check if all required fields are set
	ma.state = maState_finished
928 929
	*ma.m = schema.Maybe_Value
	return nil
930
}
931 932
func (ma *_Msg3__ReprAssembler) KeyPrototype() ipld.NodePrototype {
	return _String__Prototype{}
933
}
934 935
func (ma *_Msg3__ReprAssembler) ValuePrototype(k string) ipld.NodePrototype {
	panic("todo structbuilder mapassembler repr valueprototype")
936 937 938 939 940
}

type _Msg3__ReprKeyAssembler _Msg3__ReprAssembler

func (_Msg3__ReprKeyAssembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) {
941
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.BeginMap(0)
942 943
}
func (_Msg3__ReprKeyAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
944
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.BeginList(0)
945 946
}
func (na *_Msg3__ReprKeyAssembler) AssignNull() error {
947
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.AssignNull()
948 949
}
func (_Msg3__ReprKeyAssembler) AssignBool(bool) error {
950
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.AssignBool(false)
951 952
}
func (_Msg3__ReprKeyAssembler) AssignInt(int) error {
953
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.AssignInt(0)
954 955
}
func (_Msg3__ReprKeyAssembler) AssignFloat(float64) error {
956
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.AssignFloat(0)
957 958 959
}
func (ka *_Msg3__ReprKeyAssembler) AssignString(k string) error {
	if ka.state != maState_midKey {
960
		panic("misuse: KeyAssembler held beyond its valid lifetime")
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984
	}
	switch k {
	case "whee":
		if ka.s&fieldBit__Msg3_Whee != 0 {
			return ipld.ErrRepeatedMapKey{&fieldName__Msg3_Whee_serial}
		}
		ka.s += fieldBit__Msg3_Whee
		ka.state = maState_expectValue
		ka.f = 0
	case "woot":
		if ka.s&fieldBit__Msg3_Woot != 0 {
			return ipld.ErrRepeatedMapKey{&fieldName__Msg3_Woot_serial}
		}
		ka.s += fieldBit__Msg3_Woot
		ka.state = maState_expectValue
		ka.f = 1
	case "waga":
		if ka.s&fieldBit__Msg3_Waga != 0 {
			return ipld.ErrRepeatedMapKey{&fieldName__Msg3_Waga_serial}
		}
		ka.s += fieldBit__Msg3_Waga
		ka.state = maState_expectValue
		ka.f = 2
	default:
985
		return ipld.ErrInvalidKey{TypeName: "gendemo.Msg3.Repr", Key: &_String{k}}
986 987 988 989
	}
	return nil
}
func (_Msg3__ReprKeyAssembler) AssignBytes([]byte) error {
990
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.AssignBytes(nil)
991 992
}
func (_Msg3__ReprKeyAssembler) AssignLink(ipld.Link) error {
993
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.AssignLink(nil)
994 995 996 997 998 999 1000 1001
}
func (ka *_Msg3__ReprKeyAssembler) AssignNode(v ipld.Node) error {
	if v2, err := v.AsString(); err != nil {
		return err
	} else {
		return ka.AssignString(v2)
	}
}
1002 1003
func (_Msg3__ReprKeyAssembler) Prototype() ipld.NodePrototype {
	return _String__Prototype{}
1004
}