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

package generated

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

var _ bebop.Record = &basicTypes{}

type basicTypes struct {
	a_bool bool
	a_byte byte
	a_int16 int16
	a_uint16 uint16
	a_int32 int32
	a_uint32 uint32
	a_int64 int64
	a_uint64 uint64
	a_float32 float32
	a_float64 float64
	a_string string
	a_guid [16]byte
	a_date time.Time
}

func (bbp basicTypes) MarshalBebopTo(buf []byte) int {
	at := 0
	iohelp.WriteBoolBytes(buf[at:], bbp.a_bool)
	at += 1
	iohelp.WriteByteBytes(buf[at:], bbp.a_byte)
	at += 1
	iohelp.WriteInt16Bytes(buf[at:], bbp.a_int16)
	at += 2
	iohelp.WriteUint16Bytes(buf[at:], bbp.a_uint16)
	at += 2
	iohelp.WriteInt32Bytes(buf[at:], bbp.a_int32)
	at += 4
	iohelp.WriteUint32Bytes(buf[at:], bbp.a_uint32)
	at += 4
	iohelp.WriteInt64Bytes(buf[at:], bbp.a_int64)
	at += 8
	iohelp.WriteUint64Bytes(buf[at:], bbp.a_uint64)
	at += 8
	iohelp.WriteFloat32Bytes(buf[at:], bbp.a_float32)
	at += 4
	iohelp.WriteFloat64Bytes(buf[at:], bbp.a_float64)
	at += 8
	iohelp.WriteUint32Bytes(buf[at:], uint32(len(bbp.a_string)))
	copy(buf[at+4:at+4+len(bbp.a_string)], []byte(bbp.a_string))
	at += 4 + len(bbp.a_string)
	iohelp.WriteGUIDBytes(buf[at:], bbp.a_guid)
	at += 16
	if (bbp.a_date).IsZero() {
		iohelp.WriteInt64Bytes(buf[at:], 0)
	} else {
		iohelp.WriteInt64Bytes(buf[at:], ((bbp.a_date).UnixNano() / 100))
	}
	at += 8
	return at
}

func (bbp *basicTypes) UnmarshalBebop(buf []byte) (err error) {
	at := 0
	if len(buf[at:]) < 1 {
		return io.ErrUnexpectedEOF
	}
	bbp.a_bool = iohelp.ReadBoolBytes(buf[at:])
	at += 1
	if len(buf[at:]) < 1 {
		return io.ErrUnexpectedEOF
	}
	bbp.a_byte = iohelp.ReadByteBytes(buf[at:])
	at += 1
	if len(buf[at:]) < 2 {
		return io.ErrUnexpectedEOF
	}
	bbp.a_int16 = iohelp.ReadInt16Bytes(buf[at:])
	at += 2
	if len(buf[at:]) < 2 {
		return io.ErrUnexpectedEOF
	}
	bbp.a_uint16 = iohelp.ReadUint16Bytes(buf[at:])
	at += 2
	if len(buf[at:]) < 4 {
		return io.ErrUnexpectedEOF
	}
	bbp.a_int32 = iohelp.ReadInt32Bytes(buf[at:])
	at += 4
	if len(buf[at:]) < 4 {
		return io.ErrUnexpectedEOF
	}
	bbp.a_uint32 = iohelp.ReadUint32Bytes(buf[at:])
	at += 4
	if len(buf[at:]) < 8 {
		return io.ErrUnexpectedEOF
	}
	bbp.a_int64 = iohelp.ReadInt64Bytes(buf[at:])
	at += 8
	if len(buf[at:]) < 8 {
		return io.ErrUnexpectedEOF
	}
	bbp.a_uint64 = iohelp.ReadUint64Bytes(buf[at:])
	at += 8
	if len(buf[at:]) < 4 {
		return io.ErrUnexpectedEOF
	}
	bbp.a_float32 = iohelp.ReadFloat32Bytes(buf[at:])
	at += 4
	if len(buf[at:]) < 8 {
		return io.ErrUnexpectedEOF
	}
	bbp.a_float64 = iohelp.ReadFloat64Bytes(buf[at:])
	at += 8
	bbp.a_string, err = iohelp.ReadStringBytes(buf[at:])
	if err != nil {
		return err
	}
	at += 4 + len(bbp.a_string)
	if len(buf[at:]) < 16 {
		return io.ErrUnexpectedEOF
	}
	bbp.a_guid = iohelp.ReadGUIDBytes(buf[at:])
	at += 16
	if len(buf[at:]) < 8 {
		return io.ErrUnexpectedEOF
	}
	bbp.a_date = iohelp.ReadDateBytes(buf[at:])
	at += 8
	return nil
}

func (bbp *basicTypes) MustUnmarshalBebop(buf []byte) {
	at := 0
	bbp.a_bool = iohelp.ReadBoolBytes(buf[at:])
	at += 1
	bbp.a_byte = iohelp.ReadByteBytes(buf[at:])
	at += 1
	bbp.a_int16 = iohelp.ReadInt16Bytes(buf[at:])
	at += 2
	bbp.a_uint16 = iohelp.ReadUint16Bytes(buf[at:])
	at += 2
	bbp.a_int32 = iohelp.ReadInt32Bytes(buf[at:])
	at += 4
	bbp.a_uint32 = iohelp.ReadUint32Bytes(buf[at:])
	at += 4
	bbp.a_int64 = iohelp.ReadInt64Bytes(buf[at:])
	at += 8
	bbp.a_uint64 = iohelp.ReadUint64Bytes(buf[at:])
	at += 8
	bbp.a_float32 = iohelp.ReadFloat32Bytes(buf[at:])
	at += 4
	bbp.a_float64 = iohelp.ReadFloat64Bytes(buf[at:])
	at += 8
	bbp.a_string = iohelp.MustReadStringBytes(buf[at:])
	at += 4 + len(bbp.a_string)
	bbp.a_guid = iohelp.ReadGUIDBytes(buf[at:])
	at += 16
	bbp.a_date = iohelp.ReadDateBytes(buf[at:])
	at += 8
}

func (bbp basicTypes) EncodeBebop(iow io.Writer) (err error) {
	w := iohelp.NewErrorWriter(iow)
	iohelp.WriteBool(w, bbp.a_bool)
	iohelp.WriteByte(w, bbp.a_byte)
	iohelp.WriteInt16(w, bbp.a_int16)
	iohelp.WriteUint16(w, bbp.a_uint16)
	iohelp.WriteInt32(w, bbp.a_int32)
	iohelp.WriteUint32(w, bbp.a_uint32)
	iohelp.WriteInt64(w, bbp.a_int64)
	iohelp.WriteUint64(w, bbp.a_uint64)
	iohelp.WriteFloat32(w, bbp.a_float32)
	iohelp.WriteFloat64(w, bbp.a_float64)
	iohelp.WriteUint32(w, uint32(len(bbp.a_string)))
	w.Write([]byte(bbp.a_string))
	iohelp.WriteGUID(w, bbp.a_guid)
	if (bbp.a_date).IsZero() {
		iohelp.WriteInt64(w, 0)
	} else {
		iohelp.WriteInt64(w, ((bbp.a_date).UnixNano() / 100))
	}
	return w.Err
}

func (bbp *basicTypes) DecodeBebop(ior io.Reader) (err error) {
	r := iohelp.NewErrorReader(ior)
	bbp.a_bool = iohelp.ReadBool(r)
	bbp.a_byte = iohelp.ReadByte(r)
	bbp.a_int16 = iohelp.ReadInt16(r)
	bbp.a_uint16 = iohelp.ReadUint16(r)
	bbp.a_int32 = iohelp.ReadInt32(r)
	bbp.a_uint32 = iohelp.ReadUint32(r)
	bbp.a_int64 = iohelp.ReadInt64(r)
	bbp.a_uint64 = iohelp.ReadUint64(r)
	bbp.a_float32 = iohelp.ReadFloat32(r)
	bbp.a_float64 = iohelp.ReadFloat64(r)
	bbp.a_string = iohelp.ReadString(r)
	bbp.a_guid = iohelp.ReadGUID(r)
	bbp.a_date = iohelp.ReadDate(r)
	return r.Err
}

func (bbp basicTypes) Size() int {
	bodyLen := 0
	bodyLen += 1
	bodyLen += 1
	bodyLen += 2
	bodyLen += 2
	bodyLen += 4
	bodyLen += 4
	bodyLen += 8
	bodyLen += 8
	bodyLen += 4
	bodyLen += 8
	bodyLen += 4 + len(bbp.a_string)
	bodyLen += 16
	bodyLen += 8
	return bodyLen
}

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

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

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

func mustMakebasicTypesFromBytes(buf []byte) basicTypes {
	v := basicTypes{}
	v.MustUnmarshalBebop(buf)
	return v
}

