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

package bebop200sc 

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

var _ bebop.Record = &BebopBuf200sc{}

type BebopBuf200sc struct {
	Name string
	BirthDay time.Time
	Phone string
	Siblings int32
	Spouse bool
	Money float64
}

func (bbp *BebopBuf200sc) MarshalBebopTo(buf []byte) int {
	at := 0
	iohelp.WriteUint32Bytes(buf[at:], uint32(len(bbp.Name)))
	copy(buf[at+4:at+4+len(bbp.Name)], []byte(bbp.Name))
	at += 4 + len(bbp.Name)
	if bbp.BirthDay != (time.Time{}) {
		iohelp.WriteInt64Bytes(buf[at:], ((bbp.BirthDay).UnixNano() / 100))
	} else {
		iohelp.WriteInt64Bytes(buf[at:], 0)
	}
	at += 8
	iohelp.WriteUint32Bytes(buf[at:], uint32(len(bbp.Phone)))
	copy(buf[at+4:at+4+len(bbp.Phone)], []byte(bbp.Phone))
	at += 4 + len(bbp.Phone)
	iohelp.WriteInt32Bytes(buf[at:], bbp.Siblings)
	at += 4
	iohelp.WriteBoolBytes(buf[at:], bbp.Spouse)
	at += 1
	iohelp.WriteFloat64Bytes(buf[at:], bbp.Money)
	at += 8
	return at
}

func (bbp *BebopBuf200sc) UnmarshalBebop(buf []byte) (err error) {
	at := 0
	bbp.Name, err = iohelp.ReadStringBytes(buf[at:])
	if err != nil {
		return err
	}
	at += 4 + len(bbp.Name)
	if len(buf[at:]) < 8 {
		return io.ErrUnexpectedEOF
	}
	bbp.BirthDay = iohelp.ReadDateBytes(buf[at:])
	at += 8
	bbp.Phone, err = iohelp.ReadStringBytes(buf[at:])
	if err != nil {
		return err
	}
	at += 4 + len(bbp.Phone)
	if len(buf[at:]) < 4 {
		return io.ErrUnexpectedEOF
	}
	bbp.Siblings = iohelp.ReadInt32Bytes(buf[at:])
	at += 4
	if len(buf[at:]) < 1 {
		return io.ErrUnexpectedEOF
	}
	bbp.Spouse = iohelp.ReadBoolBytes(buf[at:])
	at += 1
	if len(buf[at:]) < 8 {
		return io.ErrUnexpectedEOF
	}
	bbp.Money = iohelp.ReadFloat64Bytes(buf[at:])
	at += 8
	return nil
}

func (bbp *BebopBuf200sc) EncodeBebop(iow io.Writer) (err error) {
	w := iohelp.NewErrorWriter(iow)
	iohelp.WriteUint32(w, uint32(len(bbp.Name)))
	w.Write([]byte(bbp.Name))
	if bbp.BirthDay != (time.Time{}) {
		iohelp.WriteInt64(w, ((bbp.BirthDay).UnixNano() / 100))
	} else {
		iohelp.WriteInt64(w, 0)
	}
	iohelp.WriteUint32(w, uint32(len(bbp.Phone)))
	w.Write([]byte(bbp.Phone))
	iohelp.WriteInt32(w, bbp.Siblings)
	iohelp.WriteBool(w, bbp.Spouse)
	iohelp.WriteFloat64(w, bbp.Money)
	return w.Err
}

func (bbp *BebopBuf200sc) DecodeBebop(ior io.Reader) (err error) {
	r := iohelp.NewErrorReader(ior)
	bbp.Name = iohelp.ReadString(r)
	bbp.BirthDay = iohelp.ReadDate(r)
	bbp.Phone = iohelp.ReadString(r)
	bbp.Siblings = iohelp.ReadInt32(r)
	bbp.Spouse = iohelp.ReadBool(r)
	bbp.Money = iohelp.ReadFloat64(r)
	return r.Err
}

func (bbp *BebopBuf200sc) Size() int {
	bodyLen := 0
	bodyLen += 4 + len(bbp.Name)
	bodyLen += 8
	bodyLen += 4 + len(bbp.Phone)
	bodyLen += 4
	bodyLen += 1
	bodyLen += 8
	return bodyLen
}

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

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

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

