// Code generated by bebop; DO NOT EDIT.

package bebopwellquite

import (
	"io"
	"time"
	"wellquite.org/bebop/runtime"
)

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

// EncodeBebop writes the value to the writer, serialized as Bebop.
func (self *BebopBufWellquite) EncodeBebop(writer io.Writer) error {
	return self.BebopEncodeEncoder(runtime.NewEncoder(writer))
}

// DecodeBebop attempts to read Bebop from the reader and to
// deserialize it into the value.
func (self *BebopBufWellquite) DecodeBebop(reader io.Reader) error {
	_, err := self.BebopDecodeDecoder(runtime.NewDecoder(reader))
	return err
}

// MarshalBebop writes the value into the buf, serialized as
// Bebop. The slice of the buf written to is returned. If the buf is too
// small, a new buf is created, written to, and returned.
func (self *BebopBufWellquite) MarshalBebop(buf []byte) ([]byte, error) {
	size := self.SizeBebop()
	if len(buf) < size {
		buf = make([]byte, size)
	}
	_, err := self.BebopMarshalAt(buf, 0)
	if err != nil {
		return nil, err
	}
	return buf[:size], nil
}

// UnmarshalBebop attempts to read Bebop from the buf and to
// deserialize it into the value.
func (self *BebopBufWellquite) UnmarshalBebop(buf []byte) (int, error) {
	return self.BebopUnmarshalAt(buf, 0)
}

// SizeBebop returns the number of bytes this struct uses when
// serialized to Bebop.
func (self *BebopBufWellquite) SizeBebop() int {
	return 4 + len(self.Name) + 8 + 4 + len(self.Phone) + 4 + 1 + 8
}

// Not intended for public use. This method is public only so that
// other Bebop-generated code in different packages can call it.
func (self *BebopBufWellquite) BebopEncodeEncoder(encoder *runtime.Encoder) (err error) {
	err = encoder.EncodeString(self.Name)
	if err != nil {
		return err
	}
	err = encoder.EncodeDate(self.BirthDay)
	if err != nil {
		return err
	}
	err = encoder.EncodeString(self.Phone)
	if err != nil {
		return err
	}
	err = encoder.EncodeInt32(self.Siblings)
	if err != nil {
		return err
	}
	err = encoder.EncodeBool(self.Spouse)
	if err != nil {
		return err
	}
	err = encoder.EncodeFloat64(self.Money)
	if err != nil {
		return err
	}

	return err
}

// Not intended for public use. This method is public only so that
// other Bebop-generated code in different packages can call it.
func (self *BebopBufWellquite) BebopMarshalAt(buf []byte, offset int) (nextOffset int, err error) {
	offset, err = runtime.BebopMarshalStringAt(buf, offset, self.Name)
	if err != nil {
		return offset, err
	}
	offset, err = runtime.BebopMarshalDateAt(buf, offset, self.BirthDay)
	if err != nil {
		return offset, err
	}
	offset, err = runtime.BebopMarshalStringAt(buf, offset, self.Phone)
	if err != nil {
		return offset, err
	}
	offset, err = runtime.BebopMarshalInt32At(buf, offset, self.Siblings)
	if err != nil {
		return offset, err
	}
	offset, err = runtime.BebopMarshalBoolAt(buf, offset, self.Spouse)
	if err != nil {
		return offset, err
	}
	offset, err = runtime.BebopMarshalFloat64At(buf, offset, self.Money)
	if err != nil {
		return offset, err
	}

	return offset, err
}

// Not intended for public use. This method is public only so that
// other Bebop-generated code in different packages can call it.
func (self *BebopBufWellquite) BebopDecodeDecoder(decoder *runtime.Decoder) (n int, err error) {
	{
		value, m, err := decoder.DecodeString()
		n += m
		if err != nil {
			return n, err
		}
		self.Name = value
	}
	{
		value, m, err := decoder.DecodeDate()
		n += m
		if err != nil {
			return n, err
		}
		self.BirthDay = value
	}
	{
		value, m, err := decoder.DecodeString()
		n += m
		if err != nil {
			return n, err
		}
		self.Phone = value
	}
	{
		value, m, err := decoder.DecodeInt32()
		n += m
		if err != nil {
			return n, err
		}
		self.Siblings = value
	}
	{
		value, m, err := decoder.DecodeBool()
		n += m
		if err != nil {
			return n, err
		}
		self.Spouse = value
	}
	{
		value, m, err := decoder.DecodeFloat64()
		n += m
		if err != nil {
			return n, err
		}
		self.Money = value
	}
	return n, nil
}

// Not intended for public use. This method is public only so that
// other Bebop-generated code in different packages can call it.
func (self *BebopBufWellquite) BebopUnmarshalAt(buf []byte, offset int) (nextOffset int, err error) {
	{
		value, nextOffset, err := runtime.BebopUnmarshalStringAt(buf, offset)
		offset = nextOffset
		if err != nil {
			return offset, err
		}
		self.Name = value
	}
	{
		value, nextOffset, err := runtime.BebopUnmarshalDateAt(buf, offset)
		offset = nextOffset
		if err != nil {
			return offset, err
		}
		self.BirthDay = value
	}
	{
		value, nextOffset, err := runtime.BebopUnmarshalStringAt(buf, offset)
		offset = nextOffset
		if err != nil {
			return offset, err
		}
		self.Phone = value
	}
	{
		value, nextOffset, err := runtime.BebopUnmarshalInt32At(buf, offset)
		offset = nextOffset
		if err != nil {
			return offset, err
		}
		self.Siblings = value
	}
	{
		value, nextOffset, err := runtime.BebopUnmarshalBoolAt(buf, offset)
		offset = nextOffset
		if err != nil {
			return offset, err
		}
		self.Spouse = value
	}
	{
		value, nextOffset, err := runtime.BebopUnmarshalFloat64At(buf, offset)
		offset = nextOffset
		if err != nil {
			return offset, err
		}
		self.Money = value
	}
	return offset, nil
}

