tMsg3.go 27.1 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
type _Msg3__Maybe struct {
	m schema.Maybe
	v Msg3
}
type MaybeMsg3 = *_Msg3__Maybe

func (m MaybeMsg3) IsNull() bool {
	return m.m == schema.Maybe_Null
}
func (m MaybeMsg3) IsUndefined() bool {
	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:
		return ipld.Undef
	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 73 74 75 76 77 78 79 80 81 82 83 84
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
}
func (n Msg3) LookupString(key string) (ipld.Node, error) {
	switch key {
	case "whee":
		return &n.whee, nil
	case "woot":
		return &n.woot, nil
	case "waga":
		return &n.waga, nil
	default:
		return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, FieldName: key}
	}
}
85
func (n Msg3) LookupNode(key ipld.Node) (ipld.Node, error) {
86 87 88 89 90 91 92
	ks, err := key.AsString()
	if err != nil {
		return nil, err
	}
	return n.LookupString(ks)
}
func (Msg3) LookupIndex(idx int) (ipld.Node, error) {
93
	return mixins.Map{"gendemo.Msg3"}.LookupIndex(0)
94 95 96 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 137 138 139 140 141 142 143
}
func (n Msg3) LookupSegment(seg ipld.PathSegment) (ipld.Node, error) {
	return n.LookupString(seg.String())
}
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
}
func (Msg3) IsUndefined() bool {
	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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
}
func (Msg3) Style() ipld.NodeStyle {
	return _Msg3__Style{}
}

type _Msg3__Style struct{}

func (_Msg3__Style) NewBuilder() ipld.NodeBuilder {
	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 303 304 305
	}
	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 (_Msg3__Assembler) Style() ipld.NodeStyle {
	return _Msg3__Style{}
}
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 364
	}
	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
		ma.ca_whee.w = &ma.w.whee
365
		ma.ca_whee.m = &ma.cm
366 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
		ma.ca_woot.w = &ma.w.woot
374
		ma.ca_woot.m = &ma.cm
375 376 377 378 379 380 381 382
		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
		ma.ca_waga.w = &ma.w.waga
383
		ma.ca_waga.m = &ma.cm
384 385
		return &ma.ca_waga, nil
	default:
386
		return nil, ipld.ErrInvalidKey{TypeName: "gendemo.Msg3", Key: &_String{k}}
387 388 389
	}
}
func (ma *_Msg3__Assembler) AssembleKey() ipld.NodeAssembler {
390 391 392 393 394 395 396 397 398 399 400 401 402
	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")
403 404 405 406 407
	}
	ma.state = maState_midKey
	return (*_Msg3__KeyAssembler)(ma)
}
func (ma *_Msg3__Assembler) AssembleValue() ipld.NodeAssembler {
408 409 410 411 412 413 414 415 416 417 418
	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")
419 420 421 422 423
	}
	ma.state = maState_midValue
	switch ma.f {
	case 0:
		ma.ca_whee.w = &ma.w.whee
424
		ma.ca_whee.m = &ma.cm
425 426 427
		return &ma.ca_whee
	case 1:
		ma.ca_woot.w = &ma.w.woot
428
		ma.ca_woot.m = &ma.cm
429 430 431
		return &ma.ca_woot
	case 2:
		ma.ca_waga.w = &ma.w.waga
432
		ma.ca_waga.m = &ma.cm
433 434 435 436 437 438
		return &ma.ca_waga
	default:
		panic("unreachable")
	}
}
func (ma *_Msg3__Assembler) Finish() error {
439 440 441 442 443 444 445 446 447 448 449 450 451
	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")
452 453 454
	}
	//FIXME check if all required fields are set
	ma.state = maState_finished
455 456
	*ma.m = schema.Maybe_Value
	return nil
457 458 459 460 461 462 463 464 465 466 467
}
func (ma *_Msg3__Assembler) KeyStyle() ipld.NodeStyle {
	return _String__Style{}
}
func (ma *_Msg3__Assembler) ValueStyle(k string) ipld.NodeStyle {
	panic("todo structbuilder mapassembler valuestyle")
}

type _Msg3__KeyAssembler _Msg3__Assembler

func (_Msg3__KeyAssembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) {
468
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.BeginMap(0)
469 470
}
func (_Msg3__KeyAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
471
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.BeginList(0)
472 473
}
func (na *_Msg3__KeyAssembler) AssignNull() error {
474
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.AssignNull()
475 476
}
func (_Msg3__KeyAssembler) AssignBool(bool) error {
477
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.AssignBool(false)
478 479
}
func (_Msg3__KeyAssembler) AssignInt(int) error {
480
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.AssignInt(0)
481 482
}
func (_Msg3__KeyAssembler) AssignFloat(float64) error {
483
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.AssignFloat(0)
484 485 486
}
func (ka *_Msg3__KeyAssembler) AssignString(k string) error {
	if ka.state != maState_midKey {
487
		panic("misuse: KeyAssembler held beyond its valid lifetime")
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
	}
	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:
512
		return ipld.ErrInvalidKey{TypeName: "gendemo.Msg3", Key: &_String{k}}
513 514 515 516
	}
	return nil
}
func (_Msg3__KeyAssembler) AssignBytes([]byte) error {
517
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.AssignBytes(nil)
518 519
}
func (_Msg3__KeyAssembler) AssignLink(ipld.Link) error {
520
	return mixins.StringAssembler{"gendemo.Msg3.KeyAssembler"}.AssignLink(nil)
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
}
func (ka *_Msg3__KeyAssembler) AssignNode(v ipld.Node) error {
	if v2, err := v.AsString(); err != nil {
		return err
	} else {
		return ka.AssignString(v2)
	}
}
func (_Msg3__KeyAssembler) Style() ipld.NodeStyle {
	return _String__Style{}
}
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
}
func (n *_Msg3__Repr) LookupString(key string) (ipld.Node, error) {
	switch key {
	case "whee":
554
		return n.whee.Representation(), nil
555
	case "woot":
556
		return n.woot.Representation(), nil
557
	case "waga":
558
		return n.waga.Representation(), nil
559 560 561 562
	default:
		return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, FieldName: key}
	}
}
563
func (n *_Msg3__Repr) LookupNode(key ipld.Node) (ipld.Node, error) {
564 565 566 567 568 569 570
	ks, err := key.AsString()
	if err != nil {
		return nil, err
	}
	return n.LookupString(ks)
}
func (_Msg3__Repr) LookupIndex(idx int) (ipld.Node, error) {
571
	return mixins.Map{"gendemo.Msg3.Repr"}.LookupIndex(0)
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
}
func (n _Msg3__Repr) LookupSegment(seg ipld.PathSegment) (ipld.Node, error) {
	return n.LookupString(seg.String())
}
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
592
		v = itr.n.whee.Representation()
593 594
	case 1:
		k = &fieldName__Msg3_Woot_serial
595
		v = itr.n.woot.Representation()
596 597
	case 2:
		k = &fieldName__Msg3_Waga_serial
598
		v = itr.n.waga.Representation()
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
	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
}
func (_Msg3__Repr) IsUndefined() bool {
	return false
}
func (_Msg3__Repr) IsNull() bool {
	return false
}
func (_Msg3__Repr) AsBool() (bool, error) {
622
	return mixins.Map{"gendemo.Msg3.Repr"}.AsBool()
623 624
}
func (_Msg3__Repr) AsInt() (int, error) {
625
	return mixins.Map{"gendemo.Msg3.Repr"}.AsInt()
626 627
}
func (_Msg3__Repr) AsFloat() (float64, error) {
628
	return mixins.Map{"gendemo.Msg3.Repr"}.AsFloat()
629 630
}
func (_Msg3__Repr) AsString() (string, error) {
631
	return mixins.Map{"gendemo.Msg3.Repr"}.AsString()
632 633
}
func (_Msg3__Repr) AsBytes() ([]byte, error) {
634
	return mixins.Map{"gendemo.Msg3.Repr"}.AsBytes()
635 636
}
func (_Msg3__Repr) AsLink() (ipld.Link, error) {
637
	return mixins.Map{"gendemo.Msg3.Repr"}.AsLink()
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
}
func (_Msg3__Repr) Style() ipld.NodeStyle {
	return _Msg3__ReprStyle{}
}

type _Msg3__ReprStyle struct{}

func (_Msg3__ReprStyle) NewBuilder() ipld.NodeBuilder {
	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
656 657
	if *nb.m != schema.Maybe_Value {
		panic("invalid state: cannot call Build on an assembler that's not finished")
658 659 660 661 662
	}
	return nb.w
}
func (nb *_Msg3__ReprBuilder) Reset() {
	var w _Msg3
663
	var m schema.Maybe
Eric Myhre's avatar
Eric Myhre committed
664
	*nb = _Msg3__ReprBuilder{_Msg3__ReprAssembler{w: &w, m: &m}}
665 666 667 668
}

type _Msg3__ReprAssembler struct {
	w     *_Msg3
669
	m     *schema.Maybe
670 671 672 673
	state maState
	s     int
	f     int

674
	cm      schema.Maybe
675 676 677 678 679
	ca_whee _Int__ReprAssembler
	ca_woot _Int__ReprAssembler
	ca_waga _Int__ReprAssembler
}

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

type _Msg3__ReprKeyAssembler _Msg3__ReprAssembler

func (_Msg3__ReprKeyAssembler) BeginMap(sizeHint int) (ipld.MapAssembler, error) {
935
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.BeginMap(0)
936 937
}
func (_Msg3__ReprKeyAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
938
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.BeginList(0)
939 940
}
func (na *_Msg3__ReprKeyAssembler) AssignNull() error {
941
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.AssignNull()
942 943
}
func (_Msg3__ReprKeyAssembler) AssignBool(bool) error {
944
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.AssignBool(false)
945 946
}
func (_Msg3__ReprKeyAssembler) AssignInt(int) error {
947
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.AssignInt(0)
948 949
}
func (_Msg3__ReprKeyAssembler) AssignFloat(float64) error {
950
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.AssignFloat(0)
951 952 953
}
func (ka *_Msg3__ReprKeyAssembler) AssignString(k string) error {
	if ka.state != maState_midKey {
954
		panic("misuse: KeyAssembler held beyond its valid lifetime")
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
	}
	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:
979
		return ipld.ErrInvalidKey{TypeName: "gendemo.Msg3.Repr", Key: &_String{k}}
980 981 982 983
	}
	return nil
}
func (_Msg3__ReprKeyAssembler) AssignBytes([]byte) error {
984
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.AssignBytes(nil)
985 986
}
func (_Msg3__ReprKeyAssembler) AssignLink(ipld.Link) error {
987
	return mixins.StringAssembler{"gendemo.Msg3.Repr.KeyAssembler"}.AssignLink(nil)
988 989 990 991 992 993 994 995 996 997 998
}
func (ka *_Msg3__ReprKeyAssembler) AssignNode(v ipld.Node) error {
	if v2, err := v.AsString(); err != nil {
		return err
	} else {
		return ka.AssignString(v2)
	}
}
func (_Msg3__ReprKeyAssembler) Style() ipld.NodeStyle {
	return _String__Style{}
}