package ipldsch

// 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 _Block) FieldSlot() Int {
	return &n.slot
}
func (n _Block) FieldEntries() List__Link {
	return &n.entries
}
func (n _Block) FieldShredding() List__Shredding {
	return &n.shredding
}

type _Block__Maybe struct {
	m schema.Maybe
	v Block
}
type MaybeBlock = *_Block__Maybe

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

var (
	fieldName__Block_Slot      = _String{"slot"}
	fieldName__Block_Entries   = _String{"entries"}
	fieldName__Block_Shredding = _String{"shredding"}
)
var _ datamodel.Node = (Block)(&_Block{})
var _ schema.TypedNode = (Block)(&_Block{})

func (Block) Kind() datamodel.Kind {
	return datamodel.Kind_Map
}
func (n Block) LookupByString(key string) (datamodel.Node, error) {
	switch key {
	case "slot":
		return &n.slot, nil
	case "entries":
		return &n.entries, nil
	case "shredding":
		return &n.shredding, nil
	default:
		return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)}
	}
}
func (n Block) LookupByNode(key datamodel.Node) (datamodel.Node, error) {
	ks, err := key.AsString()
	if err != nil {
		return nil, err
	}
	return n.LookupByString(ks)
}
func (Block) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.Map{TypeName: "ipldsch.Block"}.LookupByIndex(0)
}
func (n Block) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return n.LookupByString(seg.String())
}
func (n Block) MapIterator() datamodel.MapIterator {
	return &_Block__MapItr{n, 0}
}

type _Block__MapItr struct {
	n   Block
	idx int
}

func (itr *_Block__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__Block_Slot
		v = &itr.n.slot
	case 1:
		k = &fieldName__Block_Entries
		v = &itr.n.entries
	case 2:
		k = &fieldName__Block_Shredding
		v = &itr.n.shredding
	default:
		panic("unreachable")
	}
	itr.idx++
	return
}
func (itr *_Block__MapItr) Done() bool {
	return itr.idx >= 3
}

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

type _Block__Prototype struct{}

func (_Block__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Block__Builder
	nb.Reset()
	return &nb
}

type _Block__Builder struct {
	_Block__Assembler
}

func (nb *_Block__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 *_Block__Builder) Reset() {
	var w _Block
	var m schema.Maybe
	*nb = _Block__Builder{_Block__Assembler{w: &w, m: &m}}
}

type _Block__Assembler struct {
	w     *_Block
	m     *schema.Maybe
	state maState
	s     int
	f     int

	cm           schema.Maybe
	ca_slot      _Int__Assembler
	ca_entries   _List__Link__Assembler
	ca_shredding _List__Shredding__Assembler
}

func (na *_Block__Assembler) reset() {
	na.state = maState_initial
	na.s = 0
	na.ca_slot.reset()
	na.ca_entries.reset()
	na.ca_shredding.reset()
}

var (
	fieldBit__Block_Slot        = 1 << 0
	fieldBit__Block_Entries     = 1 << 1
	fieldBit__Block_Shredding   = 1 << 2
	fieldBits__Block_sufficient = 0 + 1<<0 + 1<<1 + 1<<2
)

func (na *_Block__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 = &_Block{}
	}
	return na, nil
}
func (_Block__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.MapAssembler{TypeName: "ipldsch.Block"}.BeginList(0)
}
func (na *_Block__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.MapAssembler{TypeName: "ipldsch.Block"}.AssignNull()
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	case midvalue:
		panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!")
	}
	panic("unreachable")
}
func (_Block__Assembler) AssignBool(bool) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Block"}.AssignBool(false)
}
func (_Block__Assembler) AssignInt(int64) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Block"}.AssignInt(0)
}
func (_Block__Assembler) AssignFloat(float64) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Block"}.AssignFloat(0)
}
func (_Block__Assembler) AssignString(string) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Block"}.AssignString("")
}
func (_Block__Assembler) AssignBytes([]byte) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Block"}.AssignBytes(nil)
}
func (_Block__Assembler) AssignLink(datamodel.Link) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Block"}.AssignLink(nil)
}
func (na *_Block__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Block); ok {
		switch *na.m {
		case schema.Maybe_Value, schema.Maybe_Null:
			panic("invalid state: cannot assign into assembler that's already finished")
		case midvalue:
			panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!")
		}
		if na.w == nil {
			na.w = v2
			*na.m = schema.Maybe_Value
			return nil
		}
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
	}
	if v.Kind() != datamodel.Kind_Map {
		return datamodel.ErrWrongKind{TypeName: "ipldsch.Block", 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 (_Block__Assembler) Prototype() datamodel.NodePrototype {
	return _Block__Prototype{}
}
func (ma *_Block__Assembler) valueFinishTidy() bool {
	switch ma.f {
	case 0:
		switch ma.cm {
		case schema.Maybe_Value:
			ma.ca_slot.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_entries.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_shredding.w = nil
			ma.cm = schema.Maybe_Absent
			ma.state = maState_initial
			return true
		default:
			return false
		}
	default:
		panic("unreachable")
	}
}
func (ma *_Block__Assembler) AssembleEntry(k string) (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 "slot":
		if ma.s&fieldBit__Block_Slot != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Block_Slot}
		}
		ma.s += fieldBit__Block_Slot
		ma.state = maState_midValue
		ma.f = 0
		ma.ca_slot.w = &ma.w.slot
		ma.ca_slot.m = &ma.cm
		return &ma.ca_slot, nil
	case "entries":
		if ma.s&fieldBit__Block_Entries != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Block_Entries}
		}
		ma.s += fieldBit__Block_Entries
		ma.state = maState_midValue
		ma.f = 1
		ma.ca_entries.w = &ma.w.entries
		ma.ca_entries.m = &ma.cm
		return &ma.ca_entries, nil
	case "shredding":
		if ma.s&fieldBit__Block_Shredding != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Block_Shredding}
		}
		ma.s += fieldBit__Block_Shredding
		ma.state = maState_midValue
		ma.f = 2
		ma.ca_shredding.w = &ma.w.shredding
		ma.ca_shredding.m = &ma.cm
		return &ma.ca_shredding, nil
	}
	return nil, schema.ErrInvalidKey{TypeName: "ipldsch.Block", Key: &_String{k}}
}
func (ma *_Block__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 (*_Block__KeyAssembler)(ma)
}
func (ma *_Block__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_slot.w = &ma.w.slot
		ma.ca_slot.m = &ma.cm
		return &ma.ca_slot
	case 1:
		ma.ca_entries.w = &ma.w.entries
		ma.ca_entries.m = &ma.cm
		return &ma.ca_entries
	case 2:
		ma.ca_shredding.w = &ma.w.shredding
		ma.ca_shredding.m = &ma.cm
		return &ma.ca_shredding
	default:
		panic("unreachable")
	}
}
func (ma *_Block__Assembler) Finish() error {
	switch ma.state {
	case maState_initial:
		// carry on
	case maState_midKey:
		panic("invalid state: Finish cannot be called when in the middle of assembling a key")
	case maState_expectValue:
		panic("invalid state: Finish cannot be called when expecting start of value assembly")
	case maState_midValue:
		if !ma.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} // if tidy success: carry on
	case maState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	if ma.s&fieldBits__Block_sufficient != fieldBits__Block_sufficient {
		err := schema.ErrMissingRequiredField{Missing: make([]string, 0)}
		if ma.s&fieldBit__Block_Slot == 0 {
			err.Missing = append(err.Missing, "slot")
		}
		if ma.s&fieldBit__Block_Entries == 0 {
			err.Missing = append(err.Missing, "entries")
		}
		if ma.s&fieldBit__Block_Shredding == 0 {
			err.Missing = append(err.Missing, "shredding")
		}
		return err
	}
	ma.state = maState_finished
	*ma.m = schema.Maybe_Value
	return nil
}
func (ma *_Block__Assembler) KeyPrototype() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (ma *_Block__Assembler) ValuePrototype(k string) datamodel.NodePrototype {
	panic("todo structbuilder mapassembler valueprototype")
}

type _Block__KeyAssembler _Block__Assembler

func (_Block__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.StringAssembler{TypeName: "ipldsch.Block.KeyAssembler"}.BeginMap(0)
}
func (_Block__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.StringAssembler{TypeName: "ipldsch.Block.KeyAssembler"}.BeginList(0)
}
func (na *_Block__KeyAssembler) AssignNull() error {
	return mixins.StringAssembler{TypeName: "ipldsch.Block.KeyAssembler"}.AssignNull()
}
func (_Block__KeyAssembler) AssignBool(bool) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Block.KeyAssembler"}.AssignBool(false)
}
func (_Block__KeyAssembler) AssignInt(int64) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Block.KeyAssembler"}.AssignInt(0)
}
func (_Block__KeyAssembler) AssignFloat(float64) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Block.KeyAssembler"}.AssignFloat(0)
}
func (ka *_Block__KeyAssembler) AssignString(k string) error {
	if ka.state != maState_midKey {
		panic("misuse: KeyAssembler held beyond its valid lifetime")
	}
	switch k {
	case "slot":
		if ka.s&fieldBit__Block_Slot != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Block_Slot}
		}
		ka.s += fieldBit__Block_Slot
		ka.state = maState_expectValue
		ka.f = 0
		return nil
	case "entries":
		if ka.s&fieldBit__Block_Entries != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Block_Entries}
		}
		ka.s += fieldBit__Block_Entries
		ka.state = maState_expectValue
		ka.f = 1
		return nil
	case "shredding":
		if ka.s&fieldBit__Block_Shredding != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Block_Shredding}
		}
		ka.s += fieldBit__Block_Shredding
		ka.state = maState_expectValue
		ka.f = 2
		return nil
	default:
		return schema.ErrInvalidKey{TypeName: "ipldsch.Block", Key: &_String{k}}
	}
}
func (_Block__KeyAssembler) AssignBytes([]byte) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Block.KeyAssembler"}.AssignBytes(nil)
}
func (_Block__KeyAssembler) AssignLink(datamodel.Link) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Block.KeyAssembler"}.AssignLink(nil)
}
func (ka *_Block__KeyAssembler) AssignNode(v datamodel.Node) error {
	if v2, err := v.AsString(); err != nil {
		return err
	} else {
		return ka.AssignString(v2)
	}
}
func (_Block__KeyAssembler) Prototype() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (Block) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Block) Representation() datamodel.Node {
	return (*_Block__Repr)(n)
}

type _Block__Repr _Block

var _ datamodel.Node = &_Block__Repr{}

func (_Block__Repr) Kind() datamodel.Kind {
	return datamodel.Kind_List
}
func (_Block__Repr) LookupByString(string) (datamodel.Node, error) {
	return mixins.List{TypeName: "ipldsch.Block.Repr"}.LookupByString("")
}
func (n *_Block__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) {
	ki, err := key.AsInt()
	if err != nil {
		return nil, err
	}
	return n.LookupByIndex(ki)
}
func (n *_Block__Repr) LookupByIndex(idx int64) (datamodel.Node, error) {
	switch idx {
	case 0:
		return n.slot.Representation(), nil
	case 1:
		return n.entries.Representation(), nil
	case 2:
		return n.shredding.Representation(), nil
	default:
		return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfInt(idx)}
	}
}
func (n _Block__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, datamodel.ErrInvalidSegmentForList{TypeName: "ipldsch.Block.Repr", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (_Block__Repr) MapIterator() datamodel.MapIterator {
	return nil
}
func (n *_Block__Repr) ListIterator() datamodel.ListIterator {
	return &_Block__ReprListItr{n, 0}
}

type _Block__ReprListItr struct {
	n   *_Block__Repr
	idx int
}

func (itr *_Block__ReprListItr) Next() (idx int64, v datamodel.Node, err error) {
	if itr.idx >= 3 {
		return -1, nil, datamodel.ErrIteratorOverread{}
	}
	switch itr.idx {
	case 0:
		idx = int64(itr.idx)
		v = itr.n.slot.Representation()
	case 1:
		idx = int64(itr.idx)
		v = itr.n.entries.Representation()
	case 2:
		idx = int64(itr.idx)
		v = itr.n.shredding.Representation()
	default:
		panic("unreachable")
	}
	itr.idx++
	return
}
func (itr *_Block__ReprListItr) Done() bool {
	return itr.idx >= 3
}

func (rn *_Block__Repr) Length() int64 {
	l := 3
	return int64(l)
}
func (_Block__Repr) IsAbsent() bool {
	return false
}
func (_Block__Repr) IsNull() bool {
	return false
}
func (_Block__Repr) AsBool() (bool, error) {
	return mixins.List{TypeName: "ipldsch.Block.Repr"}.AsBool()
}
func (_Block__Repr) AsInt() (int64, error) {
	return mixins.List{TypeName: "ipldsch.Block.Repr"}.AsInt()
}
func (_Block__Repr) AsFloat() (float64, error) {
	return mixins.List{TypeName: "ipldsch.Block.Repr"}.AsFloat()
}
func (_Block__Repr) AsString() (string, error) {
	return mixins.List{TypeName: "ipldsch.Block.Repr"}.AsString()
}
func (_Block__Repr) AsBytes() ([]byte, error) {
	return mixins.List{TypeName: "ipldsch.Block.Repr"}.AsBytes()
}
func (_Block__Repr) AsLink() (datamodel.Link, error) {
	return mixins.List{TypeName: "ipldsch.Block.Repr"}.AsLink()
}
func (_Block__Repr) Prototype() datamodel.NodePrototype {
	return _Block__ReprPrototype{}
}

type _Block__ReprPrototype struct{}

func (_Block__ReprPrototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Block__ReprBuilder
	nb.Reset()
	return &nb
}

type _Block__ReprBuilder struct {
	_Block__ReprAssembler
}

func (nb *_Block__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 *_Block__ReprBuilder) Reset() {
	var w _Block
	var m schema.Maybe
	*nb = _Block__ReprBuilder{_Block__ReprAssembler{w: &w, m: &m}}
}

type _Block__ReprAssembler struct {
	w     *_Block
	m     *schema.Maybe
	state laState
	f     int

	cm           schema.Maybe
	ca_slot      _Int__ReprAssembler
	ca_entries   _List__Link__ReprAssembler
	ca_shredding _List__Shredding__ReprAssembler
}

func (na *_Block__ReprAssembler) reset() {
	na.state = laState_initial
	na.f = 0
	na.ca_slot.reset()
	na.ca_entries.reset()
	na.ca_shredding.reset()
}
func (_Block__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.ListAssembler{TypeName: "ipldsch.Block.Repr"}.BeginMap(0)
}
func (na *_Block__ReprAssembler) BeginList(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: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if na.w == nil {
		na.w = &_Block{}
	}
	return na, nil
}
func (na *_Block__ReprAssembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{TypeName: "ipldsch.Block.Repr.Repr"}.AssignNull()
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	case midvalue:
		panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!")
	}
	panic("unreachable")
}
func (_Block__ReprAssembler) AssignBool(bool) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Block.Repr"}.AssignBool(false)
}
func (_Block__ReprAssembler) AssignInt(int64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Block.Repr"}.AssignInt(0)
}
func (_Block__ReprAssembler) AssignFloat(float64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Block.Repr"}.AssignFloat(0)
}
func (_Block__ReprAssembler) AssignString(string) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Block.Repr"}.AssignString("")
}
func (_Block__ReprAssembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Block.Repr"}.AssignBytes(nil)
}
func (_Block__ReprAssembler) AssignLink(datamodel.Link) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Block.Repr"}.AssignLink(nil)
}
func (na *_Block__ReprAssembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Block); ok {
		switch *na.m {
		case schema.Maybe_Value, schema.Maybe_Null:
			panic("invalid state: cannot assign into assembler that's already finished")
		case midvalue:
			panic("invalid state: cannot assign null into an assembler that's already begun working on recursive structures!")
		}
		if na.w == nil {
			na.w = v2
			*na.m = schema.Maybe_Value
			return nil
		}
		*na.w = *v2
		*na.m = schema.Maybe_Value
		return nil
	}
	if v.Kind() != datamodel.Kind_List {
		return datamodel.ErrWrongKind{TypeName: "ipldsch.Block.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_Block__ReprAssembler) Prototype() datamodel.NodePrototype {
	return _Block__ReprPrototype{}
}
func (la *_Block__ReprAssembler) valueFinishTidy() bool {
	switch la.f {
	case 0:
		switch la.cm {
		case schema.Maybe_Value:
			la.cm = schema.Maybe_Absent
			la.state = laState_initial
			la.f++
			return true
		default:
			return false
		}
	case 1:
		switch la.cm {
		case schema.Maybe_Value:
			la.cm = schema.Maybe_Absent
			la.state = laState_initial
			la.f++
			return true
		default:
			return false
		}
	case 2:
		switch la.cm {
		case schema.Maybe_Value:
			la.cm = schema.Maybe_Absent
			la.state = laState_initial
			la.f++
			return true
		default:
			return false
		}
	default:
		panic("unreachable")
	}
}
func (la *_Block__ReprAssembler) AssembleValue() datamodel.NodeAssembler {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	if la.f >= 3 {
		return _ErrorThunkAssembler{schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfInt(3)}}
	}
	la.state = laState_midValue
	switch la.f {
	case 0:
		la.ca_slot.w = &la.w.slot
		la.ca_slot.m = &la.cm
		return &la.ca_slot
	case 1:
		la.ca_entries.w = &la.w.entries
		la.ca_entries.m = &la.cm
		return &la.ca_entries
	case 2:
		la.ca_shredding.w = &la.w.shredding
		la.ca_shredding.m = &la.cm
		return &la.ca_shredding
	default:
		panic("unreachable")
	}
}
func (la *_Block__ReprAssembler) Finish() error {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_Block__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype {
	panic("todo structbuilder tuplerepr valueprototype")
}

func (n Bool) Bool() bool {
	return n.x
}
func (_Bool__Prototype) FromBool(v bool) (Bool, error) {
	n := _Bool{v}
	return &n, nil
}

type _Bool__Maybe struct {
	m schema.Maybe
	v _Bool
}
type MaybeBool = *_Bool__Maybe

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

var _ datamodel.Node = (Bool)(&_Bool{})
var _ schema.TypedNode = (Bool)(&_Bool{})

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

type _Bool__Prototype struct{}

func (_Bool__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Bool__Builder
	nb.Reset()
	return &nb
}

type _Bool__Builder struct {
	_Bool__Assembler
}

func (nb *_Bool__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 *_Bool__Builder) Reset() {
	var w _Bool
	var m schema.Maybe
	*nb = _Bool__Builder{_Bool__Assembler{w: &w, m: &m}}
}

type _Bool__Assembler struct {
	w *_Bool
	m *schema.Maybe
}

func (na *_Bool__Assembler) reset() {}
func (_Bool__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.BoolAssembler{TypeName: "ipldsch.Bool"}.BeginMap(0)
}
func (_Bool__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.BoolAssembler{TypeName: "ipldsch.Bool"}.BeginList(0)
}
func (na *_Bool__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.BoolAssembler{TypeName: "ipldsch.Bool"}.AssignNull()
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	}
	panic("unreachable")
}
func (na *_Bool__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 (_Bool__Assembler) AssignInt(int64) error {
	return mixins.BoolAssembler{TypeName: "ipldsch.Bool"}.AssignInt(0)
}
func (_Bool__Assembler) AssignFloat(float64) error {
	return mixins.BoolAssembler{TypeName: "ipldsch.Bool"}.AssignFloat(0)
}
func (_Bool__Assembler) AssignString(string) error {
	return mixins.BoolAssembler{TypeName: "ipldsch.Bool"}.AssignString("")
}
func (_Bool__Assembler) AssignBytes([]byte) error {
	return mixins.BoolAssembler{TypeName: "ipldsch.Bool"}.AssignBytes(nil)
}
func (_Bool__Assembler) AssignLink(datamodel.Link) error {
	return mixins.BoolAssembler{TypeName: "ipldsch.Bool"}.AssignLink(nil)
}
func (na *_Bool__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Bool); 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 (_Bool__Assembler) Prototype() datamodel.NodePrototype {
	return _Bool__Prototype{}
}
func (Bool) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Bool) Representation() datamodel.Node {
	return (*_Bool__Repr)(n)
}

type _Bool__Repr = _Bool

var _ datamodel.Node = &_Bool__Repr{}

type _Bool__ReprPrototype = _Bool__Prototype
type _Bool__ReprAssembler = _Bool__Assembler

func (n Bytes) Bytes() []byte {
	return n.x
}
func (_Bytes__Prototype) FromBytes(v []byte) (Bytes, error) {
	n := _Bytes{v}
	return &n, nil
}

type _Bytes__Maybe struct {
	m schema.Maybe
	v _Bytes
}
type MaybeBytes = *_Bytes__Maybe

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

var _ datamodel.Node = (Bytes)(&_Bytes{})
var _ schema.TypedNode = (Bytes)(&_Bytes{})

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

type _Bytes__Prototype struct{}

func (_Bytes__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Bytes__Builder
	nb.Reset()
	return &nb
}

type _Bytes__Builder struct {
	_Bytes__Assembler
}

func (nb *_Bytes__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 *_Bytes__Builder) Reset() {
	var w _Bytes
	var m schema.Maybe
	*nb = _Bytes__Builder{_Bytes__Assembler{w: &w, m: &m}}
}

type _Bytes__Assembler struct {
	w *_Bytes
	m *schema.Maybe
}

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

type _Bytes__Repr = _Bytes

var _ datamodel.Node = &_Bytes__Repr{}

type _Bytes__ReprPrototype = _Bytes__Prototype
type _Bytes__ReprAssembler = _Bytes__Assembler

func (n _Entry) FieldSlot() Int {
	return &n.slot
}
func (n _Entry) FieldIdx() Int {
	return &n.idx
}
func (n _Entry) FieldNumHashes() Int {
	return &n.numHashes
}
func (n _Entry) FieldHash() Hash {
	return &n.hash
}
func (n _Entry) FieldTxs() TransactionList {
	return &n.txs
}

type _Entry__Maybe struct {
	m schema.Maybe
	v Entry
}
type MaybeEntry = *_Entry__Maybe

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

var (
	fieldName__Entry_Slot      = _String{"slot"}
	fieldName__Entry_Idx       = _String{"idx"}
	fieldName__Entry_NumHashes = _String{"numHashes"}
	fieldName__Entry_Hash      = _String{"hash"}
	fieldName__Entry_Txs       = _String{"txs"}
)
var _ datamodel.Node = (Entry)(&_Entry{})
var _ schema.TypedNode = (Entry)(&_Entry{})

func (Entry) Kind() datamodel.Kind {
	return datamodel.Kind_Map
}
func (n Entry) LookupByString(key string) (datamodel.Node, error) {
	switch key {
	case "slot":
		return &n.slot, nil
	case "idx":
		return &n.idx, nil
	case "numHashes":
		return &n.numHashes, nil
	case "hash":
		return &n.hash, nil
	case "txs":
		return &n.txs, nil
	default:
		return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)}
	}
}
func (n Entry) LookupByNode(key datamodel.Node) (datamodel.Node, error) {
	ks, err := key.AsString()
	if err != nil {
		return nil, err
	}
	return n.LookupByString(ks)
}
func (Entry) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.Map{TypeName: "ipldsch.Entry"}.LookupByIndex(0)
}
func (n Entry) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return n.LookupByString(seg.String())
}
func (n Entry) MapIterator() datamodel.MapIterator {
	return &_Entry__MapItr{n, 0}
}

type _Entry__MapItr struct {
	n   Entry
	idx int
}

func (itr *_Entry__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) {
	if itr.idx >= 5 {
		return nil, nil, datamodel.ErrIteratorOverread{}
	}
	switch itr.idx {
	case 0:
		k = &fieldName__Entry_Slot
		v = &itr.n.slot
	case 1:
		k = &fieldName__Entry_Idx
		v = &itr.n.idx
	case 2:
		k = &fieldName__Entry_NumHashes
		v = &itr.n.numHashes
	case 3:
		k = &fieldName__Entry_Hash
		v = &itr.n.hash
	case 4:
		k = &fieldName__Entry_Txs
		v = &itr.n.txs
	default:
		panic("unreachable")
	}
	itr.idx++
	return
}
func (itr *_Entry__MapItr) Done() bool {
	return itr.idx >= 5
}

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

type _Entry__Prototype struct{}

func (_Entry__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Entry__Builder
	nb.Reset()
	return &nb
}

type _Entry__Builder struct {
	_Entry__Assembler
}

func (nb *_Entry__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 *_Entry__Builder) Reset() {
	var w _Entry
	var m schema.Maybe
	*nb = _Entry__Builder{_Entry__Assembler{w: &w, m: &m}}
}

type _Entry__Assembler struct {
	w     *_Entry
	m     *schema.Maybe
	state maState
	s     int
	f     int

	cm           schema.Maybe
	ca_slot      _Int__Assembler
	ca_idx       _Int__Assembler
	ca_numHashes _Int__Assembler
	ca_hash      _Hash__Assembler
	ca_txs       _TransactionList__Assembler
}

func (na *_Entry__Assembler) reset() {
	na.state = maState_initial
	na.s = 0
	na.ca_slot.reset()
	na.ca_idx.reset()
	na.ca_numHashes.reset()
	na.ca_hash.reset()
	na.ca_txs.reset()
}

var (
	fieldBit__Entry_Slot        = 1 << 0
	fieldBit__Entry_Idx         = 1 << 1
	fieldBit__Entry_NumHashes   = 1 << 2
	fieldBit__Entry_Hash        = 1 << 3
	fieldBit__Entry_Txs         = 1 << 4
	fieldBits__Entry_sufficient = 0 + 1<<0 + 1<<1 + 1<<2 + 1<<3 + 1<<4
)

func (na *_Entry__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 = &_Entry{}
	}
	return na, nil
}
func (_Entry__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.MapAssembler{TypeName: "ipldsch.Entry"}.BeginList(0)
}
func (na *_Entry__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.MapAssembler{TypeName: "ipldsch.Entry"}.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 (_Entry__Assembler) AssignBool(bool) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Entry"}.AssignBool(false)
}
func (_Entry__Assembler) AssignInt(int64) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Entry"}.AssignInt(0)
}
func (_Entry__Assembler) AssignFloat(float64) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Entry"}.AssignFloat(0)
}
func (_Entry__Assembler) AssignString(string) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Entry"}.AssignString("")
}
func (_Entry__Assembler) AssignBytes([]byte) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Entry"}.AssignBytes(nil)
}
func (_Entry__Assembler) AssignLink(datamodel.Link) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Entry"}.AssignLink(nil)
}
func (na *_Entry__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Entry); 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: "ipldsch.Entry", 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 (_Entry__Assembler) Prototype() datamodel.NodePrototype {
	return _Entry__Prototype{}
}
func (ma *_Entry__Assembler) valueFinishTidy() bool {
	switch ma.f {
	case 0:
		switch ma.cm {
		case schema.Maybe_Value:
			ma.ca_slot.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_idx.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_numHashes.w = nil
			ma.cm = schema.Maybe_Absent
			ma.state = maState_initial
			return true
		default:
			return false
		}
	case 3:
		switch ma.cm {
		case schema.Maybe_Value:
			ma.ca_hash.w = nil
			ma.cm = schema.Maybe_Absent
			ma.state = maState_initial
			return true
		default:
			return false
		}
	case 4:
		switch ma.cm {
		case schema.Maybe_Value:
			ma.ca_txs.w = nil
			ma.cm = schema.Maybe_Absent
			ma.state = maState_initial
			return true
		default:
			return false
		}
	default:
		panic("unreachable")
	}
}
func (ma *_Entry__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 "slot":
		if ma.s&fieldBit__Entry_Slot != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Entry_Slot}
		}
		ma.s += fieldBit__Entry_Slot
		ma.state = maState_midValue
		ma.f = 0
		ma.ca_slot.w = &ma.w.slot
		ma.ca_slot.m = &ma.cm
		return &ma.ca_slot, nil
	case "idx":
		if ma.s&fieldBit__Entry_Idx != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Entry_Idx}
		}
		ma.s += fieldBit__Entry_Idx
		ma.state = maState_midValue
		ma.f = 1
		ma.ca_idx.w = &ma.w.idx
		ma.ca_idx.m = &ma.cm
		return &ma.ca_idx, nil
	case "numHashes":
		if ma.s&fieldBit__Entry_NumHashes != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Entry_NumHashes}
		}
		ma.s += fieldBit__Entry_NumHashes
		ma.state = maState_midValue
		ma.f = 2
		ma.ca_numHashes.w = &ma.w.numHashes
		ma.ca_numHashes.m = &ma.cm
		return &ma.ca_numHashes, nil
	case "hash":
		if ma.s&fieldBit__Entry_Hash != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Entry_Hash}
		}
		ma.s += fieldBit__Entry_Hash
		ma.state = maState_midValue
		ma.f = 3
		ma.ca_hash.w = &ma.w.hash
		ma.ca_hash.m = &ma.cm
		return &ma.ca_hash, nil
	case "txs":
		if ma.s&fieldBit__Entry_Txs != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Entry_Txs}
		}
		ma.s += fieldBit__Entry_Txs
		ma.state = maState_midValue
		ma.f = 4
		ma.ca_txs.w = &ma.w.txs
		ma.ca_txs.m = &ma.cm
		return &ma.ca_txs, nil
	}
	return nil, schema.ErrInvalidKey{TypeName: "ipldsch.Entry", Key: &_String{k}}
}
func (ma *_Entry__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 (*_Entry__KeyAssembler)(ma)
}
func (ma *_Entry__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_slot.w = &ma.w.slot
		ma.ca_slot.m = &ma.cm
		return &ma.ca_slot
	case 1:
		ma.ca_idx.w = &ma.w.idx
		ma.ca_idx.m = &ma.cm
		return &ma.ca_idx
	case 2:
		ma.ca_numHashes.w = &ma.w.numHashes
		ma.ca_numHashes.m = &ma.cm
		return &ma.ca_numHashes
	case 3:
		ma.ca_hash.w = &ma.w.hash
		ma.ca_hash.m = &ma.cm
		return &ma.ca_hash
	case 4:
		ma.ca_txs.w = &ma.w.txs
		ma.ca_txs.m = &ma.cm
		return &ma.ca_txs
	default:
		panic("unreachable")
	}
}
func (ma *_Entry__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__Entry_sufficient != fieldBits__Entry_sufficient {
		err := schema.ErrMissingRequiredField{Missing: make([]string, 0)}
		if ma.s&fieldBit__Entry_Slot == 0 {
			err.Missing = append(err.Missing, "slot")
		}
		if ma.s&fieldBit__Entry_Idx == 0 {
			err.Missing = append(err.Missing, "idx")
		}
		if ma.s&fieldBit__Entry_NumHashes == 0 {
			err.Missing = append(err.Missing, "numHashes")
		}
		if ma.s&fieldBit__Entry_Hash == 0 {
			err.Missing = append(err.Missing, "hash")
		}
		if ma.s&fieldBit__Entry_Txs == 0 {
			err.Missing = append(err.Missing, "txs")
		}
		return err
	}
	ma.state = maState_finished
	*ma.m = schema.Maybe_Value
	return nil
}
func (ma *_Entry__Assembler) KeyPrototype() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (ma *_Entry__Assembler) ValuePrototype(k string) datamodel.NodePrototype {
	panic("todo structbuilder mapassembler valueprototype")
}

type _Entry__KeyAssembler _Entry__Assembler

func (_Entry__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.StringAssembler{TypeName: "ipldsch.Entry.KeyAssembler"}.BeginMap(0)
}
func (_Entry__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.StringAssembler{TypeName: "ipldsch.Entry.KeyAssembler"}.BeginList(0)
}
func (na *_Entry__KeyAssembler) AssignNull() error {
	return mixins.StringAssembler{TypeName: "ipldsch.Entry.KeyAssembler"}.AssignNull()
}
func (_Entry__KeyAssembler) AssignBool(bool) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Entry.KeyAssembler"}.AssignBool(false)
}
func (_Entry__KeyAssembler) AssignInt(int64) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Entry.KeyAssembler"}.AssignInt(0)
}
func (_Entry__KeyAssembler) AssignFloat(float64) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Entry.KeyAssembler"}.AssignFloat(0)
}
func (ka *_Entry__KeyAssembler) AssignString(k string) error {
	if ka.state != maState_midKey {
		panic("misuse: KeyAssembler held beyond its valid lifetime")
	}
	switch k {
	case "slot":
		if ka.s&fieldBit__Entry_Slot != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Entry_Slot}
		}
		ka.s += fieldBit__Entry_Slot
		ka.state = maState_expectValue
		ka.f = 0
		return nil
	case "idx":
		if ka.s&fieldBit__Entry_Idx != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Entry_Idx}
		}
		ka.s += fieldBit__Entry_Idx
		ka.state = maState_expectValue
		ka.f = 1
		return nil
	case "numHashes":
		if ka.s&fieldBit__Entry_NumHashes != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Entry_NumHashes}
		}
		ka.s += fieldBit__Entry_NumHashes
		ka.state = maState_expectValue
		ka.f = 2
		return nil
	case "hash":
		if ka.s&fieldBit__Entry_Hash != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Entry_Hash}
		}
		ka.s += fieldBit__Entry_Hash
		ka.state = maState_expectValue
		ka.f = 3
		return nil
	case "txs":
		if ka.s&fieldBit__Entry_Txs != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Entry_Txs}
		}
		ka.s += fieldBit__Entry_Txs
		ka.state = maState_expectValue
		ka.f = 4
		return nil
	default:
		return schema.ErrInvalidKey{TypeName: "ipldsch.Entry", Key: &_String{k}}
	}
}
func (_Entry__KeyAssembler) AssignBytes([]byte) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Entry.KeyAssembler"}.AssignBytes(nil)
}
func (_Entry__KeyAssembler) AssignLink(datamodel.Link) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Entry.KeyAssembler"}.AssignLink(nil)
}
func (ka *_Entry__KeyAssembler) AssignNode(v datamodel.Node) error {
	if v2, err := v.AsString(); err != nil {
		return err
	} else {
		return ka.AssignString(v2)
	}
}
func (_Entry__KeyAssembler) Prototype() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (Entry) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Entry) Representation() datamodel.Node {
	return (*_Entry__Repr)(n)
}

type _Entry__Repr _Entry

var _ datamodel.Node = &_Entry__Repr{}

func (_Entry__Repr) Kind() datamodel.Kind {
	return datamodel.Kind_List
}
func (_Entry__Repr) LookupByString(string) (datamodel.Node, error) {
	return mixins.List{TypeName: "ipldsch.Entry.Repr"}.LookupByString("")
}
func (n *_Entry__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) {
	ki, err := key.AsInt()
	if err != nil {
		return nil, err
	}
	return n.LookupByIndex(ki)
}
func (n *_Entry__Repr) LookupByIndex(idx int64) (datamodel.Node, error) {
	switch idx {
	case 0:
		return n.slot.Representation(), nil
	case 1:
		return n.idx.Representation(), nil
	case 2:
		return n.numHashes.Representation(), nil
	case 3:
		return n.hash.Representation(), nil
	case 4:
		return n.txs.Representation(), nil
	default:
		return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfInt(idx)}
	}
}
func (n _Entry__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, datamodel.ErrInvalidSegmentForList{TypeName: "ipldsch.Entry.Repr", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (_Entry__Repr) MapIterator() datamodel.MapIterator {
	return nil
}
func (n *_Entry__Repr) ListIterator() datamodel.ListIterator {
	return &_Entry__ReprListItr{n, 0}
}

type _Entry__ReprListItr struct {
	n   *_Entry__Repr
	idx int
}

func (itr *_Entry__ReprListItr) Next() (idx int64, v datamodel.Node, err error) {
	if itr.idx >= 5 {
		return -1, nil, datamodel.ErrIteratorOverread{}
	}
	switch itr.idx {
	case 0:
		idx = int64(itr.idx)
		v = itr.n.slot.Representation()
	case 1:
		idx = int64(itr.idx)
		v = itr.n.idx.Representation()
	case 2:
		idx = int64(itr.idx)
		v = itr.n.numHashes.Representation()
	case 3:
		idx = int64(itr.idx)
		v = itr.n.hash.Representation()
	case 4:
		idx = int64(itr.idx)
		v = itr.n.txs.Representation()
	default:
		panic("unreachable")
	}
	itr.idx++
	return
}
func (itr *_Entry__ReprListItr) Done() bool {
	return itr.idx >= 5
}

func (rn *_Entry__Repr) Length() int64 {
	l := 5
	return int64(l)
}
func (_Entry__Repr) IsAbsent() bool {
	return false
}
func (_Entry__Repr) IsNull() bool {
	return false
}
func (_Entry__Repr) AsBool() (bool, error) {
	return mixins.List{TypeName: "ipldsch.Entry.Repr"}.AsBool()
}
func (_Entry__Repr) AsInt() (int64, error) {
	return mixins.List{TypeName: "ipldsch.Entry.Repr"}.AsInt()
}
func (_Entry__Repr) AsFloat() (float64, error) {
	return mixins.List{TypeName: "ipldsch.Entry.Repr"}.AsFloat()
}
func (_Entry__Repr) AsString() (string, error) {
	return mixins.List{TypeName: "ipldsch.Entry.Repr"}.AsString()
}
func (_Entry__Repr) AsBytes() ([]byte, error) {
	return mixins.List{TypeName: "ipldsch.Entry.Repr"}.AsBytes()
}
func (_Entry__Repr) AsLink() (datamodel.Link, error) {
	return mixins.List{TypeName: "ipldsch.Entry.Repr"}.AsLink()
}
func (_Entry__Repr) Prototype() datamodel.NodePrototype {
	return _Entry__ReprPrototype{}
}

type _Entry__ReprPrototype struct{}

func (_Entry__ReprPrototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Entry__ReprBuilder
	nb.Reset()
	return &nb
}

type _Entry__ReprBuilder struct {
	_Entry__ReprAssembler
}

func (nb *_Entry__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 *_Entry__ReprBuilder) Reset() {
	var w _Entry
	var m schema.Maybe
	*nb = _Entry__ReprBuilder{_Entry__ReprAssembler{w: &w, m: &m}}
}

type _Entry__ReprAssembler struct {
	w     *_Entry
	m     *schema.Maybe
	state laState
	f     int

	cm           schema.Maybe
	ca_slot      _Int__ReprAssembler
	ca_idx       _Int__ReprAssembler
	ca_numHashes _Int__ReprAssembler
	ca_hash      _Hash__ReprAssembler
	ca_txs       _TransactionList__ReprAssembler
}

func (na *_Entry__ReprAssembler) reset() {
	na.state = laState_initial
	na.f = 0
	na.ca_slot.reset()
	na.ca_idx.reset()
	na.ca_numHashes.reset()
	na.ca_hash.reset()
	na.ca_txs.reset()
}
func (_Entry__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.ListAssembler{TypeName: "ipldsch.Entry.Repr"}.BeginMap(0)
}
func (na *_Entry__ReprAssembler) BeginList(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: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if na.w == nil {
		na.w = &_Entry{}
	}
	return na, nil
}
func (na *_Entry__ReprAssembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{TypeName: "ipldsch.Entry.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 (_Entry__ReprAssembler) AssignBool(bool) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Entry.Repr"}.AssignBool(false)
}
func (_Entry__ReprAssembler) AssignInt(int64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Entry.Repr"}.AssignInt(0)
}
func (_Entry__ReprAssembler) AssignFloat(float64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Entry.Repr"}.AssignFloat(0)
}
func (_Entry__ReprAssembler) AssignString(string) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Entry.Repr"}.AssignString("")
}
func (_Entry__ReprAssembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Entry.Repr"}.AssignBytes(nil)
}
func (_Entry__ReprAssembler) AssignLink(datamodel.Link) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Entry.Repr"}.AssignLink(nil)
}
func (na *_Entry__ReprAssembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Entry); 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_List {
		return datamodel.ErrWrongKind{TypeName: "ipldsch.Entry.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_Entry__ReprAssembler) Prototype() datamodel.NodePrototype {
	return _Entry__ReprPrototype{}
}
func (la *_Entry__ReprAssembler) valueFinishTidy() bool {
	switch la.f {
	case 0:
		switch la.cm {
		case schema.Maybe_Value:
			la.cm = schema.Maybe_Absent
			la.state = laState_initial
			la.f++
			return true
		default:
			return false
		}
	case 1:
		switch la.cm {
		case schema.Maybe_Value:
			la.cm = schema.Maybe_Absent
			la.state = laState_initial
			la.f++
			return true
		default:
			return false
		}
	case 2:
		switch la.cm {
		case schema.Maybe_Value:
			la.cm = schema.Maybe_Absent
			la.state = laState_initial
			la.f++
			return true
		default:
			return false
		}
	case 3:
		switch la.cm {
		case schema.Maybe_Value:
			la.cm = schema.Maybe_Absent
			la.state = laState_initial
			la.f++
			return true
		default:
			return false
		}
	case 4:
		switch la.cm {
		case schema.Maybe_Value:
			la.cm = schema.Maybe_Absent
			la.state = laState_initial
			la.f++
			return true
		default:
			return false
		}
	default:
		panic("unreachable")
	}
}
func (la *_Entry__ReprAssembler) AssembleValue() datamodel.NodeAssembler {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	if la.f >= 5 {
		return _ErrorThunkAssembler{schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfInt(5)}}
	}
	la.state = laState_midValue
	switch la.f {
	case 0:
		la.ca_slot.w = &la.w.slot
		la.ca_slot.m = &la.cm
		return &la.ca_slot
	case 1:
		la.ca_idx.w = &la.w.idx
		la.ca_idx.m = &la.cm
		return &la.ca_idx
	case 2:
		la.ca_numHashes.w = &la.w.numHashes
		la.ca_numHashes.m = &la.cm
		return &la.ca_numHashes
	case 3:
		la.ca_hash.w = &la.w.hash
		la.ca_hash.m = &la.cm
		return &la.ca_hash
	case 4:
		la.ca_txs.w = &la.w.txs
		la.ca_txs.m = &la.cm
		return &la.ca_txs
	default:
		panic("unreachable")
	}
}
func (la *_Entry__ReprAssembler) Finish() error {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_Entry__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype {
	panic("todo structbuilder tuplerepr valueprototype")
}

func (n Float) Float() float64 {
	return n.x
}
func (_Float__Prototype) FromFloat(v float64) (Float, error) {
	n := _Float{v}
	return &n, nil
}

type _Float__Maybe struct {
	m schema.Maybe
	v _Float
}
type MaybeFloat = *_Float__Maybe

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

var _ datamodel.Node = (Float)(&_Float{})
var _ schema.TypedNode = (Float)(&_Float{})

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

type _Float__Prototype struct{}

func (_Float__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Float__Builder
	nb.Reset()
	return &nb
}

type _Float__Builder struct {
	_Float__Assembler
}

func (nb *_Float__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 *_Float__Builder) Reset() {
	var w _Float
	var m schema.Maybe
	*nb = _Float__Builder{_Float__Assembler{w: &w, m: &m}}
}

type _Float__Assembler struct {
	w *_Float
	m *schema.Maybe
}

func (na *_Float__Assembler) reset() {}
func (_Float__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.FloatAssembler{TypeName: "ipldsch.Float"}.BeginMap(0)
}
func (_Float__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.FloatAssembler{TypeName: "ipldsch.Float"}.BeginList(0)
}
func (na *_Float__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.FloatAssembler{TypeName: "ipldsch.Float"}.AssignNull()
	case schema.Maybe_Value, schema.Maybe_Null:
		panic("invalid state: cannot assign into assembler that's already finished")
	}
	panic("unreachable")
}
func (_Float__Assembler) AssignBool(bool) error {
	return mixins.FloatAssembler{TypeName: "ipldsch.Float"}.AssignBool(false)
}
func (_Float__Assembler) AssignInt(int64) error {
	return mixins.FloatAssembler{TypeName: "ipldsch.Float"}.AssignInt(0)
}
func (na *_Float__Assembler) 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")
	}
	na.w.x = v
	*na.m = schema.Maybe_Value
	return nil
}
func (_Float__Assembler) AssignString(string) error {
	return mixins.FloatAssembler{TypeName: "ipldsch.Float"}.AssignString("")
}
func (_Float__Assembler) AssignBytes([]byte) error {
	return mixins.FloatAssembler{TypeName: "ipldsch.Float"}.AssignBytes(nil)
}
func (_Float__Assembler) AssignLink(datamodel.Link) error {
	return mixins.FloatAssembler{TypeName: "ipldsch.Float"}.AssignLink(nil)
}
func (na *_Float__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Float); 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.AsFloat(); err != nil {
		return err
	} else {
		return na.AssignFloat(v2)
	}
}
func (_Float__Assembler) Prototype() datamodel.NodePrototype {
	return _Float__Prototype{}
}
func (Float) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Float) Representation() datamodel.Node {
	return (*_Float__Repr)(n)
}

type _Float__Repr = _Float

var _ datamodel.Node = &_Float__Repr{}

type _Float__ReprPrototype = _Float__Prototype
type _Float__ReprAssembler = _Float__Assembler

func (n Hash) Bytes() []byte {
	return n.x
}
func (_Hash__Prototype) FromBytes(v []byte) (Hash, error) {
	n := _Hash{v}
	return &n, nil
}

type _Hash__Maybe struct {
	m schema.Maybe
	v _Hash
}
type MaybeHash = *_Hash__Maybe

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

var _ datamodel.Node = (Hash)(&_Hash{})
var _ schema.TypedNode = (Hash)(&_Hash{})

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

type _Hash__Prototype struct{}

func (_Hash__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Hash__Builder
	nb.Reset()
	return &nb
}

type _Hash__Builder struct {
	_Hash__Assembler
}

func (nb *_Hash__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 *_Hash__Builder) Reset() {
	var w _Hash
	var m schema.Maybe
	*nb = _Hash__Builder{_Hash__Assembler{w: &w, m: &m}}
}

type _Hash__Assembler struct {
	w *_Hash
	m *schema.Maybe
}

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

type _Hash__Repr = _Hash

var _ datamodel.Node = &_Hash__Repr{}

type _Hash__ReprPrototype = _Hash__Prototype
type _Hash__ReprAssembler = _Hash__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: "ipldsch.Int"}.LookupByString("")
}
func (Int) LookupByNode(datamodel.Node) (datamodel.Node, error) {
	return mixins.Int{TypeName: "ipldsch.Int"}.LookupByNode(nil)
}
func (Int) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.Int{TypeName: "ipldsch.Int"}.LookupByIndex(0)
}
func (Int) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return mixins.Int{TypeName: "ipldsch.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: "ipldsch.Int"}.AsBool()
}
func (n Int) AsInt() (int64, error) {
	return n.x, nil
}
func (Int) AsFloat() (float64, error) {
	return mixins.Int{TypeName: "ipldsch.Int"}.AsFloat()
}
func (Int) AsString() (string, error) {
	return mixins.Int{TypeName: "ipldsch.Int"}.AsString()
}
func (Int) AsBytes() ([]byte, error) {
	return mixins.Int{TypeName: "ipldsch.Int"}.AsBytes()
}
func (Int) AsLink() (datamodel.Link, error) {
	return mixins.Int{TypeName: "ipldsch.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: "ipldsch.Int"}.BeginMap(0)
}
func (_Int__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.IntAssembler{TypeName: "ipldsch.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: "ipldsch.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: "ipldsch.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: "ipldsch.Int"}.AssignFloat(0)
}
func (_Int__Assembler) AssignString(string) error {
	return mixins.IntAssembler{TypeName: "ipldsch.Int"}.AssignString("")
}
func (_Int__Assembler) AssignBytes([]byte) error {
	return mixins.IntAssembler{TypeName: "ipldsch.Int"}.AssignBytes(nil)
}
func (_Int__Assembler) AssignLink(datamodel.Link) error {
	return mixins.IntAssembler{TypeName: "ipldsch.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 Link) Link() datamodel.Link {
	return n.x
}
func (_Link__Prototype) FromLink(v datamodel.Link) (Link, error) {
	n := _Link{v}
	return &n, nil
}

type _Link__Maybe struct {
	m schema.Maybe
	v _Link
}
type MaybeLink = *_Link__Maybe

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

var _ datamodel.Node = (Link)(&_Link{})
var _ schema.TypedNode = (Link)(&_Link{})

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

type _Link__Prototype struct{}

func (_Link__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Link__Builder
	nb.Reset()
	return &nb
}

type _Link__Builder struct {
	_Link__Assembler
}

func (nb *_Link__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 *_Link__Builder) Reset() {
	var w _Link
	var m schema.Maybe
	*nb = _Link__Builder{_Link__Assembler{w: &w, m: &m}}
}

type _Link__Assembler struct {
	w *_Link
	m *schema.Maybe
}

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

type _Link__Repr = _Link

var _ datamodel.Node = &_Link__Repr{}

type _Link__ReprPrototype = _Link__Prototype
type _Link__ReprAssembler = _Link__Assembler

func (n *_List__Link) Lookup(idx int64) Link {
	if n.Length() <= idx {
		return nil
	}
	v := &n.x[idx]
	return v
}
func (n *_List__Link) LookupMaybe(idx int64) MaybeLink {
	if n.Length() <= idx {
		return nil
	}
	v := &n.x[idx]
	return &_Link__Maybe{
		m: schema.Maybe_Value,
		v: *v,
	}
}

var _List__Link__valueAbsent = _Link__Maybe{m: schema.Maybe_Absent}

func (n List__Link) Iterator() *List__Link__Itr {
	return &List__Link__Itr{n, 0}
}

type List__Link__Itr struct {
	n   List__Link
	idx int
}

func (itr *List__Link__Itr) Next() (idx int64, v Link) {
	if itr.idx >= len(itr.n.x) {
		return -1, nil
	}
	idx = int64(itr.idx)
	v = &itr.n.x[itr.idx]
	itr.idx++
	return
}
func (itr *List__Link__Itr) Done() bool {
	return itr.idx >= len(itr.n.x)
}

type _List__Link__Maybe struct {
	m schema.Maybe
	v _List__Link
}
type MaybeList__Link = *_List__Link__Maybe

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

var _ datamodel.Node = (List__Link)(&_List__Link{})
var _ schema.TypedNode = (List__Link)(&_List__Link{})

func (List__Link) Kind() datamodel.Kind {
	return datamodel.Kind_List
}
func (List__Link) LookupByString(string) (datamodel.Node, error) {
	return mixins.List{TypeName: "ipldsch.List__Link"}.LookupByString("")
}
func (n List__Link) LookupByNode(k datamodel.Node) (datamodel.Node, error) {
	idx, err := k.AsInt()
	if err != nil {
		return nil, err
	}
	return n.LookupByIndex(idx)
}
func (n List__Link) LookupByIndex(idx int64) (datamodel.Node, error) {
	if n.Length() <= idx {
		return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfInt(idx)}
	}
	v := &n.x[idx]
	return v, nil
}
func (n List__Link) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, datamodel.ErrInvalidSegmentForList{TypeName: "ipldsch.List__Link", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (List__Link) MapIterator() datamodel.MapIterator {
	return nil
}
func (n List__Link) ListIterator() datamodel.ListIterator {
	return &_List__Link__ListItr{n, 0}
}

type _List__Link__ListItr struct {
	n   List__Link
	idx int
}

func (itr *_List__Link__ListItr) Next() (idx int64, v datamodel.Node, _ error) {
	if itr.idx >= len(itr.n.x) {
		return -1, nil, datamodel.ErrIteratorOverread{}
	}
	idx = int64(itr.idx)
	x := &itr.n.x[itr.idx]
	v = x
	itr.idx++
	return
}
func (itr *_List__Link__ListItr) Done() bool {
	return itr.idx >= len(itr.n.x)
}

func (n List__Link) Length() int64 {
	return int64(len(n.x))
}
func (List__Link) IsAbsent() bool {
	return false
}
func (List__Link) IsNull() bool {
	return false
}
func (List__Link) AsBool() (bool, error) {
	return mixins.List{TypeName: "ipldsch.List__Link"}.AsBool()
}
func (List__Link) AsInt() (int64, error) {
	return mixins.List{TypeName: "ipldsch.List__Link"}.AsInt()
}
func (List__Link) AsFloat() (float64, error) {
	return mixins.List{TypeName: "ipldsch.List__Link"}.AsFloat()
}
func (List__Link) AsString() (string, error) {
	return mixins.List{TypeName: "ipldsch.List__Link"}.AsString()
}
func (List__Link) AsBytes() ([]byte, error) {
	return mixins.List{TypeName: "ipldsch.List__Link"}.AsBytes()
}
func (List__Link) AsLink() (datamodel.Link, error) {
	return mixins.List{TypeName: "ipldsch.List__Link"}.AsLink()
}
func (List__Link) Prototype() datamodel.NodePrototype {
	return _List__Link__Prototype{}
}

type _List__Link__Prototype struct{}

func (_List__Link__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _List__Link__Builder
	nb.Reset()
	return &nb
}

type _List__Link__Builder struct {
	_List__Link__Assembler
}

func (nb *_List__Link__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 *_List__Link__Builder) Reset() {
	var w _List__Link
	var m schema.Maybe
	*nb = _List__Link__Builder{_List__Link__Assembler{w: &w, m: &m}}
}

type _List__Link__Assembler struct {
	w     *_List__Link
	m     *schema.Maybe
	state laState

	cm schema.Maybe
	va _Link__Assembler
}

func (na *_List__Link__Assembler) reset() {
	na.state = laState_initial
	na.va.reset()
}
func (_List__Link__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link"}.BeginMap(0)
}
func (na *_List__Link__Assembler) 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: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if sizeHint < 0 {
		sizeHint = 0
	}
	if sizeHint > 0 {
		na.w.x = make([]_Link, 0, sizeHint)
	}
	return na, nil
}
func (na *_List__Link__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{TypeName: "ipldsch.List__Link"}.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 (_List__Link__Assembler) AssignBool(bool) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link"}.AssignBool(false)
}
func (_List__Link__Assembler) AssignInt(int64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link"}.AssignInt(0)
}
func (_List__Link__Assembler) AssignFloat(float64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link"}.AssignFloat(0)
}
func (_List__Link__Assembler) AssignString(string) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link"}.AssignString("")
}
func (_List__Link__Assembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link"}.AssignBytes(nil)
}
func (_List__Link__Assembler) AssignLink(datamodel.Link) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link"}.AssignLink(nil)
}
func (na *_List__Link__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_List__Link); 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_List {
		return datamodel.ErrWrongKind{TypeName: "ipldsch.List__Link", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_List__Link__Assembler) Prototype() datamodel.NodePrototype {
	return _List__Link__Prototype{}
}
func (la *_List__Link__Assembler) valueFinishTidy() bool {
	switch la.cm {
	case schema.Maybe_Value:
		la.va.w = nil
		la.cm = schema.Maybe_Absent
		la.state = laState_initial
		la.va.reset()
		return true
	default:
		return false
	}
}
func (la *_List__Link__Assembler) AssembleValue() datamodel.NodeAssembler {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	la.w.x = append(la.w.x, _Link{})
	la.state = laState_midValue
	row := &la.w.x[len(la.w.x)-1]
	la.va.w = row
	la.va.m = &la.cm
	return &la.va
}
func (la *_List__Link__Assembler) Finish() error {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_List__Link__Assembler) ValuePrototype(_ int64) datamodel.NodePrototype {
	return _Link__Prototype{}
}
func (List__Link) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n List__Link) Representation() datamodel.Node {
	return (*_List__Link__Repr)(n)
}

type _List__Link__Repr _List__Link

var _ datamodel.Node = &_List__Link__Repr{}

func (_List__Link__Repr) Kind() datamodel.Kind {
	return datamodel.Kind_List
}
func (_List__Link__Repr) LookupByString(string) (datamodel.Node, error) {
	return mixins.List{TypeName: "ipldsch.List__Link.Repr"}.LookupByString("")
}
func (nr *_List__Link__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) {
	v, err := (List__Link)(nr).LookupByNode(k)
	if err != nil || v == datamodel.Null {
		return v, err
	}
	return v.(Link).Representation(), nil
}
func (nr *_List__Link__Repr) LookupByIndex(idx int64) (datamodel.Node, error) {
	v, err := (List__Link)(nr).LookupByIndex(idx)
	if err != nil || v == datamodel.Null {
		return v, err
	}
	return v.(Link).Representation(), nil
}
func (n _List__Link__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, datamodel.ErrInvalidSegmentForList{TypeName: "ipldsch.List__Link.Repr", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (_List__Link__Repr) MapIterator() datamodel.MapIterator {
	return nil
}
func (nr *_List__Link__Repr) ListIterator() datamodel.ListIterator {
	return &_List__Link__ReprListItr{(List__Link)(nr), 0}
}

type _List__Link__ReprListItr _List__Link__ListItr

func (itr *_List__Link__ReprListItr) Next() (idx int64, v datamodel.Node, err error) {
	idx, v, err = (*_List__Link__ListItr)(itr).Next()
	if err != nil || v == datamodel.Null {
		return
	}
	return idx, v.(Link).Representation(), nil
}
func (itr *_List__Link__ReprListItr) Done() bool {
	return (*_List__Link__ListItr)(itr).Done()
}

func (rn *_List__Link__Repr) Length() int64 {
	return int64(len(rn.x))
}
func (_List__Link__Repr) IsAbsent() bool {
	return false
}
func (_List__Link__Repr) IsNull() bool {
	return false
}
func (_List__Link__Repr) AsBool() (bool, error) {
	return mixins.List{TypeName: "ipldsch.List__Link.Repr"}.AsBool()
}
func (_List__Link__Repr) AsInt() (int64, error) {
	return mixins.List{TypeName: "ipldsch.List__Link.Repr"}.AsInt()
}
func (_List__Link__Repr) AsFloat() (float64, error) {
	return mixins.List{TypeName: "ipldsch.List__Link.Repr"}.AsFloat()
}
func (_List__Link__Repr) AsString() (string, error) {
	return mixins.List{TypeName: "ipldsch.List__Link.Repr"}.AsString()
}
func (_List__Link__Repr) AsBytes() ([]byte, error) {
	return mixins.List{TypeName: "ipldsch.List__Link.Repr"}.AsBytes()
}
func (_List__Link__Repr) AsLink() (datamodel.Link, error) {
	return mixins.List{TypeName: "ipldsch.List__Link.Repr"}.AsLink()
}
func (_List__Link__Repr) Prototype() datamodel.NodePrototype {
	return _List__Link__ReprPrototype{}
}

type _List__Link__ReprPrototype struct{}

func (_List__Link__ReprPrototype) NewBuilder() datamodel.NodeBuilder {
	var nb _List__Link__ReprBuilder
	nb.Reset()
	return &nb
}

type _List__Link__ReprBuilder struct {
	_List__Link__ReprAssembler
}

func (nb *_List__Link__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 *_List__Link__ReprBuilder) Reset() {
	var w _List__Link
	var m schema.Maybe
	*nb = _List__Link__ReprBuilder{_List__Link__ReprAssembler{w: &w, m: &m}}
}

type _List__Link__ReprAssembler struct {
	w     *_List__Link
	m     *schema.Maybe
	state laState

	cm schema.Maybe
	va _Link__ReprAssembler
}

func (na *_List__Link__ReprAssembler) reset() {
	na.state = laState_initial
	na.va.reset()
}
func (_List__Link__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link.Repr"}.BeginMap(0)
}
func (na *_List__Link__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: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if sizeHint < 0 {
		sizeHint = 0
	}
	if sizeHint > 0 {
		na.w.x = make([]_Link, 0, sizeHint)
	}
	return na, nil
}
func (na *_List__Link__ReprAssembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{TypeName: "ipldsch.List__Link.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 (_List__Link__ReprAssembler) AssignBool(bool) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link.Repr"}.AssignBool(false)
}
func (_List__Link__ReprAssembler) AssignInt(int64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link.Repr"}.AssignInt(0)
}
func (_List__Link__ReprAssembler) AssignFloat(float64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link.Repr"}.AssignFloat(0)
}
func (_List__Link__ReprAssembler) AssignString(string) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link.Repr"}.AssignString("")
}
func (_List__Link__ReprAssembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link.Repr"}.AssignBytes(nil)
}
func (_List__Link__ReprAssembler) AssignLink(datamodel.Link) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Link.Repr"}.AssignLink(nil)
}
func (na *_List__Link__ReprAssembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_List__Link); 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_List {
		return datamodel.ErrWrongKind{TypeName: "ipldsch.List__Link.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_List__Link__ReprAssembler) Prototype() datamodel.NodePrototype {
	return _List__Link__ReprPrototype{}
}
func (la *_List__Link__ReprAssembler) valueFinishTidy() bool {
	switch la.cm {
	case schema.Maybe_Value:
		la.va.w = nil
		la.cm = schema.Maybe_Absent
		la.state = laState_initial
		la.va.reset()
		return true
	default:
		return false
	}
}
func (la *_List__Link__ReprAssembler) AssembleValue() datamodel.NodeAssembler {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	la.w.x = append(la.w.x, _Link{})
	la.state = laState_midValue
	row := &la.w.x[len(la.w.x)-1]
	la.va.w = row
	la.va.m = &la.cm
	return &la.va
}
func (la *_List__Link__ReprAssembler) Finish() error {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_List__Link__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype {
	return _Link__ReprPrototype{}
}

func (n *_List__Shredding) Lookup(idx int64) Shredding {
	if n.Length() <= idx {
		return nil
	}
	v := &n.x[idx]
	return v
}
func (n *_List__Shredding) LookupMaybe(idx int64) MaybeShredding {
	if n.Length() <= idx {
		return nil
	}
	v := &n.x[idx]
	return &_Shredding__Maybe{
		m: schema.Maybe_Value,
		v: v,
	}
}

var _List__Shredding__valueAbsent = _Shredding__Maybe{m: schema.Maybe_Absent}

func (n List__Shredding) Iterator() *List__Shredding__Itr {
	return &List__Shredding__Itr{n, 0}
}

type List__Shredding__Itr struct {
	n   List__Shredding
	idx int
}

func (itr *List__Shredding__Itr) Next() (idx int64, v Shredding) {
	if itr.idx >= len(itr.n.x) {
		return -1, nil
	}
	idx = int64(itr.idx)
	v = &itr.n.x[itr.idx]
	itr.idx++
	return
}
func (itr *List__Shredding__Itr) Done() bool {
	return itr.idx >= len(itr.n.x)
}

type _List__Shredding__Maybe struct {
	m schema.Maybe
	v _List__Shredding
}
type MaybeList__Shredding = *_List__Shredding__Maybe

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

var _ datamodel.Node = (List__Shredding)(&_List__Shredding{})
var _ schema.TypedNode = (List__Shredding)(&_List__Shredding{})

func (List__Shredding) Kind() datamodel.Kind {
	return datamodel.Kind_List
}
func (List__Shredding) LookupByString(string) (datamodel.Node, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding"}.LookupByString("")
}
func (n List__Shredding) LookupByNode(k datamodel.Node) (datamodel.Node, error) {
	idx, err := k.AsInt()
	if err != nil {
		return nil, err
	}
	return n.LookupByIndex(idx)
}
func (n List__Shredding) LookupByIndex(idx int64) (datamodel.Node, error) {
	if n.Length() <= idx {
		return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfInt(idx)}
	}
	v := &n.x[idx]
	return v, nil
}
func (n List__Shredding) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, datamodel.ErrInvalidSegmentForList{TypeName: "ipldsch.List__Shredding", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (List__Shredding) MapIterator() datamodel.MapIterator {
	return nil
}
func (n List__Shredding) ListIterator() datamodel.ListIterator {
	return &_List__Shredding__ListItr{n, 0}
}

type _List__Shredding__ListItr struct {
	n   List__Shredding
	idx int
}

func (itr *_List__Shredding__ListItr) Next() (idx int64, v datamodel.Node, _ error) {
	if itr.idx >= len(itr.n.x) {
		return -1, nil, datamodel.ErrIteratorOverread{}
	}
	idx = int64(itr.idx)
	x := &itr.n.x[itr.idx]
	v = x
	itr.idx++
	return
}
func (itr *_List__Shredding__ListItr) Done() bool {
	return itr.idx >= len(itr.n.x)
}

func (n List__Shredding) Length() int64 {
	return int64(len(n.x))
}
func (List__Shredding) IsAbsent() bool {
	return false
}
func (List__Shredding) IsNull() bool {
	return false
}
func (List__Shredding) AsBool() (bool, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding"}.AsBool()
}
func (List__Shredding) AsInt() (int64, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding"}.AsInt()
}
func (List__Shredding) AsFloat() (float64, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding"}.AsFloat()
}
func (List__Shredding) AsString() (string, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding"}.AsString()
}
func (List__Shredding) AsBytes() ([]byte, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding"}.AsBytes()
}
func (List__Shredding) AsLink() (datamodel.Link, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding"}.AsLink()
}
func (List__Shredding) Prototype() datamodel.NodePrototype {
	return _List__Shredding__Prototype{}
}

type _List__Shredding__Prototype struct{}

func (_List__Shredding__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _List__Shredding__Builder
	nb.Reset()
	return &nb
}

type _List__Shredding__Builder struct {
	_List__Shredding__Assembler
}

func (nb *_List__Shredding__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 *_List__Shredding__Builder) Reset() {
	var w _List__Shredding
	var m schema.Maybe
	*nb = _List__Shredding__Builder{_List__Shredding__Assembler{w: &w, m: &m}}
}

type _List__Shredding__Assembler struct {
	w     *_List__Shredding
	m     *schema.Maybe
	state laState

	cm schema.Maybe
	va _Shredding__Assembler
}

func (na *_List__Shredding__Assembler) reset() {
	na.state = laState_initial
	na.va.reset()
}
func (_List__Shredding__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding"}.BeginMap(0)
}
func (na *_List__Shredding__Assembler) 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: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if sizeHint < 0 {
		sizeHint = 0
	}
	if sizeHint > 0 {
		na.w.x = make([]_Shredding, 0, sizeHint)
	}
	return na, nil
}
func (na *_List__Shredding__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding"}.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 (_List__Shredding__Assembler) AssignBool(bool) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding"}.AssignBool(false)
}
func (_List__Shredding__Assembler) AssignInt(int64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding"}.AssignInt(0)
}
func (_List__Shredding__Assembler) AssignFloat(float64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding"}.AssignFloat(0)
}
func (_List__Shredding__Assembler) AssignString(string) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding"}.AssignString("")
}
func (_List__Shredding__Assembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding"}.AssignBytes(nil)
}
func (_List__Shredding__Assembler) AssignLink(datamodel.Link) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding"}.AssignLink(nil)
}
func (na *_List__Shredding__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_List__Shredding); 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_List {
		return datamodel.ErrWrongKind{TypeName: "ipldsch.List__Shredding", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_List__Shredding__Assembler) Prototype() datamodel.NodePrototype {
	return _List__Shredding__Prototype{}
}
func (la *_List__Shredding__Assembler) valueFinishTidy() bool {
	switch la.cm {
	case schema.Maybe_Value:
		la.va.w = nil
		la.cm = schema.Maybe_Absent
		la.state = laState_initial
		la.va.reset()
		return true
	default:
		return false
	}
}
func (la *_List__Shredding__Assembler) AssembleValue() datamodel.NodeAssembler {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	la.w.x = append(la.w.x, _Shredding{})
	la.state = laState_midValue
	row := &la.w.x[len(la.w.x)-1]
	la.va.w = row
	la.va.m = &la.cm
	return &la.va
}
func (la *_List__Shredding__Assembler) Finish() error {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_List__Shredding__Assembler) ValuePrototype(_ int64) datamodel.NodePrototype {
	return _Shredding__Prototype{}
}
func (List__Shredding) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n List__Shredding) Representation() datamodel.Node {
	return (*_List__Shredding__Repr)(n)
}

type _List__Shredding__Repr _List__Shredding

var _ datamodel.Node = &_List__Shredding__Repr{}

func (_List__Shredding__Repr) Kind() datamodel.Kind {
	return datamodel.Kind_List
}
func (_List__Shredding__Repr) LookupByString(string) (datamodel.Node, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding.Repr"}.LookupByString("")
}
func (nr *_List__Shredding__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) {
	v, err := (List__Shredding)(nr).LookupByNode(k)
	if err != nil || v == datamodel.Null {
		return v, err
	}
	return v.(Shredding).Representation(), nil
}
func (nr *_List__Shredding__Repr) LookupByIndex(idx int64) (datamodel.Node, error) {
	v, err := (List__Shredding)(nr).LookupByIndex(idx)
	if err != nil || v == datamodel.Null {
		return v, err
	}
	return v.(Shredding).Representation(), nil
}
func (n _List__Shredding__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, datamodel.ErrInvalidSegmentForList{TypeName: "ipldsch.List__Shredding.Repr", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (_List__Shredding__Repr) MapIterator() datamodel.MapIterator {
	return nil
}
func (nr *_List__Shredding__Repr) ListIterator() datamodel.ListIterator {
	return &_List__Shredding__ReprListItr{(List__Shredding)(nr), 0}
}

type _List__Shredding__ReprListItr _List__Shredding__ListItr

func (itr *_List__Shredding__ReprListItr) Next() (idx int64, v datamodel.Node, err error) {
	idx, v, err = (*_List__Shredding__ListItr)(itr).Next()
	if err != nil || v == datamodel.Null {
		return
	}
	return idx, v.(Shredding).Representation(), nil
}
func (itr *_List__Shredding__ReprListItr) Done() bool {
	return (*_List__Shredding__ListItr)(itr).Done()
}

func (rn *_List__Shredding__Repr) Length() int64 {
	return int64(len(rn.x))
}
func (_List__Shredding__Repr) IsAbsent() bool {
	return false
}
func (_List__Shredding__Repr) IsNull() bool {
	return false
}
func (_List__Shredding__Repr) AsBool() (bool, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding.Repr"}.AsBool()
}
func (_List__Shredding__Repr) AsInt() (int64, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding.Repr"}.AsInt()
}
func (_List__Shredding__Repr) AsFloat() (float64, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding.Repr"}.AsFloat()
}
func (_List__Shredding__Repr) AsString() (string, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding.Repr"}.AsString()
}
func (_List__Shredding__Repr) AsBytes() ([]byte, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding.Repr"}.AsBytes()
}
func (_List__Shredding__Repr) AsLink() (datamodel.Link, error) {
	return mixins.List{TypeName: "ipldsch.List__Shredding.Repr"}.AsLink()
}
func (_List__Shredding__Repr) Prototype() datamodel.NodePrototype {
	return _List__Shredding__ReprPrototype{}
}

type _List__Shredding__ReprPrototype struct{}

func (_List__Shredding__ReprPrototype) NewBuilder() datamodel.NodeBuilder {
	var nb _List__Shredding__ReprBuilder
	nb.Reset()
	return &nb
}

type _List__Shredding__ReprBuilder struct {
	_List__Shredding__ReprAssembler
}

func (nb *_List__Shredding__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 *_List__Shredding__ReprBuilder) Reset() {
	var w _List__Shredding
	var m schema.Maybe
	*nb = _List__Shredding__ReprBuilder{_List__Shredding__ReprAssembler{w: &w, m: &m}}
}

type _List__Shredding__ReprAssembler struct {
	w     *_List__Shredding
	m     *schema.Maybe
	state laState

	cm schema.Maybe
	va _Shredding__ReprAssembler
}

func (na *_List__Shredding__ReprAssembler) reset() {
	na.state = laState_initial
	na.va.reset()
}
func (_List__Shredding__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding.Repr"}.BeginMap(0)
}
func (na *_List__Shredding__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: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if sizeHint < 0 {
		sizeHint = 0
	}
	if sizeHint > 0 {
		na.w.x = make([]_Shredding, 0, sizeHint)
	}
	return na, nil
}
func (na *_List__Shredding__ReprAssembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding.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 (_List__Shredding__ReprAssembler) AssignBool(bool) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding.Repr"}.AssignBool(false)
}
func (_List__Shredding__ReprAssembler) AssignInt(int64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding.Repr"}.AssignInt(0)
}
func (_List__Shredding__ReprAssembler) AssignFloat(float64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding.Repr"}.AssignFloat(0)
}
func (_List__Shredding__ReprAssembler) AssignString(string) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding.Repr"}.AssignString("")
}
func (_List__Shredding__ReprAssembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding.Repr"}.AssignBytes(nil)
}
func (_List__Shredding__ReprAssembler) AssignLink(datamodel.Link) error {
	return mixins.ListAssembler{TypeName: "ipldsch.List__Shredding.Repr"}.AssignLink(nil)
}
func (na *_List__Shredding__ReprAssembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_List__Shredding); 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_List {
		return datamodel.ErrWrongKind{TypeName: "ipldsch.List__Shredding.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_List__Shredding__ReprAssembler) Prototype() datamodel.NodePrototype {
	return _List__Shredding__ReprPrototype{}
}
func (la *_List__Shredding__ReprAssembler) valueFinishTidy() bool {
	switch la.cm {
	case schema.Maybe_Value:
		la.va.w = nil
		la.cm = schema.Maybe_Absent
		la.state = laState_initial
		la.va.reset()
		return true
	default:
		return false
	}
}
func (la *_List__Shredding__ReprAssembler) AssembleValue() datamodel.NodeAssembler {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	la.w.x = append(la.w.x, _Shredding{})
	la.state = laState_midValue
	row := &la.w.x[len(la.w.x)-1]
	la.va.w = row
	la.va.m = &la.cm
	return &la.va
}
func (la *_List__Shredding__ReprAssembler) Finish() error {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_List__Shredding__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype {
	return _Shredding__ReprPrototype{}
}

func (n _Shredding) FieldEntryEndIdx() Int {
	return &n.entryEndIdx
}
func (n _Shredding) FieldShredEndIdx() Int {
	return &n.shredEndIdx
}

type _Shredding__Maybe struct {
	m schema.Maybe
	v Shredding
}
type MaybeShredding = *_Shredding__Maybe

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

var (
	fieldName__Shredding_EntryEndIdx = _String{"entryEndIdx"}
	fieldName__Shredding_ShredEndIdx = _String{"shredEndIdx"}
)
var _ datamodel.Node = (Shredding)(&_Shredding{})
var _ schema.TypedNode = (Shredding)(&_Shredding{})

func (Shredding) Kind() datamodel.Kind {
	return datamodel.Kind_Map
}
func (n Shredding) LookupByString(key string) (datamodel.Node, error) {
	switch key {
	case "entryEndIdx":
		return &n.entryEndIdx, nil
	case "shredEndIdx":
		return &n.shredEndIdx, nil
	default:
		return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfString(key)}
	}
}
func (n Shredding) LookupByNode(key datamodel.Node) (datamodel.Node, error) {
	ks, err := key.AsString()
	if err != nil {
		return nil, err
	}
	return n.LookupByString(ks)
}
func (Shredding) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.Map{TypeName: "ipldsch.Shredding"}.LookupByIndex(0)
}
func (n Shredding) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return n.LookupByString(seg.String())
}
func (n Shredding) MapIterator() datamodel.MapIterator {
	return &_Shredding__MapItr{n, 0}
}

type _Shredding__MapItr struct {
	n   Shredding
	idx int
}

func (itr *_Shredding__MapItr) Next() (k datamodel.Node, v datamodel.Node, _ error) {
	if itr.idx >= 2 {
		return nil, nil, datamodel.ErrIteratorOverread{}
	}
	switch itr.idx {
	case 0:
		k = &fieldName__Shredding_EntryEndIdx
		v = &itr.n.entryEndIdx
	case 1:
		k = &fieldName__Shredding_ShredEndIdx
		v = &itr.n.shredEndIdx
	default:
		panic("unreachable")
	}
	itr.idx++
	return
}
func (itr *_Shredding__MapItr) Done() bool {
	return itr.idx >= 2
}

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

type _Shredding__Prototype struct{}

func (_Shredding__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Shredding__Builder
	nb.Reset()
	return &nb
}

type _Shredding__Builder struct {
	_Shredding__Assembler
}

func (nb *_Shredding__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 *_Shredding__Builder) Reset() {
	var w _Shredding
	var m schema.Maybe
	*nb = _Shredding__Builder{_Shredding__Assembler{w: &w, m: &m}}
}

type _Shredding__Assembler struct {
	w     *_Shredding
	m     *schema.Maybe
	state maState
	s     int
	f     int

	cm             schema.Maybe
	ca_entryEndIdx _Int__Assembler
	ca_shredEndIdx _Int__Assembler
}

func (na *_Shredding__Assembler) reset() {
	na.state = maState_initial
	na.s = 0
	na.ca_entryEndIdx.reset()
	na.ca_shredEndIdx.reset()
}

var (
	fieldBit__Shredding_EntryEndIdx = 1 << 0
	fieldBit__Shredding_ShredEndIdx = 1 << 1
	fieldBits__Shredding_sufficient = 0 + 1<<0 + 1<<1
)

func (na *_Shredding__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 = &_Shredding{}
	}
	return na, nil
}
func (_Shredding__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.MapAssembler{TypeName: "ipldsch.Shredding"}.BeginList(0)
}
func (na *_Shredding__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.MapAssembler{TypeName: "ipldsch.Shredding"}.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 (_Shredding__Assembler) AssignBool(bool) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Shredding"}.AssignBool(false)
}
func (_Shredding__Assembler) AssignInt(int64) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Shredding"}.AssignInt(0)
}
func (_Shredding__Assembler) AssignFloat(float64) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Shredding"}.AssignFloat(0)
}
func (_Shredding__Assembler) AssignString(string) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Shredding"}.AssignString("")
}
func (_Shredding__Assembler) AssignBytes([]byte) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Shredding"}.AssignBytes(nil)
}
func (_Shredding__Assembler) AssignLink(datamodel.Link) error {
	return mixins.MapAssembler{TypeName: "ipldsch.Shredding"}.AssignLink(nil)
}
func (na *_Shredding__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Shredding); 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: "ipldsch.Shredding", 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 (_Shredding__Assembler) Prototype() datamodel.NodePrototype {
	return _Shredding__Prototype{}
}
func (ma *_Shredding__Assembler) valueFinishTidy() bool {
	switch ma.f {
	case 0:
		switch ma.cm {
		case schema.Maybe_Value:
			ma.ca_entryEndIdx.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_shredEndIdx.w = nil
			ma.cm = schema.Maybe_Absent
			ma.state = maState_initial
			return true
		default:
			return false
		}
	default:
		panic("unreachable")
	}
}
func (ma *_Shredding__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 "entryEndIdx":
		if ma.s&fieldBit__Shredding_EntryEndIdx != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Shredding_EntryEndIdx}
		}
		ma.s += fieldBit__Shredding_EntryEndIdx
		ma.state = maState_midValue
		ma.f = 0
		ma.ca_entryEndIdx.w = &ma.w.entryEndIdx
		ma.ca_entryEndIdx.m = &ma.cm
		return &ma.ca_entryEndIdx, nil
	case "shredEndIdx":
		if ma.s&fieldBit__Shredding_ShredEndIdx != 0 {
			return nil, datamodel.ErrRepeatedMapKey{Key: &fieldName__Shredding_ShredEndIdx}
		}
		ma.s += fieldBit__Shredding_ShredEndIdx
		ma.state = maState_midValue
		ma.f = 1
		ma.ca_shredEndIdx.w = &ma.w.shredEndIdx
		ma.ca_shredEndIdx.m = &ma.cm
		return &ma.ca_shredEndIdx, nil
	}
	return nil, schema.ErrInvalidKey{TypeName: "ipldsch.Shredding", Key: &_String{k}}
}
func (ma *_Shredding__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 (*_Shredding__KeyAssembler)(ma)
}
func (ma *_Shredding__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_entryEndIdx.w = &ma.w.entryEndIdx
		ma.ca_entryEndIdx.m = &ma.cm
		return &ma.ca_entryEndIdx
	case 1:
		ma.ca_shredEndIdx.w = &ma.w.shredEndIdx
		ma.ca_shredEndIdx.m = &ma.cm
		return &ma.ca_shredEndIdx
	default:
		panic("unreachable")
	}
}
func (ma *_Shredding__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__Shredding_sufficient != fieldBits__Shredding_sufficient {
		err := schema.ErrMissingRequiredField{Missing: make([]string, 0)}
		if ma.s&fieldBit__Shredding_EntryEndIdx == 0 {
			err.Missing = append(err.Missing, "entryEndIdx")
		}
		if ma.s&fieldBit__Shredding_ShredEndIdx == 0 {
			err.Missing = append(err.Missing, "shredEndIdx")
		}
		return err
	}
	ma.state = maState_finished
	*ma.m = schema.Maybe_Value
	return nil
}
func (ma *_Shredding__Assembler) KeyPrototype() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (ma *_Shredding__Assembler) ValuePrototype(k string) datamodel.NodePrototype {
	panic("todo structbuilder mapassembler valueprototype")
}

type _Shredding__KeyAssembler _Shredding__Assembler

func (_Shredding__KeyAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.StringAssembler{TypeName: "ipldsch.Shredding.KeyAssembler"}.BeginMap(0)
}
func (_Shredding__KeyAssembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.StringAssembler{TypeName: "ipldsch.Shredding.KeyAssembler"}.BeginList(0)
}
func (na *_Shredding__KeyAssembler) AssignNull() error {
	return mixins.StringAssembler{TypeName: "ipldsch.Shredding.KeyAssembler"}.AssignNull()
}
func (_Shredding__KeyAssembler) AssignBool(bool) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Shredding.KeyAssembler"}.AssignBool(false)
}
func (_Shredding__KeyAssembler) AssignInt(int64) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Shredding.KeyAssembler"}.AssignInt(0)
}
func (_Shredding__KeyAssembler) AssignFloat(float64) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Shredding.KeyAssembler"}.AssignFloat(0)
}
func (ka *_Shredding__KeyAssembler) AssignString(k string) error {
	if ka.state != maState_midKey {
		panic("misuse: KeyAssembler held beyond its valid lifetime")
	}
	switch k {
	case "entryEndIdx":
		if ka.s&fieldBit__Shredding_EntryEndIdx != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Shredding_EntryEndIdx}
		}
		ka.s += fieldBit__Shredding_EntryEndIdx
		ka.state = maState_expectValue
		ka.f = 0
		return nil
	case "shredEndIdx":
		if ka.s&fieldBit__Shredding_ShredEndIdx != 0 {
			return datamodel.ErrRepeatedMapKey{Key: &fieldName__Shredding_ShredEndIdx}
		}
		ka.s += fieldBit__Shredding_ShredEndIdx
		ka.state = maState_expectValue
		ka.f = 1
		return nil
	default:
		return schema.ErrInvalidKey{TypeName: "ipldsch.Shredding", Key: &_String{k}}
	}
}
func (_Shredding__KeyAssembler) AssignBytes([]byte) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Shredding.KeyAssembler"}.AssignBytes(nil)
}
func (_Shredding__KeyAssembler) AssignLink(datamodel.Link) error {
	return mixins.StringAssembler{TypeName: "ipldsch.Shredding.KeyAssembler"}.AssignLink(nil)
}
func (ka *_Shredding__KeyAssembler) AssignNode(v datamodel.Node) error {
	if v2, err := v.AsString(); err != nil {
		return err
	} else {
		return ka.AssignString(v2)
	}
}
func (_Shredding__KeyAssembler) Prototype() datamodel.NodePrototype {
	return _String__Prototype{}
}
func (Shredding) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n Shredding) Representation() datamodel.Node {
	return (*_Shredding__Repr)(n)
}

type _Shredding__Repr _Shredding

var _ datamodel.Node = &_Shredding__Repr{}

func (_Shredding__Repr) Kind() datamodel.Kind {
	return datamodel.Kind_List
}
func (_Shredding__Repr) LookupByString(string) (datamodel.Node, error) {
	return mixins.List{TypeName: "ipldsch.Shredding.Repr"}.LookupByString("")
}
func (n *_Shredding__Repr) LookupByNode(key datamodel.Node) (datamodel.Node, error) {
	ki, err := key.AsInt()
	if err != nil {
		return nil, err
	}
	return n.LookupByIndex(ki)
}
func (n *_Shredding__Repr) LookupByIndex(idx int64) (datamodel.Node, error) {
	switch idx {
	case 0:
		return n.entryEndIdx.Representation(), nil
	case 1:
		return n.shredEndIdx.Representation(), nil
	default:
		return nil, schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfInt(idx)}
	}
}
func (n _Shredding__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, datamodel.ErrInvalidSegmentForList{TypeName: "ipldsch.Shredding.Repr", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (_Shredding__Repr) MapIterator() datamodel.MapIterator {
	return nil
}
func (n *_Shredding__Repr) ListIterator() datamodel.ListIterator {
	return &_Shredding__ReprListItr{n, 0}
}

type _Shredding__ReprListItr struct {
	n   *_Shredding__Repr
	idx int
}

func (itr *_Shredding__ReprListItr) Next() (idx int64, v datamodel.Node, err error) {
	if itr.idx >= 2 {
		return -1, nil, datamodel.ErrIteratorOverread{}
	}
	switch itr.idx {
	case 0:
		idx = int64(itr.idx)
		v = itr.n.entryEndIdx.Representation()
	case 1:
		idx = int64(itr.idx)
		v = itr.n.shredEndIdx.Representation()
	default:
		panic("unreachable")
	}
	itr.idx++
	return
}
func (itr *_Shredding__ReprListItr) Done() bool {
	return itr.idx >= 2
}

func (rn *_Shredding__Repr) Length() int64 {
	l := 2
	return int64(l)
}
func (_Shredding__Repr) IsAbsent() bool {
	return false
}
func (_Shredding__Repr) IsNull() bool {
	return false
}
func (_Shredding__Repr) AsBool() (bool, error) {
	return mixins.List{TypeName: "ipldsch.Shredding.Repr"}.AsBool()
}
func (_Shredding__Repr) AsInt() (int64, error) {
	return mixins.List{TypeName: "ipldsch.Shredding.Repr"}.AsInt()
}
func (_Shredding__Repr) AsFloat() (float64, error) {
	return mixins.List{TypeName: "ipldsch.Shredding.Repr"}.AsFloat()
}
func (_Shredding__Repr) AsString() (string, error) {
	return mixins.List{TypeName: "ipldsch.Shredding.Repr"}.AsString()
}
func (_Shredding__Repr) AsBytes() ([]byte, error) {
	return mixins.List{TypeName: "ipldsch.Shredding.Repr"}.AsBytes()
}
func (_Shredding__Repr) AsLink() (datamodel.Link, error) {
	return mixins.List{TypeName: "ipldsch.Shredding.Repr"}.AsLink()
}
func (_Shredding__Repr) Prototype() datamodel.NodePrototype {
	return _Shredding__ReprPrototype{}
}

type _Shredding__ReprPrototype struct{}

func (_Shredding__ReprPrototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Shredding__ReprBuilder
	nb.Reset()
	return &nb
}

type _Shredding__ReprBuilder struct {
	_Shredding__ReprAssembler
}

func (nb *_Shredding__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 *_Shredding__ReprBuilder) Reset() {
	var w _Shredding
	var m schema.Maybe
	*nb = _Shredding__ReprBuilder{_Shredding__ReprAssembler{w: &w, m: &m}}
}

type _Shredding__ReprAssembler struct {
	w     *_Shredding
	m     *schema.Maybe
	state laState
	f     int

	cm             schema.Maybe
	ca_entryEndIdx _Int__ReprAssembler
	ca_shredEndIdx _Int__ReprAssembler
}

func (na *_Shredding__ReprAssembler) reset() {
	na.state = laState_initial
	na.f = 0
	na.ca_entryEndIdx.reset()
	na.ca_shredEndIdx.reset()
}
func (_Shredding__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.ListAssembler{TypeName: "ipldsch.Shredding.Repr"}.BeginMap(0)
}
func (na *_Shredding__ReprAssembler) BeginList(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: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if na.w == nil {
		na.w = &_Shredding{}
	}
	return na, nil
}
func (na *_Shredding__ReprAssembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{TypeName: "ipldsch.Shredding.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 (_Shredding__ReprAssembler) AssignBool(bool) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Shredding.Repr"}.AssignBool(false)
}
func (_Shredding__ReprAssembler) AssignInt(int64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Shredding.Repr"}.AssignInt(0)
}
func (_Shredding__ReprAssembler) AssignFloat(float64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Shredding.Repr"}.AssignFloat(0)
}
func (_Shredding__ReprAssembler) AssignString(string) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Shredding.Repr"}.AssignString("")
}
func (_Shredding__ReprAssembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Shredding.Repr"}.AssignBytes(nil)
}
func (_Shredding__ReprAssembler) AssignLink(datamodel.Link) error {
	return mixins.ListAssembler{TypeName: "ipldsch.Shredding.Repr"}.AssignLink(nil)
}
func (na *_Shredding__ReprAssembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_Shredding); 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_List {
		return datamodel.ErrWrongKind{TypeName: "ipldsch.Shredding.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_Shredding__ReprAssembler) Prototype() datamodel.NodePrototype {
	return _Shredding__ReprPrototype{}
}
func (la *_Shredding__ReprAssembler) valueFinishTidy() bool {
	switch la.f {
	case 0:
		switch la.cm {
		case schema.Maybe_Value:
			la.cm = schema.Maybe_Absent
			la.state = laState_initial
			la.f++
			return true
		default:
			return false
		}
	case 1:
		switch la.cm {
		case schema.Maybe_Value:
			la.cm = schema.Maybe_Absent
			la.state = laState_initial
			la.f++
			return true
		default:
			return false
		}
	default:
		panic("unreachable")
	}
}
func (la *_Shredding__ReprAssembler) AssembleValue() datamodel.NodeAssembler {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	if la.f >= 2 {
		return _ErrorThunkAssembler{schema.ErrNoSuchField{Type: nil /*TODO*/, Field: datamodel.PathSegmentOfInt(2)}}
	}
	la.state = laState_midValue
	switch la.f {
	case 0:
		la.ca_entryEndIdx.w = &la.w.entryEndIdx
		la.ca_entryEndIdx.m = &la.cm
		return &la.ca_entryEndIdx
	case 1:
		la.ca_shredEndIdx.w = &la.w.shredEndIdx
		la.ca_shredEndIdx.m = &la.cm
		return &la.ca_shredEndIdx
	default:
		panic("unreachable")
	}
}
func (la *_Shredding__ReprAssembler) Finish() error {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_Shredding__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype {
	panic("todo structbuilder tuplerepr valueprototype")
}

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: "ipldsch.String"}.LookupByString("")
}
func (String) LookupByNode(datamodel.Node) (datamodel.Node, error) {
	return mixins.String{TypeName: "ipldsch.String"}.LookupByNode(nil)
}
func (String) LookupByIndex(idx int64) (datamodel.Node, error) {
	return mixins.String{TypeName: "ipldsch.String"}.LookupByIndex(0)
}
func (String) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	return mixins.String{TypeName: "ipldsch.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: "ipldsch.String"}.AsBool()
}
func (String) AsInt() (int64, error) {
	return mixins.String{TypeName: "ipldsch.String"}.AsInt()
}
func (String) AsFloat() (float64, error) {
	return mixins.String{TypeName: "ipldsch.String"}.AsFloat()
}
func (n String) AsString() (string, error) {
	return n.x, nil
}
func (String) AsBytes() ([]byte, error) {
	return mixins.String{TypeName: "ipldsch.String"}.AsBytes()
}
func (String) AsLink() (datamodel.Link, error) {
	return mixins.String{TypeName: "ipldsch.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: "ipldsch.String"}.BeginMap(0)
}
func (_String__Assembler) BeginList(sizeHint int64) (datamodel.ListAssembler, error) {
	return mixins.StringAssembler{TypeName: "ipldsch.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: "ipldsch.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: "ipldsch.String"}.AssignBool(false)
}
func (_String__Assembler) AssignInt(int64) error {
	return mixins.StringAssembler{TypeName: "ipldsch.String"}.AssignInt(0)
}
func (_String__Assembler) AssignFloat(float64) error {
	return mixins.StringAssembler{TypeName: "ipldsch.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: "ipldsch.String"}.AssignBytes(nil)
}
func (_String__Assembler) AssignLink(datamodel.Link) error {
	return mixins.StringAssembler{TypeName: "ipldsch.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 Transaction) Bytes() []byte {
	return n.x
}
func (_Transaction__Prototype) FromBytes(v []byte) (Transaction, error) {
	n := _Transaction{v}
	return &n, nil
}

type _Transaction__Maybe struct {
	m schema.Maybe
	v _Transaction
}
type MaybeTransaction = *_Transaction__Maybe

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

var _ datamodel.Node = (Transaction)(&_Transaction{})
var _ schema.TypedNode = (Transaction)(&_Transaction{})

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

type _Transaction__Prototype struct{}

func (_Transaction__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _Transaction__Builder
	nb.Reset()
	return &nb
}

type _Transaction__Builder struct {
	_Transaction__Assembler
}

func (nb *_Transaction__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 *_Transaction__Builder) Reset() {
	var w _Transaction
	var m schema.Maybe
	*nb = _Transaction__Builder{_Transaction__Assembler{w: &w, m: &m}}
}

type _Transaction__Assembler struct {
	w *_Transaction
	m *schema.Maybe
}

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

type _Transaction__Repr = _Transaction

var _ datamodel.Node = &_Transaction__Repr{}

type _Transaction__ReprPrototype = _Transaction__Prototype
type _Transaction__ReprAssembler = _Transaction__Assembler

func (n *_TransactionList) Lookup(idx int64) Link {
	if n.Length() <= idx {
		return nil
	}
	v := &n.x[idx]
	return v
}
func (n *_TransactionList) LookupMaybe(idx int64) MaybeLink {
	if n.Length() <= idx {
		return nil
	}
	v := &n.x[idx]
	return &_Link__Maybe{
		m: schema.Maybe_Value,
		v: *v,
	}
}

var _TransactionList__valueAbsent = _Link__Maybe{m: schema.Maybe_Absent}

func (n TransactionList) Iterator() *TransactionList__Itr {
	return &TransactionList__Itr{n, 0}
}

type TransactionList__Itr struct {
	n   TransactionList
	idx int
}

func (itr *TransactionList__Itr) Next() (idx int64, v Link) {
	if itr.idx >= len(itr.n.x) {
		return -1, nil
	}
	idx = int64(itr.idx)
	v = &itr.n.x[itr.idx]
	itr.idx++
	return
}
func (itr *TransactionList__Itr) Done() bool {
	return itr.idx >= len(itr.n.x)
}

type _TransactionList__Maybe struct {
	m schema.Maybe
	v _TransactionList
}
type MaybeTransactionList = *_TransactionList__Maybe

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

var _ datamodel.Node = (TransactionList)(&_TransactionList{})
var _ schema.TypedNode = (TransactionList)(&_TransactionList{})

func (TransactionList) Kind() datamodel.Kind {
	return datamodel.Kind_List
}
func (TransactionList) LookupByString(string) (datamodel.Node, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList"}.LookupByString("")
}
func (n TransactionList) LookupByNode(k datamodel.Node) (datamodel.Node, error) {
	idx, err := k.AsInt()
	if err != nil {
		return nil, err
	}
	return n.LookupByIndex(idx)
}
func (n TransactionList) LookupByIndex(idx int64) (datamodel.Node, error) {
	if n.Length() <= idx {
		return nil, datamodel.ErrNotExists{Segment: datamodel.PathSegmentOfInt(idx)}
	}
	v := &n.x[idx]
	return v, nil
}
func (n TransactionList) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, datamodel.ErrInvalidSegmentForList{TypeName: "ipldsch.TransactionList", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (TransactionList) MapIterator() datamodel.MapIterator {
	return nil
}
func (n TransactionList) ListIterator() datamodel.ListIterator {
	return &_TransactionList__ListItr{n, 0}
}

type _TransactionList__ListItr struct {
	n   TransactionList
	idx int
}

func (itr *_TransactionList__ListItr) Next() (idx int64, v datamodel.Node, _ error) {
	if itr.idx >= len(itr.n.x) {
		return -1, nil, datamodel.ErrIteratorOverread{}
	}
	idx = int64(itr.idx)
	x := &itr.n.x[itr.idx]
	v = x
	itr.idx++
	return
}
func (itr *_TransactionList__ListItr) Done() bool {
	return itr.idx >= len(itr.n.x)
}

func (n TransactionList) Length() int64 {
	return int64(len(n.x))
}
func (TransactionList) IsAbsent() bool {
	return false
}
func (TransactionList) IsNull() bool {
	return false
}
func (TransactionList) AsBool() (bool, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList"}.AsBool()
}
func (TransactionList) AsInt() (int64, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList"}.AsInt()
}
func (TransactionList) AsFloat() (float64, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList"}.AsFloat()
}
func (TransactionList) AsString() (string, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList"}.AsString()
}
func (TransactionList) AsBytes() ([]byte, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList"}.AsBytes()
}
func (TransactionList) AsLink() (datamodel.Link, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList"}.AsLink()
}
func (TransactionList) Prototype() datamodel.NodePrototype {
	return _TransactionList__Prototype{}
}

type _TransactionList__Prototype struct{}

func (_TransactionList__Prototype) NewBuilder() datamodel.NodeBuilder {
	var nb _TransactionList__Builder
	nb.Reset()
	return &nb
}

type _TransactionList__Builder struct {
	_TransactionList__Assembler
}

func (nb *_TransactionList__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 *_TransactionList__Builder) Reset() {
	var w _TransactionList
	var m schema.Maybe
	*nb = _TransactionList__Builder{_TransactionList__Assembler{w: &w, m: &m}}
}

type _TransactionList__Assembler struct {
	w     *_TransactionList
	m     *schema.Maybe
	state laState

	cm schema.Maybe
	va _Link__Assembler
}

func (na *_TransactionList__Assembler) reset() {
	na.state = laState_initial
	na.va.reset()
}
func (_TransactionList__Assembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList"}.BeginMap(0)
}
func (na *_TransactionList__Assembler) 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: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if sizeHint < 0 {
		sizeHint = 0
	}
	if sizeHint > 0 {
		na.w.x = make([]_Link, 0, sizeHint)
	}
	return na, nil
}
func (na *_TransactionList__Assembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{TypeName: "ipldsch.TransactionList"}.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 (_TransactionList__Assembler) AssignBool(bool) error {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList"}.AssignBool(false)
}
func (_TransactionList__Assembler) AssignInt(int64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList"}.AssignInt(0)
}
func (_TransactionList__Assembler) AssignFloat(float64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList"}.AssignFloat(0)
}
func (_TransactionList__Assembler) AssignString(string) error {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList"}.AssignString("")
}
func (_TransactionList__Assembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList"}.AssignBytes(nil)
}
func (_TransactionList__Assembler) AssignLink(datamodel.Link) error {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList"}.AssignLink(nil)
}
func (na *_TransactionList__Assembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_TransactionList); 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_List {
		return datamodel.ErrWrongKind{TypeName: "ipldsch.TransactionList", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_TransactionList__Assembler) Prototype() datamodel.NodePrototype {
	return _TransactionList__Prototype{}
}
func (la *_TransactionList__Assembler) valueFinishTidy() bool {
	switch la.cm {
	case schema.Maybe_Value:
		la.va.w = nil
		la.cm = schema.Maybe_Absent
		la.state = laState_initial
		la.va.reset()
		return true
	default:
		return false
	}
}
func (la *_TransactionList__Assembler) AssembleValue() datamodel.NodeAssembler {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	la.w.x = append(la.w.x, _Link{})
	la.state = laState_midValue
	row := &la.w.x[len(la.w.x)-1]
	la.va.w = row
	la.va.m = &la.cm
	return &la.va
}
func (la *_TransactionList__Assembler) Finish() error {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_TransactionList__Assembler) ValuePrototype(_ int64) datamodel.NodePrototype {
	return _Link__Prototype{}
}
func (TransactionList) Type() schema.Type {
	return nil /*TODO:typelit*/
}
func (n TransactionList) Representation() datamodel.Node {
	return (*_TransactionList__Repr)(n)
}

type _TransactionList__Repr _TransactionList

var _ datamodel.Node = &_TransactionList__Repr{}

func (_TransactionList__Repr) Kind() datamodel.Kind {
	return datamodel.Kind_List
}
func (_TransactionList__Repr) LookupByString(string) (datamodel.Node, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList.Repr"}.LookupByString("")
}
func (nr *_TransactionList__Repr) LookupByNode(k datamodel.Node) (datamodel.Node, error) {
	v, err := (TransactionList)(nr).LookupByNode(k)
	if err != nil || v == datamodel.Null {
		return v, err
	}
	return v.(Link).Representation(), nil
}
func (nr *_TransactionList__Repr) LookupByIndex(idx int64) (datamodel.Node, error) {
	v, err := (TransactionList)(nr).LookupByIndex(idx)
	if err != nil || v == datamodel.Null {
		return v, err
	}
	return v.(Link).Representation(), nil
}
func (n _TransactionList__Repr) LookupBySegment(seg datamodel.PathSegment) (datamodel.Node, error) {
	i, err := seg.Index()
	if err != nil {
		return nil, datamodel.ErrInvalidSegmentForList{TypeName: "ipldsch.TransactionList.Repr", TroubleSegment: seg, Reason: err}
	}
	return n.LookupByIndex(i)
}
func (_TransactionList__Repr) MapIterator() datamodel.MapIterator {
	return nil
}
func (nr *_TransactionList__Repr) ListIterator() datamodel.ListIterator {
	return &_TransactionList__ReprListItr{(TransactionList)(nr), 0}
}

type _TransactionList__ReprListItr _TransactionList__ListItr

func (itr *_TransactionList__ReprListItr) Next() (idx int64, v datamodel.Node, err error) {
	idx, v, err = (*_TransactionList__ListItr)(itr).Next()
	if err != nil || v == datamodel.Null {
		return
	}
	return idx, v.(Link).Representation(), nil
}
func (itr *_TransactionList__ReprListItr) Done() bool {
	return (*_TransactionList__ListItr)(itr).Done()
}

func (rn *_TransactionList__Repr) Length() int64 {
	return int64(len(rn.x))
}
func (_TransactionList__Repr) IsAbsent() bool {
	return false
}
func (_TransactionList__Repr) IsNull() bool {
	return false
}
func (_TransactionList__Repr) AsBool() (bool, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList.Repr"}.AsBool()
}
func (_TransactionList__Repr) AsInt() (int64, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList.Repr"}.AsInt()
}
func (_TransactionList__Repr) AsFloat() (float64, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList.Repr"}.AsFloat()
}
func (_TransactionList__Repr) AsString() (string, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList.Repr"}.AsString()
}
func (_TransactionList__Repr) AsBytes() ([]byte, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList.Repr"}.AsBytes()
}
func (_TransactionList__Repr) AsLink() (datamodel.Link, error) {
	return mixins.List{TypeName: "ipldsch.TransactionList.Repr"}.AsLink()
}
func (_TransactionList__Repr) Prototype() datamodel.NodePrototype {
	return _TransactionList__ReprPrototype{}
}

type _TransactionList__ReprPrototype struct{}

func (_TransactionList__ReprPrototype) NewBuilder() datamodel.NodeBuilder {
	var nb _TransactionList__ReprBuilder
	nb.Reset()
	return &nb
}

type _TransactionList__ReprBuilder struct {
	_TransactionList__ReprAssembler
}

func (nb *_TransactionList__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 *_TransactionList__ReprBuilder) Reset() {
	var w _TransactionList
	var m schema.Maybe
	*nb = _TransactionList__ReprBuilder{_TransactionList__ReprAssembler{w: &w, m: &m}}
}

type _TransactionList__ReprAssembler struct {
	w     *_TransactionList
	m     *schema.Maybe
	state laState

	cm schema.Maybe
	va _Link__ReprAssembler
}

func (na *_TransactionList__ReprAssembler) reset() {
	na.state = laState_initial
	na.va.reset()
}
func (_TransactionList__ReprAssembler) BeginMap(sizeHint int64) (datamodel.MapAssembler, error) {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList.Repr"}.BeginMap(0)
}
func (na *_TransactionList__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: it makes no sense to 'begin' twice on the same assembler!")
	}
	*na.m = midvalue
	if sizeHint < 0 {
		sizeHint = 0
	}
	if sizeHint > 0 {
		na.w.x = make([]_Link, 0, sizeHint)
	}
	return na, nil
}
func (na *_TransactionList__ReprAssembler) AssignNull() error {
	switch *na.m {
	case allowNull:
		*na.m = schema.Maybe_Null
		return nil
	case schema.Maybe_Absent:
		return mixins.ListAssembler{TypeName: "ipldsch.TransactionList.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 (_TransactionList__ReprAssembler) AssignBool(bool) error {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList.Repr"}.AssignBool(false)
}
func (_TransactionList__ReprAssembler) AssignInt(int64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList.Repr"}.AssignInt(0)
}
func (_TransactionList__ReprAssembler) AssignFloat(float64) error {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList.Repr"}.AssignFloat(0)
}
func (_TransactionList__ReprAssembler) AssignString(string) error {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList.Repr"}.AssignString("")
}
func (_TransactionList__ReprAssembler) AssignBytes([]byte) error {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList.Repr"}.AssignBytes(nil)
}
func (_TransactionList__ReprAssembler) AssignLink(datamodel.Link) error {
	return mixins.ListAssembler{TypeName: "ipldsch.TransactionList.Repr"}.AssignLink(nil)
}
func (na *_TransactionList__ReprAssembler) AssignNode(v datamodel.Node) error {
	if v.IsNull() {
		return na.AssignNull()
	}
	if v2, ok := v.(*_TransactionList); 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_List {
		return datamodel.ErrWrongKind{TypeName: "ipldsch.TransactionList.Repr", MethodName: "AssignNode", AppropriateKind: datamodel.KindSet_JustList, ActualKind: v.Kind()}
	}
	itr := v.ListIterator()
	for !itr.Done() {
		_, v, err := itr.Next()
		if err != nil {
			return err
		}
		if err := na.AssembleValue().AssignNode(v); err != nil {
			return err
		}
	}
	return na.Finish()
}
func (_TransactionList__ReprAssembler) Prototype() datamodel.NodePrototype {
	return _TransactionList__ReprPrototype{}
}
func (la *_TransactionList__ReprAssembler) valueFinishTidy() bool {
	switch la.cm {
	case schema.Maybe_Value:
		la.va.w = nil
		la.cm = schema.Maybe_Absent
		la.state = laState_initial
		la.va.reset()
		return true
	default:
		return false
	}
}
func (la *_TransactionList__ReprAssembler) AssembleValue() datamodel.NodeAssembler {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: AssembleValue cannot be called when still in the middle of assembling the previous value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: AssembleValue cannot be called on an assembler that's already finished")
	}
	la.w.x = append(la.w.x, _Link{})
	la.state = laState_midValue
	row := &la.w.x[len(la.w.x)-1]
	la.va.w = row
	la.va.m = &la.cm
	return &la.va
}
func (la *_TransactionList__ReprAssembler) Finish() error {
	switch la.state {
	case laState_initial:
		// carry on
	case laState_midValue:
		if !la.valueFinishTidy() {
			panic("invalid state: Finish cannot be called when in the middle of assembling a value")
		} // if tidy success: carry on
	case laState_finished:
		panic("invalid state: Finish cannot be called on an assembler that's already finished")
	}
	la.state = laState_finished
	*la.m = schema.Maybe_Value
	return nil
}
func (la *_TransactionList__ReprAssembler) ValuePrototype(_ int64) datamodel.NodePrototype {
	return _Link__ReprPrototype{}
}
