tMap__String__Msg3.go 23.3 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 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
import (
	ipld "github.com/ipld/go-ipld-prime"
	"github.com/ipld/go-ipld-prime/node/mixins"
	"github.com/ipld/go-ipld-prime/schema"
)

type _Map__String__Msg3 struct {
	m map[_String]*_Msg3
	t []_Map__String__Msg3__entry
}
type Map__String__Msg3 = *_Map__String__Msg3
type _Map__String__Msg3__entry struct {
	k _String
	v _Msg3
}

func (n *_Map__String__Msg3) LookupMaybe(k String) MaybeMsg3 {
	v, ok := n.m[*k]
	if !ok {
		return &_Map__String__Msg3__valueAbsent
	}
	return &_Msg3__Maybe{
		m: schema.Maybe_Value,
		v: v,
	}
}

var _Map__String__Msg3__valueAbsent = _Msg3__Maybe{m: schema.Maybe_Absent}

// TODO generate also a plain Lookup method that doesn't box and alloc if this type contains non-nullable values!
type _Map__String__Msg3__Maybe struct {
	m schema.Maybe
	v Map__String__Msg3
}
type MaybeMap__String__Msg3 = *_Map__String__Msg3__Maybe

func (m MaybeMap__String__Msg3) IsNull() bool {
	return m.m == schema.Maybe_Null
}
func (m MaybeMap__String__Msg3) IsUndefined() bool {
	return m.m == schema.Maybe_Absent
}
func (m MaybeMap__String__Msg3) Exists() bool {
	return m.m == schema.Maybe_Value
}
func (m MaybeMap__String__Msg3) 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 MaybeMap__String__Msg3) Must() Map__String__Msg3 {
	if !m.Exists() {
		panic("unbox of a maybe rejected")
	}
	return m.v
}

var _ ipld.Node = (Map__String__Msg3)(&_Map__String__Msg3{})
var _ schema.TypedNode = (Map__String__Msg3)(&_Map__String__Msg3{})

func (Map__String__Msg3) ReprKind() ipld.ReprKind {
	return ipld.ReprKind_Map
}
func (n Map__String__Msg3) LookupString(k string) (ipld.Node, error) {
	var k2 _String
	if err := (_String__Style{}).fromString(&k2, k); err != nil {
		return nil, err // TODO wrap in some kind of ErrInvalidKey
	}
	v, exists := n.m[k2]
	if !exists {
Eric Myhre's avatar
Eric Myhre committed
82
		return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(k)}
83 84 85 86 87 88 89
	}
	return v, nil
}
func (n Map__String__Msg3) Lookup(k ipld.Node) (ipld.Node, error) {
	k2, ok := k.(String)
	if !ok {
		panic("todo invalid key type error")
90
		// 'ipld.ErrInvalidKey{TypeName:"gendemo.Map__String__Msg3", Key:&_String{k}}' doesn't quite cut it: need room to explain the type, and it's not guaranteed k can be turned into a string at all
91 92 93
	}
	v, exists := n.m[*k2]
	if !exists {
Eric Myhre's avatar
Eric Myhre committed
94
		return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(k2.String())}
95 96 97 98
	}
	return v, nil
}
func (Map__String__Msg3) LookupIndex(idx int) (ipld.Node, error) {
99
	return mixins.Map{"gendemo.Map__String__Msg3"}.LookupIndex(0)
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
}
func (n Map__String__Msg3) LookupSegment(seg ipld.PathSegment) (ipld.Node, error) {
	return n.LookupString(seg.String())
}
func (n Map__String__Msg3) MapIterator() ipld.MapIterator {
	return &_Map__String__Msg3__MapItr{n, 0}
}

type _Map__String__Msg3__MapItr struct {
	n   Map__String__Msg3
	idx int
}

func (itr *_Map__String__Msg3__MapItr) Next() (k ipld.Node, v ipld.Node, _ error) {
	if itr.idx >= len(itr.n.t) {
		return nil, nil, ipld.ErrIteratorOverread{}
	}
	x := &itr.n.t[itr.idx]
	k = &x.k
	v = &x.v
	itr.idx++
	return
}
func (itr *_Map__String__Msg3__MapItr) Done() bool {
	return itr.idx >= len(itr.n.t)
}

func (Map__String__Msg3) ListIterator() ipld.ListIterator {
	return nil
}
func (n Map__String__Msg3) Length() int {
	return len(n.t)
}
func (Map__String__Msg3) IsUndefined() bool {
	return false
}
func (Map__String__Msg3) IsNull() bool {
	return false
}
func (Map__String__Msg3) AsBool() (bool, error) {
140
	return mixins.Map{"gendemo.Map__String__Msg3"}.AsBool()
141 142
}
func (Map__String__Msg3) AsInt() (int, error) {
143
	return mixins.Map{"gendemo.Map__String__Msg3"}.AsInt()
144 145
}
func (Map__String__Msg3) AsFloat() (float64, error) {
146
	return mixins.Map{"gendemo.Map__String__Msg3"}.AsFloat()
147 148
}
func (Map__String__Msg3) AsString() (string, error) {
149
	return mixins.Map{"gendemo.Map__String__Msg3"}.AsString()
150 151
}
func (Map__String__Msg3) AsBytes() ([]byte, error) {
152
	return mixins.Map{"gendemo.Map__String__Msg3"}.AsBytes()
153 154
}
func (Map__String__Msg3) AsLink() (ipld.Link, error) {
155
	return mixins.Map{"gendemo.Map__String__Msg3"}.AsLink()
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
}
func (Map__String__Msg3) Style() ipld.NodeStyle {
	return _Map__String__Msg3__Style{}
}

type _Map__String__Msg3__Style struct{}

func (_Map__String__Msg3__Style) NewBuilder() ipld.NodeBuilder {
	var nb _Map__String__Msg3__Builder
	nb.Reset()
	return &nb
}

type _Map__String__Msg3__Builder struct {
	_Map__String__Msg3__Assembler
}

func (nb *_Map__String__Msg3__Builder) Build() ipld.Node {
Eric Myhre's avatar
Eric Myhre committed
174 175
	if *nb.m != schema.Maybe_Value {
		panic("invalid state: cannot call Build on an assembler that's not finished")
176 177 178 179 180 181
	}
	return nb.w
}
func (nb *_Map__String__Msg3__Builder) Reset() {
	var w _Map__String__Msg3
	var m schema.Maybe
Eric Myhre's avatar
Eric Myhre committed
182
	*nb = _Map__String__Msg3__Builder{_Map__String__Msg3__Assembler{w: &w, m: &m}}
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
}

type _Map__String__Msg3__Assembler struct {
	w     *_Map__String__Msg3
	m     *schema.Maybe
	state maState

	cm schema.Maybe
	ka _String__Assembler
	va _Msg3__Assembler
}

func (na *_Map__String__Msg3__Assembler) reset() {
	na.state = maState_initial
	na.ka.reset()
	na.va.reset()
}
func (na *_Map__String__Msg3__Assembler) BeginMap(sizeHint 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 sizeHint < 0 {
		sizeHint = 0
	}
	if na.w == nil {
		na.w = &_Map__String__Msg3{}
	}
	na.w.m = make(map[_String]*_Msg3, sizeHint)
	na.w.t = make([]_Map__String__Msg3__entry, 0, sizeHint)
	return na, nil
}
func (_Map__String__Msg3__Assembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
219
	return mixins.MapAssembler{"gendemo.Map__String__Msg3"}.BeginList(0)
220 221 222 223 224 225 226
}
func (na *_Map__String__Msg3__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
227
		return mixins.MapAssembler{"gendemo.Map__String__Msg3"}.AssignNull()
228 229 230 231 232 233 234 235
	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 (_Map__String__Msg3__Assembler) AssignBool(bool) error {
236
	return mixins.MapAssembler{"gendemo.Map__String__Msg3"}.AssignBool(false)
237 238
}
func (_Map__String__Msg3__Assembler) AssignInt(int) error {
239
	return mixins.MapAssembler{"gendemo.Map__String__Msg3"}.AssignInt(0)
240 241
}
func (_Map__String__Msg3__Assembler) AssignFloat(float64) error {
242
	return mixins.MapAssembler{"gendemo.Map__String__Msg3"}.AssignFloat(0)
243 244
}
func (_Map__String__Msg3__Assembler) AssignString(string) error {
245
	return mixins.MapAssembler{"gendemo.Map__String__Msg3"}.AssignString("")
246 247
}
func (_Map__String__Msg3__Assembler) AssignBytes([]byte) error {
248
	return mixins.MapAssembler{"gendemo.Map__String__Msg3"}.AssignBytes(nil)
249 250
}
func (_Map__String__Msg3__Assembler) AssignLink(ipld.Link) error {
251
	return mixins.MapAssembler{"gendemo.Map__String__Msg3"}.AssignLink(nil)
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
}
func (na *_Map__String__Msg3__Assembler) AssignNode(v ipld.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Map__String__Msg3); 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 {
274
		return ipld.ErrWrongKind{TypeName: "gendemo.Map__String__Msg3", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: v.ReprKind()}
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
	}
	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 (_Map__String__Msg3__Assembler) Style() ipld.NodeStyle {
	return _Map__String__Msg3__Style{}
}
func (ma *_Map__String__Msg3__Assembler) keyFinishTidy() bool {
	switch ma.cm {
	case schema.Maybe_Value:
		ma.ka.w = nil
		tz := &ma.w.t[len(ma.w.t)-1]
		ma.cm = schema.Maybe_Absent
		ma.state = maState_expectValue
		ma.w.m[tz.k] = &tz.v
		ma.va.w = &tz.v
		ma.va.m = &ma.cm
		ma.ka.reset()
		return true
	default:
		return false
	}
}
func (ma *_Map__String__Msg3__Assembler) valueFinishTidy() bool {
	switch ma.cm {
	case schema.Maybe_Value:
		ma.va.w = nil
		ma.cm = schema.Maybe_Absent
		ma.state = maState_initial
		ma.va.reset()
		return true
	default:
		return false
	}
}
func (ma *_Map__String__Msg3__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")
	}

	var k2 _String
	if err := (_String__Style{}).fromString(&k2, k); err != nil {
		return nil, err // TODO wrap in some kind of ErrInvalidKey
	}
	if _, exists := ma.w.m[k2]; exists {
		return nil, ipld.ErrRepeatedMapKey{&k2}
	}
	ma.w.t = append(ma.w.t, _Map__String__Msg3__entry{k: k2})
	tz := &ma.w.t[len(ma.w.t)-1]
	ma.state = maState_midValue

	ma.w.m[k2] = &tz.v
	ma.va.w = &tz.v
	ma.va.m = &ma.cm
	return &ma.va, nil
}
func (ma *_Map__String__Msg3__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")
	}
Eric Myhre's avatar
Eric Myhre committed
369
	ma.w.t = append(ma.w.t, _Map__String__Msg3__entry{})
370
	ma.state = maState_midKey
Eric Myhre's avatar
Eric Myhre committed
371 372
	ma.ka.m = &ma.cm
	ma.ka.w = &ma.w.t[len(ma.w.t)-1].k
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
	return &ma.ka
}
func (ma *_Map__String__Msg3__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:
		if !ma.keyFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key")
		} // if tidy success: carry on
	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
	return &ma.va
}
func (ma *_Map__String__Msg3__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")
	}
	ma.state = maState_finished
	*ma.m = schema.Maybe_Value
	return nil
}
func (ma *_Map__String__Msg3__Assembler) KeyStyle() ipld.NodeStyle {
	return _String__Style{}
}
func (ma *_Map__String__Msg3__Assembler) ValueStyle(_ string) ipld.NodeStyle {
	return _Msg3__Style{}
}
func (Map__String__Msg3) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Map__String__Msg3) Representation() ipld.Node {
	return (*_Map__String__Msg3__Repr)(n)
}

Eric Myhre's avatar
Eric Myhre committed
425
type _Map__String__Msg3__Repr _Map__String__Msg3
426 427 428

var _ ipld.Node = &_Map__String__Msg3__Repr{}

Eric Myhre's avatar
Eric Myhre committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
func (_Map__String__Msg3__Repr) ReprKind() ipld.ReprKind {
	return ipld.ReprKind_Map
}
func (nr *_Map__String__Msg3__Repr) LookupString(k string) (ipld.Node, error) {
	v, err := (Map__String__Msg3)(nr).LookupString(k)
	if err != nil || v == ipld.Null {
		return v, err
	}
	return v.(Msg3).Representation(), nil
}
func (nr *_Map__String__Msg3__Repr) Lookup(k ipld.Node) (ipld.Node, error) {
	v, err := (Map__String__Msg3)(nr).Lookup(k)
	if err != nil || v == ipld.Null {
		return v, err
	}
	return v.(Msg3).Representation(), nil
}
func (_Map__String__Msg3__Repr) LookupIndex(idx int) (ipld.Node, error) {
447
	return mixins.Map{"gendemo.Map__String__Msg3.Repr"}.LookupIndex(0)
Eric Myhre's avatar
Eric Myhre committed
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
}
func (n _Map__String__Msg3__Repr) LookupSegment(seg ipld.PathSegment) (ipld.Node, error) {
	return n.LookupString(seg.String())
}
func (nr *_Map__String__Msg3__Repr) MapIterator() ipld.MapIterator {
	return &_Map__String__Msg3__ReprMapItr{(Map__String__Msg3)(nr), 0}
}

type _Map__String__Msg3__ReprMapItr _Map__String__Msg3__MapItr

func (itr *_Map__String__Msg3__ReprMapItr) Next() (k ipld.Node, v ipld.Node, err error) {
	k, v, err = (*_Map__String__Msg3__MapItr)(itr).Next()
	if err != nil || v == ipld.Null {
		return
	}
	return k, v.(Msg3).Representation(), nil
}
func (itr *_Map__String__Msg3__ReprMapItr) Done() bool {
	return (*_Map__String__Msg3__MapItr)(itr).Done()
}

func (_Map__String__Msg3__Repr) ListIterator() ipld.ListIterator {
	return nil
}
func (rn *_Map__String__Msg3__Repr) Length() int {
	return len(rn.t)
}
func (_Map__String__Msg3__Repr) IsUndefined() bool {
	return false
}
func (_Map__String__Msg3__Repr) IsNull() bool {
	return false
}
func (_Map__String__Msg3__Repr) AsBool() (bool, error) {
482
	return mixins.Map{"gendemo.Map__String__Msg3.Repr"}.AsBool()
Eric Myhre's avatar
Eric Myhre committed
483 484
}
func (_Map__String__Msg3__Repr) AsInt() (int, error) {
485
	return mixins.Map{"gendemo.Map__String__Msg3.Repr"}.AsInt()
Eric Myhre's avatar
Eric Myhre committed
486 487
}
func (_Map__String__Msg3__Repr) AsFloat() (float64, error) {
488
	return mixins.Map{"gendemo.Map__String__Msg3.Repr"}.AsFloat()
Eric Myhre's avatar
Eric Myhre committed
489 490
}
func (_Map__String__Msg3__Repr) AsString() (string, error) {
491
	return mixins.Map{"gendemo.Map__String__Msg3.Repr"}.AsString()
Eric Myhre's avatar
Eric Myhre committed
492 493
}
func (_Map__String__Msg3__Repr) AsBytes() ([]byte, error) {
494
	return mixins.Map{"gendemo.Map__String__Msg3.Repr"}.AsBytes()
Eric Myhre's avatar
Eric Myhre committed
495 496
}
func (_Map__String__Msg3__Repr) AsLink() (ipld.Link, error) {
497
	return mixins.Map{"gendemo.Map__String__Msg3.Repr"}.AsLink()
Eric Myhre's avatar
Eric Myhre committed
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 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 554 555 556 557 558 559 560
}
func (_Map__String__Msg3__Repr) Style() ipld.NodeStyle {
	return _Map__String__Msg3__ReprStyle{}
}

type _Map__String__Msg3__ReprStyle struct{}

func (_Map__String__Msg3__ReprStyle) NewBuilder() ipld.NodeBuilder {
	var nb _Map__String__Msg3__ReprBuilder
	nb.Reset()
	return &nb
}

type _Map__String__Msg3__ReprBuilder struct {
	_Map__String__Msg3__ReprAssembler
}

func (nb *_Map__String__Msg3__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 *_Map__String__Msg3__ReprBuilder) Reset() {
	var w _Map__String__Msg3
	var m schema.Maybe
	*nb = _Map__String__Msg3__ReprBuilder{_Map__String__Msg3__ReprAssembler{w: &w, m: &m}}
}

type _Map__String__Msg3__ReprAssembler struct {
	w     *_Map__String__Msg3
	m     *schema.Maybe
	state maState

	cm schema.Maybe
	ka _String__ReprAssembler
	va _Msg3__ReprAssembler
}

func (na *_Map__String__Msg3__ReprAssembler) reset() {
	na.state = maState_initial
	na.ka.reset()
	na.va.reset()
}
func (na *_Map__String__Msg3__ReprAssembler) BeginMap(sizeHint 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 sizeHint < 0 {
		sizeHint = 0
	}
	if na.w == nil {
		na.w = &_Map__String__Msg3{}
	}
	na.w.m = make(map[_String]*_Msg3, sizeHint)
	na.w.t = make([]_Map__String__Msg3__entry, 0, sizeHint)
	return na, nil
}
func (_Map__String__Msg3__ReprAssembler) BeginList(sizeHint int) (ipld.ListAssembler, error) {
561
	return mixins.MapAssembler{"gendemo.Map__String__Msg3.Repr"}.BeginList(0)
Eric Myhre's avatar
Eric Myhre committed
562 563 564 565 566 567 568
}
func (na *_Map__String__Msg3__ReprAssembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
569
		return mixins.MapAssembler{"gendemo.Map__String__Msg3.Repr.Repr"}.AssignNull()
Eric Myhre's avatar
Eric Myhre committed
570 571 572 573 574 575 576 577
	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 (_Map__String__Msg3__ReprAssembler) AssignBool(bool) error {
578
	return mixins.MapAssembler{"gendemo.Map__String__Msg3.Repr"}.AssignBool(false)
Eric Myhre's avatar
Eric Myhre committed
579 580
}
func (_Map__String__Msg3__ReprAssembler) AssignInt(int) error {
581
	return mixins.MapAssembler{"gendemo.Map__String__Msg3.Repr"}.AssignInt(0)
Eric Myhre's avatar
Eric Myhre committed
582 583
}
func (_Map__String__Msg3__ReprAssembler) AssignFloat(float64) error {
584
	return mixins.MapAssembler{"gendemo.Map__String__Msg3.Repr"}.AssignFloat(0)
Eric Myhre's avatar
Eric Myhre committed
585 586
}
func (_Map__String__Msg3__ReprAssembler) AssignString(string) error {
587
	return mixins.MapAssembler{"gendemo.Map__String__Msg3.Repr"}.AssignString("")
Eric Myhre's avatar
Eric Myhre committed
588 589
}
func (_Map__String__Msg3__ReprAssembler) AssignBytes([]byte) error {
590
	return mixins.MapAssembler{"gendemo.Map__String__Msg3.Repr"}.AssignBytes(nil)
Eric Myhre's avatar
Eric Myhre committed
591 592
}
func (_Map__String__Msg3__ReprAssembler) AssignLink(ipld.Link) error {
593
	return mixins.MapAssembler{"gendemo.Map__String__Msg3.Repr"}.AssignLink(nil)
Eric Myhre's avatar
Eric Myhre committed
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
}
func (na *_Map__String__Msg3__ReprAssembler) AssignNode(v ipld.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Map__String__Msg3); 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 {
616
		return ipld.ErrWrongKind{TypeName: "gendemo.Map__String__Msg3.Repr", MethodName: "AssignNode", AppropriateKind: ipld.ReprKindSet_JustMap, ActualKind: v.ReprKind()}
Eric Myhre's avatar
Eric Myhre committed
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
	}
	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 (_Map__String__Msg3__ReprAssembler) Style() ipld.NodeStyle {
	return _Map__String__Msg3__ReprStyle{}
}
func (ma *_Map__String__Msg3__ReprAssembler) keyFinishTidy() bool {
	switch ma.cm {
	case schema.Maybe_Value:
		ma.ka.w = nil
		tz := &ma.w.t[len(ma.w.t)-1]
		ma.cm = schema.Maybe_Absent
		ma.state = maState_expectValue
		ma.w.m[tz.k] = &tz.v
		ma.va.w = &tz.v
		ma.va.m = &ma.cm
		ma.ka.reset()
		return true
	default:
		return false
	}
}
func (ma *_Map__String__Msg3__ReprAssembler) valueFinishTidy() bool {
	switch ma.cm {
	case schema.Maybe_Value:
		ma.va.w = nil
		ma.cm = schema.Maybe_Absent
		ma.state = maState_initial
		ma.va.reset()
		return true
	default:
		return false
	}
}
func (ma *_Map__String__Msg3__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")
	}

	var k2 _String
	if err := (_String__ReprStyle{}).fromString(&k2, k); err != nil {
		return nil, err // TODO wrap in some kind of ErrInvalidKey
	}
	if _, exists := ma.w.m[k2]; exists {
		return nil, ipld.ErrRepeatedMapKey{&k2}
	}
	ma.w.t = append(ma.w.t, _Map__String__Msg3__entry{k: k2})
	tz := &ma.w.t[len(ma.w.t)-1]
	ma.state = maState_midValue

	ma.w.m[k2] = &tz.v
	ma.va.w = &tz.v
	ma.va.m = &ma.cm
	return &ma.va, nil
}
func (ma *_Map__String__Msg3__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.w.t = append(ma.w.t, _Map__String__Msg3__entry{})
	ma.state = maState_midKey
	ma.ka.m = &ma.cm
	ma.ka.w = &ma.w.t[len(ma.w.t)-1].k
	return &ma.ka
}
func (ma *_Map__String__Msg3__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:
		if !ma.keyFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when in the middle of assembling a key")
		} // if tidy success: carry on
	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
	return &ma.va
}
func (ma *_Map__String__Msg3__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")
	}
	ma.state = maState_finished
	*ma.m = schema.Maybe_Value
	return nil
}
func (ma *_Map__String__Msg3__ReprAssembler) KeyStyle() ipld.NodeStyle {
	return _String__ReprStyle{}
}
func (ma *_Map__String__Msg3__ReprAssembler) ValueStyle(_ string) ipld.NodeStyle {
	return _Msg3__ReprStyle{}
}