// Code generated by bebopc-go; DO NOT EDIT.

package generated

import (
	"github.com/200sc/bebop"
	"github.com/200sc/bebop/iohelp"
	"io"
)

type depE uint32

const (
	// Deprecated: X in DepE
	depE_X depE = 1
)

// Documented enum 
type docE uint32

const (
	// Documented constant 
	docE_X docE = 1
	// Deprecated: Y in DocE
	docE_Y docE = 2
	// Deprecated, documented constant 
	// Deprecated: Z in DocE
	docE_Z docE = 3
)

var _ bebop.Record = &docS{}

// Documented struct 
type docS struct {
	// Documented field 
	x int32
}

func (bbp docS) MarshalBebopTo(buf []byte) int {
	at := 0
	iohelp.WriteInt32Bytes(buf[at:], bbp.x)
	at += 4
	return at
}

func (bbp *docS) UnmarshalBebop(buf []byte) (err error) {
	at := 0
	if len(buf[at:]) < 4 {
		return io.ErrUnexpectedEOF
	}
	bbp.x = iohelp.ReadInt32Bytes(buf[at:])
	at += 4
	return nil
}

func (bbp *docS) MustUnmarshalBebop(buf []byte) {
	at := 0
	bbp.x = iohelp.ReadInt32Bytes(buf[at:])
	at += 4
}

func (bbp docS) EncodeBebop(iow io.Writer) (err error) {
	w := iohelp.NewErrorWriter(iow)
	iohelp.WriteInt32(w, bbp.x)
	return w.Err
}

func (bbp *docS) DecodeBebop(ior io.Reader) (err error) {
	r := iohelp.NewErrorReader(ior)
	bbp.x = iohelp.ReadInt32(r)
	return r.Err
}

func (bbp docS) Size() int {
	bodyLen := 0
	bodyLen += 4
	return bodyLen
}

func (bbp docS) MarshalBebop() []byte {
	buf := make([]byte, bbp.Size())
	bbp.MarshalBebopTo(buf)
	return buf
}

func makedocS(r *iohelp.ErrorReader) (docS, error) {
	v := docS{}
	err := v.DecodeBebop(r)
	return v, err
}

func makedocSFromBytes(buf []byte) (docS, error) {
	v := docS{}
	err := v.UnmarshalBebop(buf)
	return v, err
}

func mustMakedocSFromBytes(buf []byte) docS {
	v := docS{}
	v.MustUnmarshalBebop(buf)
	return v
}

var _ bebop.Record = &depM{}

type depM struct {
	// Deprecated: x in DepM
	x *int32
}

func (bbp depM) MarshalBebopTo(buf []byte) int {
	at := 0
	iohelp.WriteUint32Bytes(buf[at:], uint32(bbp.Size()-4))
	at += 4
	return at
}

func (bbp *depM) UnmarshalBebop(buf []byte) (err error) {
	at := 0
	_ = iohelp.ReadUint32Bytes(buf[at:])
	buf = buf[4:]
	for {
		switch buf[at] {
		case 1:
			at += 1
			bbp.x = new(int32)
			if len(buf[at:]) < 4 {
				return io.ErrUnexpectedEOF
			}
			(*bbp.x) = iohelp.ReadInt32Bytes(buf[at:])
			at += 4
		default:
			return nil
		}
	}
}

func (bbp *depM) MustUnmarshalBebop(buf []byte) {
	at := 0
	_ = iohelp.ReadUint32Bytes(buf[at:])
	buf = buf[4:]
	for {
		switch buf[at] {
		case 1:
			at += 1
			bbp.x = new(int32)
			(*bbp.x) = iohelp.ReadInt32Bytes(buf[at:])
			at += 4
		default:
			return
		}
	}
}

func (bbp depM) EncodeBebop(iow io.Writer) (err error) {
	w := iohelp.NewErrorWriter(iow)
	iohelp.WriteUint32(w, uint32(bbp.Size()-4))
	w.Write([]byte{0})
	return w.Err
}

func (bbp *depM) DecodeBebop(ior io.Reader) (err error) {
	r := iohelp.NewErrorReader(ior)
	bodyLen := iohelp.ReadUint32(r)
	baseReader := r.Reader
	r.Reader = &io.LimitedReader{R: baseReader, N: int64(bodyLen)}
	for {
		switch iohelp.ReadByte(r) {
		case 1:
			bbp.x = new(int32)
			*bbp.x = iohelp.ReadInt32(r)
		default:
			r.Drain()
			r.Reader = baseReader
			return r.Err
		}
	}
}

func (bbp depM) Size() int {
	bodyLen := 5
	return bodyLen
}

func (bbp depM) MarshalBebop() []byte {
	buf := make([]byte, bbp.Size())
	bbp.MarshalBebopTo(buf)
	return buf
}

func makedepM(r *iohelp.ErrorReader) (depM, error) {
	v := depM{}
	err := v.DecodeBebop(r)
	return v, err
}

func makedepMFromBytes(buf []byte) (depM, error) {
	v := depM{}
	err := v.UnmarshalBebop(buf)
	return v, err
}

func mustMakedepMFromBytes(buf []byte) depM {
	v := depM{}
	v.MustUnmarshalBebop(buf)
	return v
}

var _ bebop.Record = &docM{}

// Documented message 
type docM struct {
	// Documented field 
	x *int32
	// Deprecated: y in DocM
	y *int32
	// Deprecated, documented field 
	// Deprecated: z in DocM
	z *int32
}

func (bbp docM) MarshalBebopTo(buf []byte) int {
	at := 0
	iohelp.WriteUint32Bytes(buf[at:], uint32(bbp.Size()-4))
	at += 4
	if bbp.x != nil {
		buf[at] = 1
		at++
		iohelp.WriteInt32Bytes(buf[at:], *bbp.x)
		at += 4
	}
	return at
}

func (bbp *docM) UnmarshalBebop(buf []byte) (err error) {
	at := 0
	_ = iohelp.ReadUint32Bytes(buf[at:])
	buf = buf[4:]
	for {
		switch buf[at] {
		case 1:
			at += 1
			bbp.x = new(int32)
			if len(buf[at:]) < 4 {
				return io.ErrUnexpectedEOF
			}
			(*bbp.x) = iohelp.ReadInt32Bytes(buf[at:])
			at += 4
		case 2:
			at += 1
			bbp.y = new(int32)
			if len(buf[at:]) < 4 {
				return io.ErrUnexpectedEOF
			}
			(*bbp.y) = iohelp.ReadInt32Bytes(buf[at:])
			at += 4
		case 3:
			at += 1
			bbp.z = new(int32)
			if len(buf[at:]) < 4 {
				return io.ErrUnexpectedEOF
			}
			(*bbp.z) = iohelp.ReadInt32Bytes(buf[at:])
			at += 4
		default:
			return nil
		}
	}
}

func (bbp *docM) MustUnmarshalBebop(buf []byte) {
	at := 0
	_ = iohelp.ReadUint32Bytes(buf[at:])
	buf = buf[4:]
	for {
		switch buf[at] {
		case 1:
			at += 1
			bbp.x = new(int32)
			(*bbp.x) = iohelp.ReadInt32Bytes(buf[at:])
			at += 4
		case 2:
			at += 1
			bbp.y = new(int32)
			(*bbp.y) = iohelp.ReadInt32Bytes(buf[at:])
			at += 4
		case 3:
			at += 1
			bbp.z = new(int32)
			(*bbp.z) = iohelp.ReadInt32Bytes(buf[at:])
			at += 4
		default:
			return
		}
	}
}

func (bbp docM) EncodeBebop(iow io.Writer) (err error) {
	w := iohelp.NewErrorWriter(iow)
	iohelp.WriteUint32(w, uint32(bbp.Size()-4))
	if bbp.x != nil {
		w.Write([]byte{1})
		iohelp.WriteInt32(w, *bbp.x)
	}
	w.Write([]byte{0})
	return w.Err
}

func (bbp *docM) DecodeBebop(ior io.Reader) (err error) {
	r := iohelp.NewErrorReader(ior)
	bodyLen := iohelp.ReadUint32(r)
	baseReader := r.Reader
	r.Reader = &io.LimitedReader{R: baseReader, N: int64(bodyLen)}
	for {
		switch iohelp.ReadByte(r) {
		case 1:
			bbp.x = new(int32)
			*bbp.x = iohelp.ReadInt32(r)
		case 2:
			bbp.y = new(int32)
			*bbp.y = iohelp.ReadInt32(r)
		case 3:
			bbp.z = new(int32)
			*bbp.z = iohelp.ReadInt32(r)
		default:
			r.Drain()
			r.Reader = baseReader
			return r.Err
		}
	}
}

func (bbp docM) Size() int {
	bodyLen := 5
	if bbp.x != nil {
		bodyLen += 1
		bodyLen += 4
	}
	return bodyLen
}

func (bbp docM) MarshalBebop() []byte {
	buf := make([]byte, bbp.Size())
	bbp.MarshalBebopTo(buf)
	return buf
}

func makedocM(r *iohelp.ErrorReader) (docM, error) {
	v := docM{}
	err := v.DecodeBebop(r)
	return v, err
}

func makedocMFromBytes(buf []byte) (docM, error) {
	v := docM{}
	err := v.UnmarshalBebop(buf)
	return v, err
}

func mustMakedocMFromBytes(buf []byte) docM {
	v := docM{}
	v.MustUnmarshalBebop(buf)
	return v
}

