package gendemo

// Code generated by go-ipld-prime gengo.  DO NOT EDIT.

import (
	"github.com/ipld/go-ipld-prime/datamodel"
	"github.com/ipld/go-ipld-prime/node/mixins"
	"github.com/ipld/go-ipld-prime/schema"
)

func (n Bar) Bool() bool {
	return n.x
}
func (_Bar__Prototype) FromBool(v bool) (Bar, error) {
	n := _Bar{v}
	return &n, nil
}

type _Bar__Maybe struct {
	m schema.Maybe
	v _Bar
}
type MaybeBar = *_Bar__Maybe

func (m MaybeBar) IsNull() bool {
	return m.m == schema.Maybe_Null
}
func (m MaybeBar) IsAbsent() bool {
	return m.m == schema.Maybe_Absent
}
func (m MaybeBar) Exists() bool {
	return m.m == schema.Maybe_Value
}
func (m MaybeBar) AsNode() datamodel.Node {
	switch m.m {
	case schema.Maybe_Absent:
		return datamodel.Absent
	case schema.Maybe_Null:
		return datamodel.Null
	case schema.Maybe_Value:
		return &m.v
	default:
		panic("unreachable")
	}
}
func (m MaybeBar) Must() Bar {
	if !m.Exists() {
		panic("unbox of a maybe rejected")
	}
	return &m.v
}

var _ datamodel.Node = (Bar)(&_Bar{})
var _ schema.TypedNode = (Bar)(&_Bar{})

func (Bar) Kind() datamodel.Kind {
	return datamodel.Kind_Bool
}
func (Bar) LookupByString(string) (datamodel.Node, error) {
	return mixins.Bool{TypeName: "gendemo.Bar"}.LookupByString("")
}
func (Bar) LookupByNode(datamodel.Node) (datamodel.Node, error) {
	return mixins.Bool{TypeName: "gendemo.Bar"}.LookupByNode(nil)
}
func (Bar) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.Bool{TypeName: "gendemo.Bar"}.LookupByIndex(0)
}
func (Bar) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return mixins.Bool{TypeName: "gendemo.Bar"}.LookupBySegment(seg)
}
func (Bar) MapIterator() datamodel.MapIterator {
	return nil
}
func (Bar) ListIterator() datamodel.ListIterator {
	return nil
}
func (Bar) Length() int64 {
	return -1
}
func (Bar) IsAbsent() bool {
	return false
}
func (Bar) IsNull() bool {
	return false
}
func (n Bar) AsBool() (bool, error) {
	return n.x, nil
}
func (Bar) AsInt() (int64, error) {
	return mixins.Bool{TypeName: "gendemo.Bar"}.AsInt()
}
func (Bar) AsFloat() (float64, error) {
	return mixins.Bool{TypeName: "gendemo.Bar"}.AsFloat()
}
func (Bar) AsString() (string, error) {
	return mixins.Bool{TypeName: "gendemo.Bar"}.AsString()
}
func (Bar) AsBytes() ([]byte, error) {
	return mixins.Bool{TypeName: "gendemo.Bar"}.AsBytes()
}
func (Bar) AsLink() (datamodel.Link, error) {
	return mixins.Bool{TypeName: "gendemo.Bar"}.AsLink()
}
func (Bar) Prototype() datamodel.NodePrototype {
	return _Bar__Prototype{}
}

type _Bar__Prototype struct{}

func (_Bar__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Bar__Builder
	nb.Reset()
	return &nb
}

type _Bar__Builder struct {
	_Bar__Assembler
}

func (nb *_Bar__Builder) Build() datamodel.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 *_Bar__Builder) Reset() {
	var w _Bar
	var m schema.Maybe
	*nb = _Bar__Builder{_Bar__Assembler{w: &w, m: &m}}
}

type _Bar__Assembler struct {
	w *_Bar
	m *schema.Maybe
}

func (na *_Bar__Assembler) reset() {}
func (_Bar__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.BoolAssembler{TypeName: "gendemo.Bar"}.BeginMap(0)
}
func (_Bar__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.BoolAssembler{TypeName: "gendemo.Bar"}.BeginList(0)
}
func (na *_Bar__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.BoolAssembler{TypeName: "gendemo.Bar"}.AssignNull()
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	}
	panic("unreachable")
}
func (na *_Bar__Assembler) AssignBool(v bool) error {
	switch *na.m {
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	}
	na.w.x = v
	*na.m = schema.Maybe_Value
	return nil
}
func (_Bar__Assembler) AssignInt(int64) error {
	return mixins.BoolAssembler{TypeName: "gendemo.Bar"}.AssignInt(0)
}
func (_Bar__Assembler) AssignFloat(float64) error {
	return mixins.BoolAssembler{TypeName: "gendemo.Bar"}.AssignFloat(0)
}
func (_Bar__Assembler) AssignString(string) error {
	return mixins.BoolAssembler{TypeName: "gendemo.Bar"}.AssignString("")
}
func (_Bar__Assembler) AssignBytes([]byte) error {
	return mixins.BoolAssembler{TypeName: "gendemo.Bar"}.AssignBytes(nil)
}
func (_Bar__Assembler) AssignLink(datamodel.Link) error {
	return mixins.BoolAssembler{TypeName: "gendemo.Bar"}.AssignLink(nil)
}
func (na *_Bar__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Bar); ok {
		switch *na.m {
		case schema.Maybe_Value, schema.Maybe_Null:
			panic("invalid state: cannot assign into assembler that's already finished")
		}
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
	}
	if v2, err := v.AsBool(); err != nil {
		return err
	} else {
		return na.AssignBool(v2)
	}
}
func (_Bar__Assembler) Prototype() datamodel.NodePrototype {
	return _Bar__Prototype{}
}
func (Bar) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Bar) Representation() datamodel.Node {
	return (*_Bar__Repr)(n)
}

type _Bar__Repr = _Bar

var _ datamodel.Node = &_Bar__Repr{}

type _Bar__ReprPrototype = _Bar__Prototype
type _Bar__ReprAssembler = _Bar__Assembler

func (n Baz) String() string {
	return n.x
}
func (_Baz__Prototype) fromString(w *_Baz, v string) error {
	*w = _Baz{v}
	return nil
}
func (_Baz__Prototype) FromString(v string) (Baz, error) {
	n := _Baz{v}
	return &n, nil
}

type _Baz__Maybe struct {
	m schema.Maybe
	v _Baz
}
type MaybeBaz = *_Baz__Maybe

func (m MaybeBaz) IsNull() bool {
	return m.m == schema.Maybe_Null
}
func (m MaybeBaz) IsAbsent() bool {
	return m.m == schema.Maybe_Absent
}
func (m MaybeBaz) Exists() bool {
	return m.m == schema.Maybe_Value
}
func (m MaybeBaz) AsNode() datamodel.Node {
	switch m.m {
	case schema.Maybe_Absent:
		return datamodel.Absent
	case schema.Maybe_Null:
		return datamodel.Null
	case schema.Maybe_Value:
		return &m.v
	default:
		panic("unreachable")
	}
}
func (m MaybeBaz) Must() Baz {
	if !m.Exists() {
		panic("unbox of a maybe rejected")
	}
	return &m.v
}

var _ datamodel.Node = (Baz)(&_Baz{})
var _ schema.TypedNode = (Baz)(&_Baz{})

func (Baz) Kind() datamodel.Kind {
	return datamodel.Kind_String
}
func (Baz) LookupByString(string) (datamodel.Node, error) {
	return mixins.String{TypeName: "gendemo.Baz"}.LookupByString("")
}
func (Baz) LookupByNode(datamodel.Node) (datamodel.Node, error) {
	return mixins.String{TypeName: "gendemo.Baz"}.LookupByNode(nil)
}
func (Baz) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.String{TypeName: "gendemo.Baz"}.LookupByIndex(0)
}
func (Baz) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return mixins.String{TypeName: "gendemo.Baz"}.LookupBySegment(seg)
}
func (Baz) MapIterator() datamodel.MapIterator {
	return nil
}
func (Baz) ListIterator() datamodel.ListIterator {
	return nil
}
func (Baz) Length() int64 {
	return -1
}
func (Baz) IsAbsent() bool {
	return false
}
func (Baz) IsNull() bool {
	return false
}
func (Baz) AsBool() (bool, error) {
	return mixins.String{TypeName: "gendemo.Baz"}.AsBool()
}
func (Baz) AsInt() (int64, error) {
	return mixins.String{TypeName: "gendemo.Baz"}.AsInt()
}
func (Baz) AsFloat() (float64, error) {
	return mixins.String{TypeName: "gendemo.Baz"}.AsFloat()
}
func (n Baz) AsString() (string, error) {
	return n.x, nil
}
func (Baz) AsBytes() ([]byte, error) {
	return mixins.String{TypeName: "gendemo.Baz"}.AsBytes()
}
func (Baz) AsLink() (datamodel.Link, error) {
	return mixins.String{TypeName: "gendemo.Baz"}.AsLink()
}
func (Baz) Prototype() datamodel.NodePrototype {
	return _Baz__Prototype{}
}

type _Baz__Prototype struct{}

func (_Baz__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Baz__Builder
	nb.Reset()
	return &nb
}

type _Baz__Builder struct {
	_Baz__Assembler
}

func (nb *_Baz__Builder) Build() datamodel.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 *_Baz__Builder) Reset() {
	var w _Baz
	var m schema.Maybe
	*nb = _Baz__Builder{_Baz__Assembler{w: &w, m: &m}}
}

type _Baz__Assembler struct {
	w *_Baz
	m *schema.Maybe
}

func (na *_Baz__Assembler) reset() {}
func (_Baz__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.StringAssembler{TypeName: "gendemo.Baz"}.BeginMap(0)
}
func (_Baz__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.StringAssembler{TypeName: "gendemo.Baz"}.BeginList(0)
}
func (na *_Baz__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.StringAssembler{TypeName: "gendemo.Baz"}.AssignNull()
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	}
	panic("unreachable")
}
func (_Baz__Assembler) AssignBool(bool) error {
	return mixins.StringAssembler{TypeName: "gendemo.Baz"}.AssignBool(false)
}
func (_Baz__Assembler) AssignInt(int64) error {
	return mixins.StringAssembler{TypeName: "gendemo.Baz"}.AssignInt(0)
}
func (_Baz__Assembler) AssignFloat(float64) error {
	return mixins.StringAssembler{TypeName: "gendemo.Baz"}.AssignFloat(0)
}
func (na *_Baz__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")
	}
	na.w.x = v
	*na.m = schema.Maybe_Value
	return nil
}
func (_Baz__Assembler) AssignBytes([]byte) error {
	return mixins.StringAssembler{TypeName: "gendemo.Baz"}.AssignBytes(nil)
}
func (_Baz__Assembler) AssignLink(datamodel.Link) error {
	return mixins.StringAssembler{TypeName: "gendemo.Baz"}.AssignLink(nil)
}
func (na *_Baz__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Baz); ok {
		switch *na.m {
		case schema.Maybe_Value, schema.Maybe_Null:
			panic("invalid state: cannot assign into assembler that's already finished")
		}
		*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 (_Baz__Assembler) Prototype() datamodel.NodePrototype {
	return _Baz__Prototype{}
}
func (Baz) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Baz) Representation() datamodel.Node {
	return (*_Baz__Repr)(n)
}

type _Baz__Repr = _Baz

var _ datamodel.Node = &_Baz__Repr{}

type _Baz__ReprPrototype = _Baz__Prototype
type _Baz__ReprAssembler = _Baz__Assembler

func (n Foo) Int() int64 {
	return n.x
}
func (_Foo__Prototype) FromInt(v int64) (Foo, error) {
	n := _Foo{v}
	return &n, nil
}

type _Foo__Maybe struct {
	m schema.Maybe
	v _Foo
}
type MaybeFoo = *_Foo__Maybe

func (m MaybeFoo) IsNull() bool {
	return m.m == schema.Maybe_Null
}
func (m MaybeFoo) IsAbsent() bool {
	return m.m == schema.Maybe_Absent
}
func (m MaybeFoo) Exists() bool {
	return m.m == schema.Maybe_Value
}
func (m MaybeFoo) AsNode() datamodel.Node {
	switch m.m {
	case schema.Maybe_Absent:
		return datamodel.Absent
	case schema.Maybe_Null:
		return datamodel.Null
	case schema.Maybe_Value:
		return &m.v
	default:
		panic("unreachable")
	}
}
func (m MaybeFoo) Must() Foo {
	if !m.Exists() {
		panic("unbox of a maybe rejected")
	}
	return &m.v
}

var _ datamodel.Node = (Foo)(&_Foo{})
var _ schema.TypedNode = (Foo)(&_Foo{})

func (Foo) Kind() datamodel.Kind {
	return datamodel.Kind_Int
}
func (Foo) LookupByString(string) (datamodel.Node, error) {
	return mixins.Int{TypeName: "gendemo.Foo"}.LookupByString("")
}
func (Foo) LookupByNode(datamodel.Node) (datamodel.Node, error) {
	return mixins.Int{TypeName: "gendemo.Foo"}.LookupByNode(nil)
}
func (Foo) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.Int{TypeName: "gendemo.Foo"}.LookupByIndex(0)
}
func (Foo) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return mixins.Int{TypeName: "gendemo.Foo"}.LookupBySegment(seg)
}
func (Foo) MapIterator() datamodel.MapIterator {
	return nil
}
func (Foo) ListIterator() datamodel.ListIterator {
	return nil
}
func (Foo) Length() int64 {
	return -1
}
func (Foo) IsAbsent() bool {
	return false
}
func (Foo) IsNull() bool {
	return false
}
func (Foo) AsBool() (bool, error) {
	return mixins.Int{TypeName: "gendemo.Foo"}.AsBool()
}
func (n Foo) AsInt() (int64, error) {
	return n.x, nil
}
func (Foo) AsFloat() (float64, error) {
	return mixins.Int{TypeName: "gendemo.Foo"}.AsFloat()
}
func (Foo) AsString() (string, error) {
	return mixins.Int{TypeName: "gendemo.Foo"}.AsString()
}
func (Foo) AsBytes() ([]byte, error) {
	return mixins.Int{TypeName: "gendemo.Foo"}.AsBytes()
}
func (Foo) AsLink() (datamodel.Link, error) {
	return mixins.Int{TypeName: "gendemo.Foo"}.AsLink()
}
func (Foo) Prototype() datamodel.NodePrototype {
	return _Foo__Prototype{}
}

type _Foo__Prototype struct{}

func (_Foo__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Foo__Builder
	nb.Reset()
	return &nb
}

type _Foo__Builder struct {
	_Foo__Assembler
}

func (nb *_Foo__Builder) Build() datamodel.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 *_Foo__Builder) Reset() {
	var w _Foo
	var m schema.Maybe
	*nb = _Foo__Builder{_Foo__Assembler{w: &w, m: &m}}
}

type _Foo__Assembler struct {
	w *_Foo
	m *schema.Maybe
}

func (na *_Foo__Assembler) reset() {}
func (_Foo__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.IntAssembler{TypeName: "gendemo.Foo"}.BeginMap(0)
}
func (_Foo__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.IntAssembler{TypeName: "gendemo.Foo"}.BeginList(0)
}
func (na *_Foo__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.IntAssembler{TypeName: "gendemo.Foo"}.AssignNull()
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	}
	panic("unreachable")
}
func (_Foo__Assembler) AssignBool(bool) error {
	return mixins.IntAssembler{TypeName: "gendemo.Foo"}.AssignBool(false)
}
func (na *_Foo__Assembler) AssignInt(v int64) error {
	switch *na.m {
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	}
	na.w.x = v
	*na.m = schema.Maybe_Value
	return nil
}
func (_Foo__Assembler) AssignFloat(float64) error {
	return mixins.IntAssembler{TypeName: "gendemo.Foo"}.AssignFloat(0)
}
func (_Foo__Assembler) AssignString(string) error {
	return mixins.IntAssembler{TypeName: "gendemo.Foo"}.AssignString("")
}
func (_Foo__Assembler) AssignBytes([]byte) error {
	return mixins.IntAssembler{TypeName: "gendemo.Foo"}.AssignBytes(nil)
}
func (_Foo__Assembler) AssignLink(datamodel.Link) error {
	return mixins.IntAssembler{TypeName: "gendemo.Foo"}.AssignLink(nil)
}
func (na *_Foo__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Foo); ok {
		switch *na.m {
		case schema.Maybe_Value, schema.Maybe_Null:
			panic("invalid state: cannot assign into assembler that's already finished")
		}
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
	}
	if v2, err := v.AsInt(); err != nil {
		return err
	} else {
		return na.AssignInt(v2)
	}
}
func (_Foo__Assembler) Prototype() datamodel.NodePrototype {
	return _Foo__Prototype{}
}
func (Foo) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Foo) Representation() datamodel.Node {
	return (*_Foo__Repr)(n)
}

type _Foo__Repr = _Foo

var _ datamodel.Node = &_Foo__Repr{}

type _Foo__ReprPrototype = _Foo__Prototype
type _Foo__ReprAssembler = _Foo__Assembler

func (n Int) Int() int64 {
	return n.x
}
func (_Int__Prototype) FromInt(v int64) (Int, error) {
	n := _Int{v}
	return &n, nil
}

type _Int__Maybe struct {
	m schema.Maybe
	v _Int
}
type MaybeInt = *_Int__Maybe

func (m MaybeInt) IsNull() bool {
	return m.m == schema.Maybe_Null
}
func (m MaybeInt) IsAbsent() bool {
	return m.m == schema.Maybe_Absent
}
func (m MaybeInt) Exists() bool {
	return m.m == schema.Maybe_Value
}
func (m MaybeInt) AsNode() datamodel.Node {
	switch m.m {
	case schema.Maybe_Absent:
		return datamodel.Absent
	case schema.Maybe_Null:
		return datamodel.Null
	case schema.Maybe_Value:
		return &m.v
	default:
		panic("unreachable")
	}
}
func (m MaybeInt) Must() Int {
	if !m.Exists() {
		panic("unbox of a maybe rejected")
	}
	return &m.v
}

var _ datamodel.Node = (Int)(&_Int{})
var _ schema.TypedNode = (Int)(&_Int{})

func (Int) Kind() datamodel.Kind {
	return datamodel.Kind_Int
}
func (Int) LookupByString(string) (datamodel.Node, error) {
	return mixins.Int{TypeName: "gendemo.Int"}.LookupByString("")
}
func (Int) LookupByNode(datamodel.Node) (datamodel.Node, error) {
	return mixins.Int{TypeName: "gendemo.Int"}.LookupByNode(nil)
}
func (Int) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.Int{TypeName: "gendemo.Int"}.LookupByIndex(0)
}
func (Int) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return mixins.Int{TypeName: "gendemo.Int"}.LookupBySegment(seg)
}
func (Int) MapIterator() datamodel.MapIterator {
	return nil
}
func (Int) ListIterator() datamodel.ListIterator {
	return nil
}
func (Int) Length() int64 {
	return -1
}
func (Int) IsAbsent() bool {
	return false
}
func (Int) IsNull() bool {
	return false
}
func (Int) AsBool() (bool, error) {
	return mixins.Int{TypeName: "gendemo.Int"}.AsBool()
}
func (n Int) AsInt() (int64, error) {
	return n.x, nil
}
func (Int) AsFloat() (float64, error) {
	return mixins.Int{TypeName: "gendemo.Int"}.AsFloat()
}
func (Int) AsString() (string, error) {
	return mixins.Int{TypeName: "gendemo.Int"}.AsString()
}
func (Int) AsBytes() ([]byte, error) {
	return mixins.Int{TypeName: "gendemo.Int"}.AsBytes()
}
func (Int) AsLink() (datamodel.Link, error) {
	return mixins.Int{TypeName: "gendemo.Int"}.AsLink()
}
func (Int) Prototype() datamodel.NodePrototype {
	return _Int__Prototype{}
}

type _Int__Prototype struct{}

func (_Int__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Int__Builder
	nb.Reset()
	return &nb
}

type _Int__Builder struct {
	_Int__Assembler
}

func (nb *_Int__Builder) Build() datamodel.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 *_Int__Builder) Reset() {
	var w _Int
	var m schema.Maybe
	*nb = _Int__Builder{_Int__Assembler{w: &w, m: &m}}
}

type _Int__Assembler struct {
	w *_Int
	m *schema.Maybe
}

func (na *_Int__Assembler) reset() {}
func (_Int__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.IntAssembler{TypeName: "gendemo.Int"}.BeginMap(0)
}
func (_Int__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.IntAssembler{TypeName: "gendemo.Int"}.BeginList(0)
}
func (na *_Int__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.IntAssembler{TypeName: "gendemo.Int"}.AssignNull()
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	}
	panic("unreachable")
}
func (_Int__Assembler) AssignBool(bool) error {
	return mixins.IntAssembler{TypeName: "gendemo.Int"}.AssignBool(false)
}
func (na *_Int__Assembler) AssignInt(v int64) error {
	switch *na.m {
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	}
	na.w.x = v
	*na.m = schema.Maybe_Value
	return nil
}
func (_Int__Assembler) AssignFloat(float64) error {
	return mixins.IntAssembler{TypeName: "gendemo.Int"}.AssignFloat(0)
}
func (_Int__Assembler) AssignString(string) error {
	return mixins.IntAssembler{TypeName: "gendemo.Int"}.AssignString("")
}
func (_Int__Assembler) AssignBytes([]byte) error {
	return mixins.IntAssembler{TypeName: "gendemo.Int"}.AssignBytes(nil)
}
func (_Int__Assembler) AssignLink(datamodel.Link) error {
	return mixins.IntAssembler{TypeName: "gendemo.Int"}.AssignLink(nil)
}
func (na *_Int__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Int); ok {
		switch *na.m {
		case schema.Maybe_Value, schema.Maybe_Null:
			panic("invalid state: cannot assign into assembler that's already finished")
		}
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
	}
	if v2, err := v.AsInt(); err != nil {
		return err
	} else {
		return na.AssignInt(v2)
	}
}
func (_Int__Assembler) Prototype() datamodel.NodePrototype {
	return _Int__Prototype{}
}
func (Int) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Int) Representation() datamodel.Node {
	return (*_Int__Repr)(n)
}

type _Int__Repr = _Int

var _ datamodel.Node = &_Int__Repr{}

type _Int__ReprPrototype = _Int__Prototype
type _Int__ReprAssembler = _Int__Assembler

func (n *_Map__String__Msg3) Lookup(k String) Msg3 {
	v, exists := n.m[*k]
	if !exists {
		return nil
	}
	return v
}
func (n *_Map__String__Msg3) LookupMaybe(k String) MaybeMsg3 {
	v, exists := n.m[*k]
	if !exists {
		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}

func (n Map__String__Msg3) Iterator() *Map__String__Msg3__Itr {
	return &Map__String__Msg3__Itr{n, 0}
}

type Map__String__Msg3__Itr struct {
	n   Map__String__Msg3
	idx int
}

func (itr *Map__String__Msg3__Itr) Next() (k String, v Msg3) {
	if itr.idx >= len(itr.n.t) {
		return nil, nil
	}
	x := &itr.n.t[itr.idx]
	k = &x.k
	v = &x.v
	itr.idx++
	return
}
func (itr *Map__String__Msg3__Itr) Done() bool {
	return itr.idx >= len(itr.n.t)
}

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) IsAbsent() 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() datamodel.Node {
	switch m.m {
	case schema.Maybe_Absent:
		return datamodel.Absent
	case schema.Maybe_Null:
		return datamodel.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 _ datamodel.Node = (Map__String__Msg3)(&_Map__String__Msg3{})
var _ schema.TypedNode = (Map__String__Msg3)(&_Map__String__Msg3{})

func (Map__String__Msg3) Kind() datamodel.Kind {
	return datamodel.Kind_Map
}
func (n Map__String__Msg3) LookupByString(k string) (datamodel.Node, error) {
	var k2 _String
	if err := (_String__ReprPrototype{}).fromString(&k2, k); err != nil {
		return nil, err // TODO wrap in some kind of ErrInvalidKey
	}
	v, exists := n.m[k2]
	if !exists {
		return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(k)}
	}
	return v, nil
}
func (n Map__String__Msg3) LookupByNode(k datamodel.Node) (datamodel.Node, error) {
	k2, ok := k.(String)
	if !ok {
		panic("todo invalid key type error")
		// 'schema.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
	}
	v, exists := n.m[*k2]
	if !exists {
		return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(k2.String())}
	}
	return v, nil
}
func (Map__String__Msg3) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3"}.LookupByIndex(0)
}
func (n Map__String__Msg3) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return n.LookupByString(seg.String())
}
func (n Map__String__Msg3) MapIterator() datamodel.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 datamodel.Node, v datamodel.Node, _ error) {
	if itr.idx >= len(itr.n.t) {
		return nil, nil, datamodel.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() datamodel.ListIterator {
	return nil
}
func (n Map__String__Msg3) Length() int64 {
	return int64(len(n.t))
}
func (Map__String__Msg3) IsAbsent() bool {
	return false
}
func (Map__String__Msg3) IsNull() bool {
	return false
}
func (Map__String__Msg3) AsBool() (bool, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3"}.AsBool()
}
func (Map__String__Msg3) AsInt() (int64, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3"}.AsInt()
}
func (Map__String__Msg3) AsFloat() (float64, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3"}.AsFloat()
}
func (Map__String__Msg3) AsString() (string, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3"}.AsString()
}
func (Map__String__Msg3) AsBytes() ([]byte, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3"}.AsBytes()
}
func (Map__String__Msg3) AsLink() (datamodel.Link, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3"}.AsLink()
}
func (Map__String__Msg3) Prototype() datamodel.NodePrototype {
	return _Map__String__Msg3__Prototype{}
}

type _Map__String__Msg3__Prototype struct{}

func (_Map__String__Msg3__Prototype) NewBuilder() datamodel.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() datamodel.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__Builder) Reset() {
	var w _Map__String__Msg3
	var m schema.Maybe
	*nb = _Map__String__Msg3__Builder{_Map__String__Msg3__Assembler{w: &w, m: &m}}
}

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 int64) (datamodel.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
	}
	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 int64) (datamodel.ListAssembler, error) {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3"}.BeginList(0)
}
func (na *_Map__String__Msg3__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3"}.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 (_Map__String__Msg3__Assembler) AssignBool(bool) error {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3"}.AssignBool(false)
}
func (_Map__String__Msg3__Assembler) AssignInt(int64) error {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3"}.AssignInt(0)
}
func (_Map__String__Msg3__Assembler) AssignFloat(float64) error {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3"}.AssignFloat(0)
}
func (_Map__String__Msg3__Assembler) AssignString(string) error {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3"}.AssignString("")
}
func (_Map__String__Msg3__Assembler) AssignBytes([]byte) error {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3"}.AssignBytes(nil)
}
func (_Map__String__Msg3__Assembler) AssignLink(datamodel.Link) error {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3"}.AssignLink(nil)
}
func (na *_Map__String__Msg3__Assembler) AssignNode(v datamodel.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!")
		}
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
	}
	if v.Kind() != datamodel.Kind_Map {
		return datamodel.ErrWrongKind{TypeName: "gendemo.Map__String__Msg3", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()}
	}
	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) Prototype() datamodel.NodePrototype {
	return _Map__String__Msg3__Prototype{}
}
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) (datamodel.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__ReprPrototype{}).fromString(&k2, k); err != nil {
		return nil, err // TODO wrap in some kind of ErrInvalidKey
	}
	if _, exists := ma.w.m[k2]; exists {
		return nil, datamodel.ErrRepeatedMapKey{Key: &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() datamodel.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__Assembler) AssembleValue() datamodel.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) KeyPrototype() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (ma *_Map__String__Msg3__Assembler) ValuePrototype(_ string) datamodel.NodePrototype {
	return _Msg3__Prototype{}
}
func (Map__String__Msg3) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Map__String__Msg3) Representation() datamodel.Node {
	return (*_Map__String__Msg3__Repr)(n)
}

type _Map__String__Msg3__Repr _Map__String__Msg3

var _ datamodel.Node = &_Map__String__Msg3__Repr{}

func (_Map__String__Msg3__Repr) Kind() datamodel.Kind {
	return datamodel.Kind_Map
}
func (nr *_Map__String__Msg3__Repr) LookupByString(k string) (datamodel.Node, error) {
	v, err := (Map__String__Msg3)(nr).LookupByString(k)
	if err != nil || v == datamodel.Null {
		return v, err
	}
	return v.(Msg3).Representation(), nil
}
func (nr *_Map__String__Msg3__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) {
	v, err := (Map__String__Msg3)(nr).LookupByNode(k)
	if err != nil || v == datamodel.Null {
		return v, err
	}
	return v.(Msg3).Representation(), nil
}
func (_Map__String__Msg3__Repr) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3.Repr"}.LookupByIndex(0)
}
func (n _Map__String__Msg3__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return n.LookupByString(seg.String())
}
func (nr *_Map__String__Msg3__Repr) MapIterator() datamodel.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 datamodel.Node, v datamodel.Node, err error) {
	k, v, err = (*_Map__String__Msg3__MapItr)(itr).Next()
	if err != nil || v == datamodel.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() datamodel.ListIterator {
	return nil
}
func (rn *_Map__String__Msg3__Repr) Length() int64 {
	return int64(len(rn.t))
}
func (_Map__String__Msg3__Repr) IsAbsent() bool {
	return false
}
func (_Map__String__Msg3__Repr) IsNull() bool {
	return false
}
func (_Map__String__Msg3__Repr) AsBool() (bool, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3.Repr"}.AsBool()
}
func (_Map__String__Msg3__Repr) AsInt() (int64, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3.Repr"}.AsInt()
}
func (_Map__String__Msg3__Repr) AsFloat() (float64, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3.Repr"}.AsFloat()
}
func (_Map__String__Msg3__Repr) AsString() (string, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3.Repr"}.AsString()
}
func (_Map__String__Msg3__Repr) AsBytes() ([]byte, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3.Repr"}.AsBytes()
}
func (_Map__String__Msg3__Repr) AsLink() (datamodel.Link, error) {
	return mixins.Map{TypeName: "gendemo.Map__String__Msg3.Repr"}.AsLink()
}
func (_Map__String__Msg3__Repr) Prototype() datamodel.NodePrototype {
	return _Map__String__Msg3__ReprPrototype{}
}

type _Map__String__Msg3__ReprPrototype struct{}

func (_Map__String__Msg3__ReprPrototype) NewBuilder() datamodel.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() datamodel.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 int64) (datamodel.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
	}
	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 int64) (datamodel.ListAssembler, error) {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3.Repr"}.BeginList(0)
}
func (na *_Map__String__Msg3__ReprAssembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3.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 (_Map__String__Msg3__ReprAssembler) AssignBool(bool) error {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3.Repr"}.AssignBool(false)
}
func (_Map__String__Msg3__ReprAssembler) AssignInt(int64) error {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3.Repr"}.AssignInt(0)
}
func (_Map__String__Msg3__ReprAssembler) AssignFloat(float64) error {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3.Repr"}.AssignFloat(0)
}
func (_Map__String__Msg3__ReprAssembler) AssignString(string) error {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3.Repr"}.AssignString("")
}
func (_Map__String__Msg3__ReprAssembler) AssignBytes([]byte) error {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3.Repr"}.AssignBytes(nil)
}
func (_Map__String__Msg3__ReprAssembler) AssignLink(datamodel.Link) error {
	return mixins.MapAssembler{TypeName: "gendemo.Map__String__Msg3.Repr"}.AssignLink(nil)
}
func (na *_Map__String__Msg3__ReprAssembler) AssignNode(v datamodel.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!")
		}
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
	}
	if v.Kind() != datamodel.Kind_Map {
		return datamodel.ErrWrongKind{TypeName: "gendemo.Map__String__Msg3.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()}
	}
	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) Prototype() datamodel.NodePrototype {
	return _Map__String__Msg3__ReprPrototype{}
}
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) (datamodel.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__ReprPrototype{}).fromString(&k2, k); err != nil {
		return nil, err // TODO wrap in some kind of ErrInvalidKey
	}
	if _, exists := ma.w.m[k2]; exists {
		return nil, datamodel.ErrRepeatedMapKey{Key: &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() datamodel.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() datamodel.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) KeyPrototype() datamodel.NodePrototype {
	return _String__ReprPrototype{}
}
func (ma *_Map__String__Msg3__ReprAssembler) ValuePrototype(_ string) datamodel.NodePrototype {
	return _Msg3__ReprPrototype{}
}

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

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) IsAbsent() bool {
	return m.m == schema.Maybe_Absent
}
func (m MaybeMsg3) Exists() bool {
	return m.m == schema.Maybe_Value
}
func (m MaybeMsg3) AsNode() datamodel.Node {
	switch m.m {
	case schema.Maybe_Absent:
		return datamodel.Absent
	case schema.Maybe_Null:
		return datamodel.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
}

var (
	fieldName__Msg3_Whee = _String{"whee"}
	fieldName__Msg3_Woot = _String{"woot"}
	fieldName__Msg3_Waga = _String{"waga"}
)
var _ datamodel.Node = (Msg3)(&_Msg3{})
var _ schema.TypedNode = (Msg3)(&_Msg3{})

func (Msg3) Kind() datamodel.Kind {
	return datamodel.Kind_Map
}
func (n Msg3) LookupByString(key string) (datamodel.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*/, Field: datamodel.PathSegmentOfString(key)}
	}
}
func (n Msg3) LookupByNode(key datamodel.Node) (datamodel.Node, error) {
	ks, err := key.AsString()
	if err != nil {
		return nil, err
	}
	return n.LookupByString(ks)
}
func (Msg3) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.Map{TypeName: "gendemo.Msg3"}.LookupByIndex(0)
}
func (n Msg3) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return n.LookupByString(seg.String())
}
func (n Msg3) MapIterator() datamodel.MapIterator {
	return &_Msg3__MapItr{n, 0}
}

type _Msg3__MapItr struct {
	n   Msg3
	idx int
}

func (itr *_Msg3__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) {
	if itr.idx >= 3 {
		return nil, nil, datamodel.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() datamodel.ListIterator {
	return nil
}
func (Msg3) Length() int64 {
	return 3
}
func (Msg3) IsAbsent() bool {
	return false
}
func (Msg3) IsNull() bool {
	return false
}
func (Msg3) AsBool() (bool, error) {
	return mixins.Map{TypeName: "gendemo.Msg3"}.AsBool()
}
func (Msg3) AsInt() (int64, error) {
	return mixins.Map{TypeName: "gendemo.Msg3"}.AsInt()
}
func (Msg3) AsFloat() (float64, error) {
	return mixins.Map{TypeName: "gendemo.Msg3"}.AsFloat()
}
func (Msg3) AsString() (string, error) {
	return mixins.Map{TypeName: "gendemo.Msg3"}.AsString()
}
func (Msg3) AsBytes() ([]byte, error) {
	return mixins.Map{TypeName: "gendemo.Msg3"}.AsBytes()
}
func (Msg3) AsLink() (datamodel.Link, error) {
	return mixins.Map{TypeName: "gendemo.Msg3"}.AsLink()
}
func (Msg3) Prototype() datamodel.NodePrototype {
	return _Msg3__Prototype{}
}

type _Msg3__Prototype struct{}

func (_Msg3__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Msg3__Builder
	nb.Reset()
	return &nb
}

type _Msg3__Builder struct {
	_Msg3__Assembler
}

func (nb *_Msg3__Builder) Build() datamodel.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 *_Msg3__Builder) Reset() {
	var w _Msg3
	var m schema.Maybe
	*nb = _Msg3__Builder{_Msg3__Assembler{w: &w, m: &m}}
}

type _Msg3__Assembler struct {
	w     *_Msg3
	m     *schema.Maybe
	state maState
	s     int
	f     int

	cm      schema.Maybe
	ca_whee _Int__Assembler
	ca_woot _Int__Assembler
	ca_waga _Int__Assembler
}

func (na *_Msg3__Assembler) reset() {
	na.state = maState_initial
	na.s = 0
	na.ca_whee.reset()
	na.ca_woot.reset()
	na.ca_waga.reset()
}

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(int64) (datamodel.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 = &_Msg3{}
	}
	return na, nil
}
func (_Msg3__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3"}.BeginList(0)
}
func (na *_Msg3__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.MapAssembler{TypeName: "gendemo.Msg3"}.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 (_Msg3__Assembler) AssignBool(bool) error {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3"}.AssignBool(false)
}
func (_Msg3__Assembler) AssignInt(int64) error {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3"}.AssignInt(0)
}
func (_Msg3__Assembler) AssignFloat(float64) error {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3"}.AssignFloat(0)
}
func (_Msg3__Assembler) AssignString(string) error {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3"}.AssignString("")
}
func (_Msg3__Assembler) AssignBytes([]byte) error {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3"}.AssignBytes(nil)
}
func (_Msg3__Assembler) AssignLink(datamodel.Link) error {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3"}.AssignLink(nil)
}
func (na *_Msg3__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_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.Kind() != datamodel.Kind_Map {
		return datamodel.ErrWrongKind{TypeName: "gendemo.Msg3", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()}
	}
	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) Prototype() datamodel.NodePrototype {
	return _Msg3__Prototype{}
}
func (ma *_Msg3__Assembler) valueFinishTidy() bool {
	switch ma.f {
	case 0:
		switch ma.cm {
		case schema.Maybe_Value:
			ma.ca_whee.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_woot.w = nil
			ma.cm = schema.Maybe_Absent
			ma.state = maState_initial
			return true
		default:
			return false
		}
	case 2:
		switch ma.cm {
		case schema.Maybe_Value:
			ma.ca_waga.w = nil
			ma.cm = schema.Maybe_Absent
			ma.state = maState_initial
			return true
		default:
			return false
		}
	default:
		panic("unreachable")
	}
}
func (ma *_Msg3__Assembler) AssembleEntry(k string) (datamodel.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 "whee":
		if ma.s&fieldBit__Msg3_Whee != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Msg3_Whee}
		}
		ma.s += fieldBit__Msg3_Whee
		ma.state = maState_midValue
		ma.f = 0
		ma.ca_whee.w = &ma.w.whee
		ma.ca_whee.m = &ma.cm
		return &ma.ca_whee, nil
	case "woot":
		if ma.s&fieldBit__Msg3_Woot != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Msg3_Woot}
		}
		ma.s += fieldBit__Msg3_Woot
		ma.state = maState_midValue
		ma.f = 1
		ma.ca_woot.w = &ma.w.woot
		ma.ca_woot.m = &ma.cm
		return &ma.ca_woot, nil
	case "waga":
		if ma.s&fieldBit__Msg3_Waga != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Msg3_Waga}
		}
		ma.s += fieldBit__Msg3_Waga
		ma.state = maState_midValue
		ma.f = 2
		ma.ca_waga.w = &ma.w.waga
		ma.ca_waga.m = &ma.cm
		return &ma.ca_waga, nil
	}
	return nil, schema.ErrInvalidKey{TypeName: "gendemo.Msg3", Key: &_String{k}}
}
func (ma *_Msg3__Assembler) AssembleKey() datamodel.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 (*_Msg3__KeyAssembler)(ma)
}
func (ma *_Msg3__Assembler) AssembleValue() datamodel.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_whee.w = &ma.w.whee
		ma.ca_whee.m = &ma.cm
		return &ma.ca_whee
	case 1:
		ma.ca_woot.w = &ma.w.woot
		ma.ca_woot.m = &ma.cm
		return &ma.ca_woot
	case 2:
		ma.ca_waga.w = &ma.w.waga
		ma.ca_waga.m = &ma.cm
		return &ma.ca_waga
	default:
		panic("unreachable")
	}
}
func (ma *_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")
	}
	if ma.s&fieldBits__Msg3_sufficient != fieldBits__Msg3_sufficient {
		err := schema.ErrMissingRequiredField{Missing: make([]string, 0)}
		if ma.s&fieldBit__Msg3_Whee == 0 {
			err.Missing = append(err.Missing, "whee")
		}
		if ma.s&fieldBit__Msg3_Woot == 0 {
			err.Missing = append(err.Missing, "woot")
		}
		if ma.s&fieldBit__Msg3_Waga == 0 {
			err.Missing = append(err.Missing, "waga")
		}
		return err
	}
	ma.state = maState_finished
	*ma.m = schema.Maybe_Value
	return nil
}
func (ma *_Msg3__Assembler) KeyPrototype() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (ma *_Msg3__Assembler) ValuePrototype(k string) datamodel.NodePrototype {
	panic("todo structbuilder mapassembler valueprototype")
}

type _Msg3__KeyAssembler _Msg3__Assembler

func (_Msg3__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.KeyAssembler"}.BeginMap(0)
}
func (_Msg3__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.KeyAssembler"}.BeginList(0)
}
func (na *_Msg3__KeyAssembler) AssignNull() error {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.KeyAssembler"}.AssignNull()
}
func (_Msg3__KeyAssembler) AssignBool(bool) error {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.KeyAssembler"}.AssignBool(false)
}
func (_Msg3__KeyAssembler) AssignInt(int64) error {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.KeyAssembler"}.AssignInt(0)
}
func (_Msg3__KeyAssembler) AssignFloat(float64) error {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.KeyAssembler"}.AssignFloat(0)
}
func (ka *_Msg3__KeyAssembler) AssignString(k string) error {
	if ka.state != maState_midKey {
		panic("misuse: KeyAssembler held beyond its valid lifetime")
	}
	switch k {
	case "whee":
		if ka.s&fieldBit__Msg3_Whee != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Msg3_Whee}
		}
		ka.s += fieldBit__Msg3_Whee
		ka.state = maState_expectValue
		ka.f = 0
		return nil
	case "woot":
		if ka.s&fieldBit__Msg3_Woot != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Msg3_Woot}
		}
		ka.s += fieldBit__Msg3_Woot
		ka.state = maState_expectValue
		ka.f = 1
		return nil
	case "waga":
		if ka.s&fieldBit__Msg3_Waga != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Msg3_Waga}
		}
		ka.s += fieldBit__Msg3_Waga
		ka.state = maState_expectValue
		ka.f = 2
		return nil
	default:
		return schema.ErrInvalidKey{TypeName: "gendemo.Msg3", Key: &_String{k}}
	}
}
func (_Msg3__KeyAssembler) AssignBytes([]byte) error {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.KeyAssembler"}.AssignBytes(nil)
}
func (_Msg3__KeyAssembler) AssignLink(datamodel.Link) error {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.KeyAssembler"}.AssignLink(nil)
}
func (ka *_Msg3__KeyAssembler) AssignNode(v datamodel.Node) error {
	if v2, err := v.AsString(); err != nil {
		return err
	} else {
		return ka.AssignString(v2)
	}
}
func (_Msg3__KeyAssembler) Prototype() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (Msg3) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Msg3) Representation() datamodel.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 _ datamodel.Node = &_Msg3__Repr{}

func (_Msg3__Repr) Kind() datamodel.Kind {
	return datamodel.Kind_Map
}
func (n *_Msg3__Repr) LookupByString(key string) (datamodel.Node, error) {
	switch key {
	case "whee":
		return n.whee.Representation(), nil
	case "woot":
		return n.woot.Representation(), nil
	case "waga":
		return n.waga.Representation(), nil
	default:
		return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)}
	}
}
func (n *_Msg3__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) {
	ks, err := key.AsString()
	if err != nil {
		return nil, err
	}
	return n.LookupByString(ks)
}
func (_Msg3__Repr) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.Map{TypeName: "gendemo.Msg3.Repr"}.LookupByIndex(0)
}
func (n _Msg3__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return n.LookupByString(seg.String())
}
func (n *_Msg3__Repr) MapIterator() datamodel.MapIterator {
	return &_Msg3__ReprMapItr{n, 0}
}

type _Msg3__ReprMapItr struct {
	n   *_Msg3__Repr
	idx int
}

func (itr *_Msg3__ReprMapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) {
	if itr.idx >= 3 {
		return nil, nil, datamodel.ErrIteratorOverread{}
	}
	switch itr.idx {
	case 0:
		k = &fieldName__Msg3_Whee_serial
		v = itr.n.whee.Representation()
	case 1:
		k = &fieldName__Msg3_Woot_serial
		v = itr.n.woot.Representation()
	case 2:
		k = &fieldName__Msg3_Waga_serial
		v = itr.n.waga.Representation()
	default:
		panic("unreachable")
	}
	itr.idx++
	return
}
func (itr *_Msg3__ReprMapItr) Done() bool {
	return itr.idx >= 3
}
func (_Msg3__Repr) ListIterator() datamodel.ListIterator {
	return nil
}
func (rn *_Msg3__Repr) Length() int64 {
	l := 3
	return int64(l)
}
func (_Msg3__Repr) IsAbsent() bool {
	return false
}
func (_Msg3__Repr) IsNull() bool {
	return false
}
func (_Msg3__Repr) AsBool() (bool, error) {
	return mixins.Map{TypeName: "gendemo.Msg3.Repr"}.AsBool()
}
func (_Msg3__Repr) AsInt() (int64, error) {
	return mixins.Map{TypeName: "gendemo.Msg3.Repr"}.AsInt()
}
func (_Msg3__Repr) AsFloat() (float64, error) {
	return mixins.Map{TypeName: "gendemo.Msg3.Repr"}.AsFloat()
}
func (_Msg3__Repr) AsString() (string, error) {
	return mixins.Map{TypeName: "gendemo.Msg3.Repr"}.AsString()
}
func (_Msg3__Repr) AsBytes() ([]byte, error) {
	return mixins.Map{TypeName: "gendemo.Msg3.Repr"}.AsBytes()
}
func (_Msg3__Repr) AsLink() (datamodel.Link, error) {
	return mixins.Map{TypeName: "gendemo.Msg3.Repr"}.AsLink()
}
func (_Msg3__Repr) Prototype() datamodel.NodePrototype {
	return _Msg3__ReprPrototype{}
}

type _Msg3__ReprPrototype struct{}

func (_Msg3__ReprPrototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Msg3__ReprBuilder
	nb.Reset()
	return &nb
}

type _Msg3__ReprBuilder struct {
	_Msg3__ReprAssembler
}

func (nb *_Msg3__ReprBuilder) Build() datamodel.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 *_Msg3__ReprBuilder) Reset() {
	var w _Msg3
	var m schema.Maybe
	*nb = _Msg3__ReprBuilder{_Msg3__ReprAssembler{w: &w, m: &m}}
}

type _Msg3__ReprAssembler struct {
	w     *_Msg3
	m     *schema.Maybe
	state maState
	s     int
	f     int

	cm      schema.Maybe
	ca_whee _Int__ReprAssembler
	ca_woot _Int__ReprAssembler
	ca_waga _Int__ReprAssembler
}

func (na *_Msg3__ReprAssembler) reset() {
	na.state = maState_initial
	na.s = 0
	na.ca_whee.reset()
	na.ca_woot.reset()
	na.ca_waga.reset()
}
func (na *_Msg3__ReprAssembler) BeginMap(int64) (datamodel.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 = &_Msg3{}
	}
	return na, nil
}
func (_Msg3__ReprAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3.Repr"}.BeginList(0)
}
func (na *_Msg3__ReprAssembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.MapAssembler{TypeName: "gendemo.Msg3.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 (_Msg3__ReprAssembler) AssignBool(bool) error {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3.Repr"}.AssignBool(false)
}
func (_Msg3__ReprAssembler) AssignInt(int64) error {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3.Repr"}.AssignInt(0)
}
func (_Msg3__ReprAssembler) AssignFloat(float64) error {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3.Repr"}.AssignFloat(0)
}
func (_Msg3__ReprAssembler) AssignString(string) error {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3.Repr"}.AssignString("")
}
func (_Msg3__ReprAssembler) AssignBytes([]byte) error {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3.Repr"}.AssignBytes(nil)
}
func (_Msg3__ReprAssembler) AssignLink(datamodel.Link) error {
	return mixins.MapAssembler{TypeName: "gendemo.Msg3.Repr"}.AssignLink(nil)
}
func (na *_Msg3__ReprAssembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_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.Kind() != datamodel.Kind_Map {
		return datamodel.ErrWrongKind{TypeName: "gendemo.Msg3.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()}
	}
	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) Prototype() datamodel.NodePrototype {
	return _Msg3__ReprPrototype{}
}
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")
	}
}
func (ma *_Msg3__ReprAssembler) AssembleEntry(k string) (datamodel.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 "whee":
		if ma.s&fieldBit__Msg3_Whee != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Msg3_Whee_serial}
		}
		ma.s += fieldBit__Msg3_Whee
		ma.state = maState_midValue
		ma.f = 0
		ma.ca_whee.w = &ma.w.whee
		ma.ca_whee.m = &ma.cm
		return &ma.ca_whee, nil
	case "woot":
		if ma.s&fieldBit__Msg3_Woot != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Msg3_Woot_serial}
		}
		ma.s += fieldBit__Msg3_Woot
		ma.state = maState_midValue
		ma.f = 1
		ma.ca_woot.w = &ma.w.woot
		ma.ca_woot.m = &ma.cm
		return &ma.ca_woot, nil
	case "waga":
		if ma.s&fieldBit__Msg3_Waga != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Msg3_Waga_serial}
		}
		ma.s += fieldBit__Msg3_Waga
		ma.state = maState_midValue
		ma.f = 2
		ma.ca_waga.w = &ma.w.waga
		ma.ca_waga.m = &ma.cm
		return &ma.ca_waga, nil
	default:
	}
	return nil, schema.ErrInvalidKey{TypeName: "gendemo.Msg3.Repr", Key: &_String{k}}
}
func (ma *_Msg3__ReprAssembler) AssembleKey() datamodel.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 (*_Msg3__ReprKeyAssembler)(ma)
}
func (ma *_Msg3__ReprAssembler) AssembleValue() datamodel.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_whee.w = &ma.w.whee
		ma.ca_whee.m = &ma.cm
		return &ma.ca_whee
	case 1:
		ma.ca_woot.w = &ma.w.woot
		ma.ca_woot.m = &ma.cm
		return &ma.ca_woot
	case 2:
		ma.ca_waga.w = &ma.w.waga
		ma.ca_waga.m = &ma.cm
		return &ma.ca_waga
	default:
		panic("unreachable")
	}
}
func (ma *_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")
	}
	if ma.s&fieldBits__Msg3_sufficient != fieldBits__Msg3_sufficient {
		err := schema.ErrMissingRequiredField{Missing: make([]string, 0)}
		if ma.s&fieldBit__Msg3_Whee == 0 {
			err.Missing = append(err.Missing, "whee")
		}
		if ma.s&fieldBit__Msg3_Woot == 0 {
			err.Missing = append(err.Missing, "woot")
		}
		if ma.s&fieldBit__Msg3_Waga == 0 {
			err.Missing = append(err.Missing, "waga")
		}
		return err
	}
	ma.state = maState_finished
	*ma.m = schema.Maybe_Value
	return nil
}
func (ma *_Msg3__ReprAssembler) KeyPrototype() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (ma *_Msg3__ReprAssembler) ValuePrototype(k string) datamodel.NodePrototype {
	panic("todo structbuilder mapassembler repr valueprototype")
}

type _Msg3__ReprKeyAssembler _Msg3__ReprAssembler

func (_Msg3__ReprKeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.Repr.KeyAssembler"}.BeginMap(0)
}
func (_Msg3__ReprKeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.Repr.KeyAssembler"}.BeginList(0)
}
func (na *_Msg3__ReprKeyAssembler) AssignNull() error {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.Repr.KeyAssembler"}.AssignNull()
}
func (_Msg3__ReprKeyAssembler) AssignBool(bool) error {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.Repr.KeyAssembler"}.AssignBool(false)
}
func (_Msg3__ReprKeyAssembler) AssignInt(int64) error {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.Repr.KeyAssembler"}.AssignInt(0)
}
func (_Msg3__ReprKeyAssembler) AssignFloat(float64) error {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.Repr.KeyAssembler"}.AssignFloat(0)
}
func (ka *_Msg3__ReprKeyAssembler) AssignString(k string) error {
	if ka.state != maState_midKey {
		panic("misuse: KeyAssembler held beyond its valid lifetime")
	}
	switch k {
	case "whee":
		if ka.s&fieldBit__Msg3_Whee != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Msg3_Whee_serial}
		}
		ka.s += fieldBit__Msg3_Whee
		ka.state = maState_expectValue
		ka.f = 0
		return nil
	case "woot":
		if ka.s&fieldBit__Msg3_Woot != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Msg3_Woot_serial}
		}
		ka.s += fieldBit__Msg3_Woot
		ka.state = maState_expectValue
		ka.f = 1
		return nil
	case "waga":
		if ka.s&fieldBit__Msg3_Waga != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Msg3_Waga_serial}
		}
		ka.s += fieldBit__Msg3_Waga
		ka.state = maState_expectValue
		ka.f = 2
		return nil
	}
	return schema.ErrInvalidKey{TypeName: "gendemo.Msg3.Repr", Key: &_String{k}}
}
func (_Msg3__ReprKeyAssembler) AssignBytes([]byte) error {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.Repr.KeyAssembler"}.AssignBytes(nil)
}
func (_Msg3__ReprKeyAssembler) AssignLink(datamodel.Link) error {
	return mixins.StringAssembler{TypeName: "gendemo.Msg3.Repr.KeyAssembler"}.AssignLink(nil)
}
func (ka *_Msg3__ReprKeyAssembler) AssignNode(v datamodel.Node) error {
	if v2, err := v.AsString(); err != nil {
		return err
	} else {
		return ka.AssignString(v2)
	}
}
func (_Msg3__ReprKeyAssembler) Prototype() datamodel.NodePrototype {
	return _String__Prototype{}
}

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() datamodel.Node {
	switch m.m {
	case schema.Maybe_Absent:
		return datamodel.Absent
	case schema.Maybe_Null:
		return datamodel.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 _ datamodel.Node = (String)(&_String{})
var _ schema.TypedNode = (String)(&_String{})

func (String) Kind() datamodel.Kind {
	return datamodel.Kind_String
}
func (String) LookupByString(string) (datamodel.Node, error) {
	return mixins.String{TypeName: "gendemo.String"}.LookupByString("")
}
func (String) LookupByNode(datamodel.Node) (datamodel.Node, error) {
	return mixins.String{TypeName: "gendemo.String"}.LookupByNode(nil)
}
func (String) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.String{TypeName: "gendemo.String"}.LookupByIndex(0)
}
func (String) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return mixins.String{TypeName: "gendemo.String"}.LookupBySegment(seg)
}
func (String) MapIterator() datamodel.MapIterator {
	return nil
}
func (String) ListIterator() datamodel.ListIterator {
	return nil
}
func (String) Length() int64 {
	return -1
}
func (String) IsAbsent() bool {
	return false
}
func (String) IsNull() bool {
	return false
}
func (String) AsBool() (bool, error) {
	return mixins.String{TypeName: "gendemo.String"}.AsBool()
}
func (String) AsInt() (int64, error) {
	return mixins.String{TypeName: "gendemo.String"}.AsInt()
}
func (String) AsFloat() (float64, error) {
	return mixins.String{TypeName: "gendemo.String"}.AsFloat()
}
func (n String) AsString() (string, error) {
	return n.x, nil
}
func (String) AsBytes() ([]byte, error) {
	return mixins.String{TypeName: "gendemo.String"}.AsBytes()
}
func (String) AsLink() (datamodel.Link, error) {
	return mixins.String{TypeName: "gendemo.String"}.AsLink()
}
func (String) Prototype() datamodel.NodePrototype {
	return _String__Prototype{}
}

type _String__Prototype struct{}

func (_String__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _String__Builder
	nb.Reset()
	return &nb
}

type _String__Builder struct {
	_String__Assembler
}

func (nb *_String__Builder) Build() datamodel.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 int64) (datamodel.MapAssembler, error) {
	return mixins.StringAssembler{TypeName: "gendemo.String"}.BeginMap(0)
}
func (_String__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.StringAssembler{TypeName: "gendemo.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{TypeName: "gendemo.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{TypeName: "gendemo.String"}.AssignBool(false)
}
func (_String__Assembler) AssignInt(int64) error {
	return mixins.StringAssembler{TypeName: "gendemo.String"}.AssignInt(0)
}
func (_String__Assembler) AssignFloat(float64) error {
	return mixins.StringAssembler{TypeName: "gendemo.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")
	}
	na.w.x = v
	*na.m = schema.Maybe_Value
	return nil
}
func (_String__Assembler) AssignBytes([]byte) error {
	return mixins.StringAssembler{TypeName: "gendemo.String"}.AssignBytes(nil)
}
func (_String__Assembler) AssignLink(datamodel.Link) error {
	return mixins.StringAssembler{TypeName: "gendemo.String"}.AssignLink(nil)
}
func (na *_String__Assembler) AssignNode(v datamodel.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")
		}
		*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() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (String) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n String) Representation() datamodel.Node {
	return (*_String__Repr)(n)
}

type _String__Repr = _String

var _ datamodel.Node = &_String__Repr{}

type _String__ReprPrototype = _String__Prototype
type _String__ReprAssembler = _String__Assembler

func (n _UnionKinded) AsInterface() _UnionKinded__iface {
	switch n.tag {
	case 1:
		return &n.x1
	case 2:
		return &n.x2
	case 3:
		return &n.x3
	default:
		panic("invalid union state; how did you create this object?")
	}
}

type _UnionKinded__Maybe struct {
	m schema.Maybe
	v UnionKinded
}
type MaybeUnionKinded = *_UnionKinded__Maybe

func (m MaybeUnionKinded) IsNull() bool {
	return m.m == schema.Maybe_Null
}
func (m MaybeUnionKinded) IsAbsent() bool {
	return m.m == schema.Maybe_Absent
}
func (m MaybeUnionKinded) Exists() bool {
	return m.m == schema.Maybe_Value
}
func (m MaybeUnionKinded) AsNode() datamodel.Node {
	switch m.m {
	case schema.Maybe_Absent:
		return datamodel.Absent
	case schema.Maybe_Null:
		return datamodel.Null
	case schema.Maybe_Value:
		return m.v
	default:
		panic("unreachable")
	}
}
func (m MaybeUnionKinded) Must() UnionKinded {
	if !m.Exists() {
		panic("unbox of a maybe rejected")
	}
	return m.v
}

var (
	memberName__UnionKinded_Foo = _String{"Foo"}
	memberName__UnionKinded_Bar = _String{"Bar"}
	memberName__UnionKinded_Baz = _String{"Baz"}
)
var _ datamodel.Node = (UnionKinded)(&_UnionKinded{})
var _ schema.TypedNode = (UnionKinded)(&_UnionKinded{})

func (UnionKinded) Kind() datamodel.Kind {
	return datamodel.Kind_Map
}
func (n UnionKinded) LookupByString(key string) (datamodel.Node, error) {
	switch key {
	case "Foo":
		if n.tag != 1 {
			return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)}
		}
		return &n.x1, nil
	case "Bar":
		if n.tag != 2 {
			return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)}
		}
		return &n.x2, nil
	case "Baz":
		if n.tag != 3 {
			return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfString(key)}
		}
		return &n.x3, nil
	default:
		return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)}
	}
}
func (n UnionKinded) LookupByNode(key datamodel.Node) (datamodel.Node, error) {
	ks, err := key.AsString()
	if err != nil {
		return nil, err
	}
	return n.LookupByString(ks)
}
func (UnionKinded) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.Map{TypeName: "gendemo.UnionKinded"}.LookupByIndex(0)
}
func (n UnionKinded) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return n.LookupByString(seg.String())
}
func (n UnionKinded) MapIterator() datamodel.MapIterator {
	return &_UnionKinded__MapItr{n, false}
}

type _UnionKinded__MapItr struct {
	n    UnionKinded
	done bool
}

func (itr *_UnionKinded__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) {
	if itr.done {
		return nil, nil, datamodel.ErrIteratorOverread{}
	}
	switch itr.n.tag {
	case 1:
		k, v = &memberName__UnionKinded_Foo, &itr.n.x1
	case 2:
		k, v = &memberName__UnionKinded_Bar, &itr.n.x2
	case 3:
		k, v = &memberName__UnionKinded_Baz, &itr.n.x3
	default:
		panic("unreachable")
	}
	itr.done = true
	return
}
func (itr *_UnionKinded__MapItr) Done() bool {
	return itr.done
}

func (UnionKinded) ListIterator() datamodel.ListIterator {
	return nil
}
func (UnionKinded) Length() int64 {
	return 1
}
func (UnionKinded) IsAbsent() bool {
	return false
}
func (UnionKinded) IsNull() bool {
	return false
}
func (UnionKinded) AsBool() (bool, error) {
	return mixins.Map{TypeName: "gendemo.UnionKinded"}.AsBool()
}
func (UnionKinded) AsInt() (int64, error) {
	return mixins.Map{TypeName: "gendemo.UnionKinded"}.AsInt()
}
func (UnionKinded) AsFloat() (float64, error) {
	return mixins.Map{TypeName: "gendemo.UnionKinded"}.AsFloat()
}
func (UnionKinded) AsString() (string, error) {
	return mixins.Map{TypeName: "gendemo.UnionKinded"}.AsString()
}
func (UnionKinded) AsBytes() ([]byte, error) {
	return mixins.Map{TypeName: "gendemo.UnionKinded"}.AsBytes()
}
func (UnionKinded) AsLink() (datamodel.Link, error) {
	return mixins.Map{TypeName: "gendemo.UnionKinded"}.AsLink()
}
func (UnionKinded) Prototype() datamodel.NodePrototype {
	return _UnionKinded__Prototype{}
}

type _UnionKinded__Prototype struct{}

func (_UnionKinded__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _UnionKinded__Builder
	nb.Reset()
	return &nb
}

type _UnionKinded__Builder struct {
	_UnionKinded__Assembler
}

func (nb *_UnionKinded__Builder) Build() datamodel.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 *_UnionKinded__Builder) Reset() {
	var w _UnionKinded
	var m schema.Maybe
	*nb = _UnionKinded__Builder{_UnionKinded__Assembler{w: &w, m: &m}}
}

type _UnionKinded__Assembler struct {
	w     *_UnionKinded
	m     *schema.Maybe
	state maState

	cm  schema.Maybe
	ca1 _Foo__Assembler

	ca2 _Bar__Assembler

	ca3 _Baz__Assembler
	ca  uint
}

func (na *_UnionKinded__Assembler) reset() {
	na.state = maState_initial
	switch na.ca {
	case 0:
		return
	case 1:
		na.ca1.reset()

	case 2:
		na.ca2.reset()

	case 3:
		na.ca3.reset()
	default:
		panic("unreachable")
	}
	na.ca = 0
	na.cm = schema.Maybe_Absent
}
func (na *_UnionKinded__Assembler) BeginMap(int64) (datamodel.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 = &_UnionKinded{}
	}
	return na, nil
}
func (_UnionKinded__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.MapAssembler{TypeName: "gendemo.UnionKinded"}.BeginList(0)
}
func (na *_UnionKinded__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.MapAssembler{TypeName: "gendemo.UnionKinded"}.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 (_UnionKinded__Assembler) AssignBool(bool) error {
	return mixins.MapAssembler{TypeName: "gendemo.UnionKinded"}.AssignBool(false)
}
func (_UnionKinded__Assembler) AssignInt(int64) error {
	return mixins.MapAssembler{TypeName: "gendemo.UnionKinded"}.AssignInt(0)
}
func (_UnionKinded__Assembler) AssignFloat(float64) error {
	return mixins.MapAssembler{TypeName: "gendemo.UnionKinded"}.AssignFloat(0)
}
func (_UnionKinded__Assembler) AssignString(string) error {
	return mixins.MapAssembler{TypeName: "gendemo.UnionKinded"}.AssignString("")
}
func (_UnionKinded__Assembler) AssignBytes([]byte) error {
	return mixins.MapAssembler{TypeName: "gendemo.UnionKinded"}.AssignBytes(nil)
}
func (_UnionKinded__Assembler) AssignLink(datamodel.Link) error {
	return mixins.MapAssembler{TypeName: "gendemo.UnionKinded"}.AssignLink(nil)
}
func (na *_UnionKinded__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_UnionKinded); 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.Kind() != datamodel.Kind_Map {
		return datamodel.ErrWrongKind{TypeName: "gendemo.UnionKinded", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: v.Kind()}
	}
	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 (_UnionKinded__Assembler) Prototype() datamodel.NodePrototype {
	return _UnionKinded__Prototype{}
}
func (ma *_UnionKinded__Assembler) valueFinishTidy() bool {
	switch ma.cm {
	case schema.Maybe_Value:
		ma.state = maState_initial
		return true
	default:
		return false
	}
}
func (ma *_UnionKinded__Assembler) AssembleEntry(k string) (datamodel.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 for the moment, but we'll still be erroring shortly.
	case maState_finished:
		panic("invalid state: AssembleEntry cannot be called on an assembler that's already finished")
	}
	if ma.ca != 0 {
		return nil, schema.ErrNotUnionStructure{TypeName: "gendemo.UnionKinded", Detail: "cannot add another entry -- a union can only contain one thing!"}
	}
	switch k {
	case "Foo":
		ma.state = maState_midValue
		ma.ca = 1
		ma.w.tag = 1
		ma.ca1.w = &ma.w.x1
		ma.ca1.m = &ma.cm
		return &ma.ca1, nil
	case "Bar":
		ma.state = maState_midValue
		ma.ca = 2
		ma.w.tag = 2
		ma.ca2.w = &ma.w.x2
		ma.ca2.m = &ma.cm
		return &ma.ca2, nil
	case "Baz":
		ma.state = maState_midValue
		ma.ca = 3
		ma.w.tag = 3
		ma.ca3.w = &ma.w.x3
		ma.ca3.m = &ma.cm
		return &ma.ca3, nil
	}
	return nil, schema.ErrInvalidKey{TypeName: "gendemo.UnionKinded", Key: &_String{k}}
}
func (ma *_UnionKinded__Assembler) AssembleKey() datamodel.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 for the moment, but we'll still be erroring shortly... or rather, the keyassembler will be.
	case maState_finished:
		panic("invalid state: AssembleKey cannot be called on an assembler that's already finished")
	}
	ma.state = maState_midKey
	return (*_UnionKinded__KeyAssembler)(ma)
}
func (ma *_UnionKinded__Assembler) AssembleValue() datamodel.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.ca {
	case 1:
		ma.ca1.w = &ma.w.x1
		ma.ca1.m = &ma.cm
		return &ma.ca1
	case 2:
		ma.ca2.w = &ma.w.x2
		ma.ca2.m = &ma.cm
		return &ma.ca2
	case 3:
		ma.ca3.w = &ma.w.x3
		ma.ca3.m = &ma.cm
		return &ma.ca3
	default:
		panic("unreachable")
	}
}
func (ma *_UnionKinded__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")
	}
	if ma.ca == 0 {
		return schema.ErrNotUnionStructure{TypeName: "gendemo.UnionKinded", Detail: "a union must have exactly one entry (not none)!"}
	}
	ma.state = maState_finished
	*ma.m = schema.Maybe_Value
	return nil
}
func (ma *_UnionKinded__Assembler) KeyPrototype() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (ma *_UnionKinded__Assembler) ValuePrototype(k string) datamodel.NodePrototype {
	switch k {
	case "Foo":
		return _Foo__Prototype{}
	case "Bar":
		return _Bar__Prototype{}
	case "Baz":
		return _Baz__Prototype{}
	default:
		return nil
	}
}

type _UnionKinded__KeyAssembler _UnionKinded__Assembler

func (_UnionKinded__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.StringAssembler{TypeName: "gendemo.UnionKinded.KeyAssembler"}.BeginMap(0)
}
func (_UnionKinded__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.StringAssembler{TypeName: "gendemo.UnionKinded.KeyAssembler"}.BeginList(0)
}
func (na *_UnionKinded__KeyAssembler) AssignNull() error {
	return mixins.StringAssembler{TypeName: "gendemo.UnionKinded.KeyAssembler"}.AssignNull()
}
func (_UnionKinded__KeyAssembler) AssignBool(bool) error {
	return mixins.StringAssembler{TypeName: "gendemo.UnionKinded.KeyAssembler"}.AssignBool(false)
}
func (_UnionKinded__KeyAssembler) AssignInt(int64) error {
	return mixins.StringAssembler{TypeName: "gendemo.UnionKinded.KeyAssembler"}.AssignInt(0)
}
func (_UnionKinded__KeyAssembler) AssignFloat(float64) error {
	return mixins.StringAssembler{TypeName: "gendemo.UnionKinded.KeyAssembler"}.AssignFloat(0)
}
func (ka *_UnionKinded__KeyAssembler) AssignString(k string) error {
	if ka.state != maState_midKey {
		panic("misuse: KeyAssembler held beyond its valid lifetime")
	}
	if ka.ca != 0 {
		return schema.ErrNotUnionStructure{TypeName: "gendemo.UnionKinded", Detail: "cannot add another entry -- a union can only contain one thing!"}
	}
	switch k {
	case "Foo":
		ka.ca = 1
		ka.w.tag = 1
		ka.state = maState_expectValue
		return nil
	case "Bar":
		ka.ca = 2
		ka.w.tag = 2
		ka.state = maState_expectValue
		return nil
	case "Baz":
		ka.ca = 3
		ka.w.tag = 3
		ka.state = maState_expectValue
		return nil
	}
	return schema.ErrInvalidKey{TypeName: "gendemo.UnionKinded", Key: &_String{k}} // TODO: error quality: ErrInvalidUnionDiscriminant ?
}
func (_UnionKinded__KeyAssembler) AssignBytes([]byte) error {
	return mixins.StringAssembler{TypeName: "gendemo.UnionKinded.KeyAssembler"}.AssignBytes(nil)
}
func (_UnionKinded__KeyAssembler) AssignLink(datamodel.Link) error {
	return mixins.StringAssembler{TypeName: "gendemo.UnionKinded.KeyAssembler"}.AssignLink(nil)
}
func (ka *_UnionKinded__KeyAssembler) AssignNode(v datamodel.Node) error {
	if v2, err := v.AsString(); err != nil {
		return err
	} else {
		return ka.AssignString(v2)
	}
}
func (_UnionKinded__KeyAssembler) Prototype() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (UnionKinded) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n UnionKinded) Representation() datamodel.Node {
	return (*_UnionKinded__Repr)(n)
}

type _UnionKinded__Repr _UnionKinded

var _ datamodel.Node = &_UnionKinded__Repr{}

func (n *_UnionKinded__Repr) Kind() datamodel.Kind {
	switch n.tag {
	case 1:
		return datamodel.Kind_Int
	case 2:
		return datamodel.Kind_Bool
	case 3:
		return datamodel.Kind_String
	default:
		panic("unreachable")
	}
}
func (n *_UnionKinded__Repr) LookupByString(key string) (datamodel.Node, error) {
	return nil, datamodel.ErrWrongKind{TypeName: "gendemo.UnionKinded.Repr", MethodName: "LookupByString", AppropriateKind: datamodel.KindSet_JustMap, ActualKind: n.Kind()}
}
func (n *_UnionKinded__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) {
	return nil, datamodel.ErrWrongKind{TypeName: "gendemo.UnionKinded.Repr", MethodName: "LookupByNode", AppropriateKind: datamodel.KindSet_Recursive, ActualKind: n.Kind()}
}
func (n *_UnionKinded__Repr) LookupByIndex(idx int64) (datamodel.Node, error) {
	return nil, datamodel.ErrWrongKind{TypeName: "gendemo.UnionKinded.Repr", MethodName: "LookupByIndex", AppropriateKind: datamodel.KindSet_JustList, ActualKind: n.Kind()}
}
func (n *_UnionKinded__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return nil, datamodel.ErrWrongKind{TypeName: "gendemo.UnionKinded.Repr", MethodName: "LookupBySegment", AppropriateKind: datamodel.KindSet_Recursive, ActualKind: n.Kind()}
}
func (n *_UnionKinded__Repr) MapIterator() datamodel.MapIterator {
	return nil
}
func (n *_UnionKinded__Repr) ListIterator() datamodel.ListIterator {
	return nil
}
func (n *_UnionKinded__Repr) Length() int64 {
	return -1
}
func (n *_UnionKinded__Repr) IsAbsent() bool {
	return false
}
func (n *_UnionKinded__Repr) IsNull() bool {
	return false
}
func (n *_UnionKinded__Repr) AsBool() (bool, error) {
	switch n.tag {
	case 2:
		return n.x2.Representation().AsBool()
	default:
		return false, datamodel.ErrWrongKind{TypeName: "gendemo.UnionKinded.Repr", MethodName: "AsBool", AppropriateKind: datamodel.KindSet_JustBool, ActualKind: n.Kind()}
	}
}
func (n *_UnionKinded__Repr) AsInt() (int64, error) {
	switch n.tag {
	case 1:
		return n.x1.Representation().AsInt()
	default:
		return 0, datamodel.ErrWrongKind{TypeName: "gendemo.UnionKinded.Repr", MethodName: "AsInt", AppropriateKind: datamodel.KindSet_JustInt, ActualKind: n.Kind()}
	}
}
func (n *_UnionKinded__Repr) AsFloat() (float64, error) {
	return 0, datamodel.ErrWrongKind{TypeName: "gendemo.UnionKinded.Repr", MethodName: "AsFloat", AppropriateKind: datamodel.KindSet_JustFloat, ActualKind: n.Kind()}
}
func (n *_UnionKinded__Repr) AsString() (string, error) {
	switch n.tag {
	case 3:
		return n.x3.Representation().AsString()
	default:
		return "", datamodel.ErrWrongKind{TypeName: "gendemo.UnionKinded.Repr", MethodName: "AsString", AppropriateKind: datamodel.KindSet_JustString, ActualKind: n.Kind()}
	}
}
func (n *_UnionKinded__Repr) AsBytes() ([]byte, error) {
	return nil, datamodel.ErrWrongKind{TypeName: "gendemo.UnionKinded.Repr", MethodName: "AsBytes", AppropriateKind: datamodel.KindSet_JustBytes, ActualKind: n.Kind()}
}
func (n *_UnionKinded__Repr) AsLink() (datamodel.Link, error) {
	return nil, datamodel.ErrWrongKind{TypeName: "gendemo.UnionKinded.Repr", MethodName: "AsLink", AppropriateKind: datamodel.KindSet_JustLink, ActualKind: n.Kind()}
}
func (_UnionKinded__Repr) Prototype() datamodel.NodePrototype {
	return _UnionKinded__ReprPrototype{}
}

type _UnionKinded__ReprPrototype struct{}

func (_UnionKinded__ReprPrototype) NewBuilder() datamodel.NodeBuilder {
	var nb _UnionKinded__ReprBuilder
	nb.Reset()
	return &nb
}

type _UnionKinded__ReprBuilder struct {
	_UnionKinded__ReprAssembler
}

func (nb *_UnionKinded__ReprBuilder) Build() datamodel.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 *_UnionKinded__ReprBuilder) Reset() {
	var w _UnionKinded
	var m schema.Maybe
	*nb = _UnionKinded__ReprBuilder{_UnionKinded__ReprAssembler{w: &w, m: &m}}
}

type _UnionKinded__ReprAssembler struct {
	w   *_UnionKinded
	m   *schema.Maybe
	ca1 _Foo__ReprAssembler
	ca2 _Bar__ReprAssembler
	ca3 _Baz__ReprAssembler
	ca  uint
}

func (na *_UnionKinded__ReprAssembler) reset() {
	switch na.ca {
	case 0:
		return
	case 1:
		na.ca1.reset()
	case 2:
		na.ca2.reset()
	case 3:
		na.ca3.reset()
	default:
		panic("unreachable")
	}
	na.ca = 0
}
func (na *_UnionKinded__ReprAssembler) BeginMap(sizeHint int64) (datamodel.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: cannot assign into assembler that's already working on a larger structure!")
	}
	return nil, schema.ErrNotUnionStructure{TypeName: "gendemo.UnionKinded.Repr", Detail: "BeginMap called but is not valid for any of the kinds that are valid members of this union"}
}
func (na *_UnionKinded__ReprAssembler) BeginList(sizeHint int64) (datamodel.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: cannot assign into assembler that's already working on a larger structure!")
	}
	return nil, schema.ErrNotUnionStructure{TypeName: "gendemo.UnionKinded.Repr", Detail: "BeginList called but is not valid for any of the kinds that are valid members of this union"}
}
func (na *_UnionKinded__ReprAssembler) AssignNull() 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: cannot assign into assembler that's already working on a larger structure!")
	}
	return schema.ErrNotUnionStructure{TypeName: "gendemo.UnionKinded.Repr", Detail: "AssignNull called but is not valid for any of the kinds that are valid members of this union"}
}
func (na *_UnionKinded__ReprAssembler) AssignBool(v bool) 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: cannot assign into assembler that's already working on a larger structure!")
	}
	if na.w == nil {
		na.w = &_UnionKinded{}
	}
	na.ca = 2
	na.w.tag = 2
	na.ca2.w = &na.w.x2
	na.ca2.m = na.m
	return na.ca2.AssignBool(v)
}
func (na *_UnionKinded__ReprAssembler) AssignInt(v int64) 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: cannot assign into assembler that's already working on a larger structure!")
	}
	if na.w == nil {
		na.w = &_UnionKinded{}
	}
	na.ca = 1
	na.w.tag = 1
	na.ca1.w = &na.w.x1
	na.ca1.m = na.m
	return na.ca1.AssignInt(v)
}
func (na *_UnionKinded__ReprAssembler) AssignFloat(v float64) 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: cannot assign into assembler that's already working on a larger structure!")
	}
	return schema.ErrNotUnionStructure{TypeName: "gendemo.UnionKinded.Repr", Detail: "AssignFloat called but is not valid for any of the kinds that are valid members of this union"}
}
func (na *_UnionKinded__ReprAssembler) 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")
	case midvalue:
		panic("invalid state: cannot assign into assembler that's already working on a larger structure!")
	}
	if na.w == nil {
		na.w = &_UnionKinded{}
	}
	na.ca = 3
	na.w.tag = 3
	na.ca3.w = &na.w.x3
	na.ca3.m = na.m
	return na.ca3.AssignString(v)
}
func (na *_UnionKinded__ReprAssembler) 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")
	case midvalue:
		panic("invalid state: cannot assign into assembler that's already working on a larger structure!")
	}
	return schema.ErrNotUnionStructure{TypeName: "gendemo.UnionKinded.Repr", Detail: "AssignBytes called but is not valid for any of the kinds that are valid members of this union"}
}
func (na *_UnionKinded__ReprAssembler) AssignLink(v datamodel.Link) 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: cannot assign into assembler that's already working on a larger structure!")
	}
	return schema.ErrNotUnionStructure{TypeName: "gendemo.UnionKinded.Repr", Detail: "AssignLink called but is not valid for any of the kinds that are valid members of this union"}
}
func (na *_UnionKinded__ReprAssembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_UnionKinded); 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
	}
	switch v.Kind() {
	case datamodel.Kind_Bool:
		v2, _ := v.AsBool()
		return na.AssignBool(v2)
	case datamodel.Kind_Int:
		v2, _ := v.AsInt()
		return na.AssignInt(v2)
	case datamodel.Kind_Float:
		v2, _ := v.AsFloat()
		return na.AssignFloat(v2)
	case datamodel.Kind_String:
		v2, _ := v.AsString()
		return na.AssignString(v2)
	case datamodel.Kind_Bytes:
		v2, _ := v.AsBytes()
		return na.AssignBytes(v2)
	case datamodel.Kind_Map:
		na, err := na.BeginMap(v.Length())
		if err != nil {
			return err
		}
		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()
	case datamodel.Kind_List:
		na, err := na.BeginList(v.Length())
		if err != nil {
			return err
		}
		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()
	case datamodel.Kind_Link:
		v2, _ := v.AsLink()
		return na.AssignLink(v2)
	default:
		panic("unreachable")
	}
}
func (na *_UnionKinded__ReprAssembler) Prototype() datamodel.NodePrototype {
	return _UnionKinded__ReprPrototype{}
}
