// Code generated by fastssz. DO NOT EDIT.
package ethereum_beacon_p2p_v1

import (
	"fmt"

	ssz "github.com/ferranbt/fastssz"
	v1alpha1 "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
)

var (
	errDivideInt           = fmt.Errorf("incorrect int divide")
	errListTooBig          = fmt.Errorf("incorrect list size, too big")
	errMarshalDynamicBytes = fmt.Errorf("incorrect dynamic bytes marshalling")
	errMarshalFixedBytes   = fmt.Errorf("incorrect fixed bytes marshalling")
	errMarshalList         = fmt.Errorf("incorrect vector list")
	errMarshalVector       = fmt.Errorf("incorrect vector marshalling")
	errOffset              = fmt.Errorf("incorrect offset")
	errSize                = fmt.Errorf("incorrect size")
)

// MarshalSSZ ssz marshals the BeaconState object
func (b *BeaconState) MarshalSSZ() ([]byte, error) {
	buf := make([]byte, b.SizeSSZ())
	return b.MarshalSSZTo(buf[:0])
}

// MarshalSSZTo ssz marshals the BeaconState object to a target array
func (b *BeaconState) MarshalSSZTo(dst []byte) ([]byte, error) {
	var err error
	offset := int(2687377)

	// Field (0) 'GenesisTime'
	dst = ssz.MarshalUint64(dst, b.GenesisTime)

	// Field (1) 'GenesisValidatorsRoot'
	if dst, err = ssz.MarshalFixedBytes(dst, b.GenesisValidatorsRoot, 32); err != nil {
		return nil, errMarshalFixedBytes
	}

	// Field (2) 'Slot'
	dst = ssz.MarshalUint64(dst, b.Slot)

	// Field (3) 'Fork'
	if b.Fork == nil {
		b.Fork = new(Fork)
	}
	if dst, err = b.Fork.MarshalSSZTo(dst); err != nil {
		return nil, err
	}

	// Field (4) 'LatestBlockHeader'
	if b.LatestBlockHeader == nil {
		b.LatestBlockHeader = new(v1alpha1.BeaconBlockHeader)
	}
	if dst, err = b.LatestBlockHeader.MarshalSSZTo(dst); err != nil {
		return nil, err
	}

	// Field (5) 'BlockRoots'
	if len(b.BlockRoots) != 8192 {
		return nil, errMarshalVector
	}
	for ii := 0; ii < 8192; ii++ {
		if dst, err = ssz.MarshalFixedBytes(dst, b.BlockRoots[ii], 32); err != nil {
			return nil, errMarshalFixedBytes
		}
	}

	// Field (6) 'StateRoots'
	if len(b.StateRoots) != 8192 {
		return nil, errMarshalVector
	}
	for ii := 0; ii < 8192; ii++ {
		if dst, err = ssz.MarshalFixedBytes(dst, b.StateRoots[ii], 32); err != nil {
			return nil, errMarshalFixedBytes
		}
	}

	// Offset (7) 'HistoricalRoots'
	dst = ssz.WriteOffset(dst, offset)
	offset += len(b.HistoricalRoots) * 32

	// Field (8) 'Eth1Data'
	if b.Eth1Data == nil {
		b.Eth1Data = new(v1alpha1.Eth1Data)
	}
	if dst, err = b.Eth1Data.MarshalSSZTo(dst); err != nil {
		return nil, err
	}

	// Offset (9) 'Eth1DataVotes'
	dst = ssz.WriteOffset(dst, offset)
	offset += len(b.Eth1DataVotes) * 72

	// Field (10) 'Eth1DepositIndex'
	dst = ssz.MarshalUint64(dst, b.Eth1DepositIndex)

	// Offset (11) 'Validators'
	dst = ssz.WriteOffset(dst, offset)
	offset += len(b.Validators) * 121

	// Offset (12) 'Balances'
	dst = ssz.WriteOffset(dst, offset)
	offset += len(b.Balances) * 8

	// Field (13) 'RandaoMixes'
	if len(b.RandaoMixes) != 65536 {
		return nil, errMarshalVector
	}
	for ii := 0; ii < 65536; ii++ {
		if dst, err = ssz.MarshalFixedBytes(dst, b.RandaoMixes[ii], 32); err != nil {
			return nil, errMarshalFixedBytes
		}
	}

	// Field (14) 'Slashings'
	if len(b.Slashings) != 8192 {
		return nil, errMarshalVector
	}
	for ii := 0; ii < 8192; ii++ {
		dst = ssz.MarshalUint64(dst, b.Slashings[ii])
	}

	// Offset (15) 'PreviousEpochAttestations'
	dst = ssz.WriteOffset(dst, offset)
	for ii := 0; ii < len(b.PreviousEpochAttestations); ii++ {
		offset += 4
		offset += b.PreviousEpochAttestations[ii].SizeSSZ()
	}

	// Offset (16) 'CurrentEpochAttestations'
	dst = ssz.WriteOffset(dst, offset)
	for ii := 0; ii < len(b.CurrentEpochAttestations); ii++ {
		offset += 4
		offset += b.CurrentEpochAttestations[ii].SizeSSZ()
	}

	// Field (17) 'JustificationBits'
	if dst, err = ssz.MarshalFixedBytes(dst, b.JustificationBits, 1); err != nil {
		return nil, errMarshalFixedBytes
	}

	// Field (18) 'PreviousJustifiedCheckpoint'
	if b.PreviousJustifiedCheckpoint == nil {
		b.PreviousJustifiedCheckpoint = new(v1alpha1.Checkpoint)
	}
	if dst, err = b.PreviousJustifiedCheckpoint.MarshalSSZTo(dst); err != nil {
		return nil, err
	}

	// Field (19) 'CurrentJustifiedCheckpoint'
	if b.CurrentJustifiedCheckpoint == nil {
		b.CurrentJustifiedCheckpoint = new(v1alpha1.Checkpoint)
	}
	if dst, err = b.CurrentJustifiedCheckpoint.MarshalSSZTo(dst); err != nil {
		return nil, err
	}

	// Field (20) 'FinalizedCheckpoint'
	if b.FinalizedCheckpoint == nil {
		b.FinalizedCheckpoint = new(v1alpha1.Checkpoint)
	}
	if dst, err = b.FinalizedCheckpoint.MarshalSSZTo(dst); err != nil {
		return nil, err
	}

	// Field (7) 'HistoricalRoots'
	if len(b.HistoricalRoots) > 16777216 {
		return nil, errMarshalList
	}
	for ii := 0; ii < len(b.HistoricalRoots); ii++ {
		if dst, err = ssz.MarshalFixedBytes(dst, b.HistoricalRoots[ii], 32); err != nil {
			return nil, errMarshalFixedBytes
		}
	}

	// Field (9) 'Eth1DataVotes'
	if len(b.Eth1DataVotes) > 1024 {
		return nil, errMarshalList
	}
	for ii := 0; ii < len(b.Eth1DataVotes); ii++ {
		if dst, err = b.Eth1DataVotes[ii].MarshalSSZTo(dst); err != nil {
			return nil, err
		}
	}

	// Field (11) 'Validators'
	if len(b.Validators) > 1099511627776 {
		return nil, errMarshalList
	}
	for ii := 0; ii < len(b.Validators); ii++ {
		if dst, err = b.Validators[ii].MarshalSSZTo(dst); err != nil {
			return nil, err
		}
	}

	// Field (12) 'Balances'
	if len(b.Balances) > 1099511627776 {
		return nil, errMarshalList
	}
	for ii := 0; ii < len(b.Balances); ii++ {
		dst = ssz.MarshalUint64(dst, b.Balances[ii])
	}

	// Field (15) 'PreviousEpochAttestations'
	if len(b.PreviousEpochAttestations) > 4096 {
		return nil, errMarshalList
	}
	{
		offset = 4 * len(b.PreviousEpochAttestations)
		for ii := 0; ii < len(b.PreviousEpochAttestations); ii++ {
			dst = ssz.WriteOffset(dst, offset)
			offset += b.PreviousEpochAttestations[ii].SizeSSZ()
		}
	}
	for ii := 0; ii < len(b.PreviousEpochAttestations); ii++ {
		if dst, err = b.PreviousEpochAttestations[ii].MarshalSSZTo(dst); err != nil {
			return nil, err
		}
	}

	// Field (16) 'CurrentEpochAttestations'
	if len(b.CurrentEpochAttestations) > 4096 {
		return nil, errMarshalList
	}
	{
		offset = 4 * len(b.CurrentEpochAttestations)
		for ii := 0; ii < len(b.CurrentEpochAttestations); ii++ {
			dst = ssz.WriteOffset(dst, offset)
			offset += b.CurrentEpochAttestations[ii].SizeSSZ()
		}
	}
	for ii := 0; ii < len(b.CurrentEpochAttestations); ii++ {
		if dst, err = b.CurrentEpochAttestations[ii].MarshalSSZTo(dst); err != nil {
			return nil, err
		}
	}

	return dst, err
}

// UnmarshalSSZ ssz unmarshals the BeaconState object
func (b *BeaconState) UnmarshalSSZ(buf []byte) error {
	var err error
	size := uint64(len(buf))
	if size < 2687377 {
		return errSize
	}

	tail := buf
	var o7, o9, o11, o12, o15, o16 uint64

	// Field (0) 'GenesisTime'
	b.GenesisTime = ssz.UnmarshallUint64(buf[0:8])

	// Field (1) 'GenesisValidatorsRoot'
	b.GenesisValidatorsRoot = append(b.GenesisValidatorsRoot, buf[8:40]...)

	// Field (2) 'Slot'
	b.Slot = ssz.UnmarshallUint64(buf[40:48])

	// Field (3) 'Fork'
	if b.Fork == nil {
		b.Fork = new(Fork)
	}
	if err = b.Fork.UnmarshalSSZ(buf[48:64]); err != nil {
		return err
	}

	// Field (4) 'LatestBlockHeader'
	if b.LatestBlockHeader == nil {
		b.LatestBlockHeader = new(v1alpha1.BeaconBlockHeader)
	}
	if err = b.LatestBlockHeader.UnmarshalSSZ(buf[64:176]); err != nil {
		return err
	}

	// Field (5) 'BlockRoots'
	b.BlockRoots = make([][]byte, 8192)
	for ii := 0; ii < 8192; ii++ {
		b.BlockRoots[ii] = append(b.BlockRoots[ii], buf[176:262320][ii*32:(ii+1)*32]...)
	}

	// Field (6) 'StateRoots'
	b.StateRoots = make([][]byte, 8192)
	for ii := 0; ii < 8192; ii++ {
		b.StateRoots[ii] = append(b.StateRoots[ii], buf[262320:524464][ii*32:(ii+1)*32]...)
	}

	// Offset (7) 'HistoricalRoots'
	if o7 = ssz.ReadOffset(buf[524464:524468]); o7 > size {
		return errOffset
	}

	// Field (8) 'Eth1Data'
	if b.Eth1Data == nil {
		b.Eth1Data = new(v1alpha1.Eth1Data)
	}
	if err = b.Eth1Data.UnmarshalSSZ(buf[524468:524540]); err != nil {
		return err
	}

	// Offset (9) 'Eth1DataVotes'
	if o9 = ssz.ReadOffset(buf[524540:524544]); o9 > size || o7 > o9 {
		return errOffset
	}

	// Field (10) 'Eth1DepositIndex'
	b.Eth1DepositIndex = ssz.UnmarshallUint64(buf[524544:524552])

	// Offset (11) 'Validators'
	if o11 = ssz.ReadOffset(buf[524552:524556]); o11 > size || o9 > o11 {
		return errOffset
	}

	// Offset (12) 'Balances'
	if o12 = ssz.ReadOffset(buf[524556:524560]); o12 > size || o11 > o12 {
		return errOffset
	}

	// Field (13) 'RandaoMixes'
	b.RandaoMixes = make([][]byte, 65536)
	for ii := 0; ii < 65536; ii++ {
		b.RandaoMixes[ii] = append(b.RandaoMixes[ii], buf[524560:2621712][ii*32:(ii+1)*32]...)
	}

	// Field (14) 'Slashings'
	b.Slashings = ssz.ExtendUint64(b.Slashings, 8192)
	for ii := 0; ii < 8192; ii++ {
		b.Slashings[ii] = ssz.UnmarshallUint64(buf[2621712:2687248][ii*8 : (ii+1)*8])
	}

	// Offset (15) 'PreviousEpochAttestations'
	if o15 = ssz.ReadOffset(buf[2687248:2687252]); o15 > size || o12 > o15 {
		return errOffset
	}

	// Offset (16) 'CurrentEpochAttestations'
	if o16 = ssz.ReadOffset(buf[2687252:2687256]); o16 > size || o15 > o16 {
		return errOffset
	}

	// Field (17) 'JustificationBits'
	b.JustificationBits = append(b.JustificationBits, buf[2687256:2687257]...)

	// Field (18) 'PreviousJustifiedCheckpoint'
	if b.PreviousJustifiedCheckpoint == nil {
		b.PreviousJustifiedCheckpoint = new(v1alpha1.Checkpoint)
	}
	if err = b.PreviousJustifiedCheckpoint.UnmarshalSSZ(buf[2687257:2687297]); err != nil {
		return err
	}

	// Field (19) 'CurrentJustifiedCheckpoint'
	if b.CurrentJustifiedCheckpoint == nil {
		b.CurrentJustifiedCheckpoint = new(v1alpha1.Checkpoint)
	}
	if err = b.CurrentJustifiedCheckpoint.UnmarshalSSZ(buf[2687297:2687337]); err != nil {
		return err
	}

	// Field (20) 'FinalizedCheckpoint'
	if b.FinalizedCheckpoint == nil {
		b.FinalizedCheckpoint = new(v1alpha1.Checkpoint)
	}
	if err = b.FinalizedCheckpoint.UnmarshalSSZ(buf[2687337:2687377]); err != nil {
		return err
	}

	// Field (7) 'HistoricalRoots'
	{
		buf = tail[o7:o9]
		num, ok := ssz.DivideInt(len(buf), 32)
		if !ok {
			return errDivideInt
		}
		if num > 16777216 {
			return errListTooBig
		}
		b.HistoricalRoots = make([][]byte, num)
		for ii := 0; ii < num; ii++ {
			b.HistoricalRoots[ii] = append(b.HistoricalRoots[ii], buf[ii*32:(ii+1)*32]...)
		}
	}

	// Field (9) 'Eth1DataVotes'
	{
		buf = tail[o9:o11]
		num, ok := ssz.DivideInt(len(buf), 72)
		if !ok {
			return errDivideInt
		}
		if num > 1024 {
			return errListTooBig
		}
		b.Eth1DataVotes = make([]*v1alpha1.Eth1Data, num)
		for ii := 0; ii < num; ii++ {
			if b.Eth1DataVotes[ii] == nil {
				b.Eth1DataVotes[ii] = new(v1alpha1.Eth1Data)
			}
			if err = b.Eth1DataVotes[ii].UnmarshalSSZ(buf[ii*72 : (ii+1)*72]); err != nil {
				return err
			}
		}
	}

	// Field (11) 'Validators'
	{
		buf = tail[o11:o12]
		num, ok := ssz.DivideInt(len(buf), 121)
		if !ok {
			return errDivideInt
		}
		if num > 1099511627776 {
			return errListTooBig
		}
		b.Validators = make([]*v1alpha1.Validator, num)
		for ii := 0; ii < num; ii++ {
			if b.Validators[ii] == nil {
				b.Validators[ii] = new(v1alpha1.Validator)
			}
			if err = b.Validators[ii].UnmarshalSSZ(buf[ii*121 : (ii+1)*121]); err != nil {
				return err
			}
		}
	}

	// Field (12) 'Balances'
	{
		buf = tail[o12:o15]
		num, ok := ssz.DivideInt(len(buf), 8)
		if !ok {
			return errDivideInt
		}
		if num > 1099511627776 {
			return errListTooBig
		}
		b.Balances = ssz.ExtendUint64(b.Balances, num)
		for ii := 0; ii < num; ii++ {
			b.Balances[ii] = ssz.UnmarshallUint64(buf[ii*8 : (ii+1)*8])
		}
	}

	// Field (15) 'PreviousEpochAttestations'
	{
		buf = tail[o15:o16]
		num, err := ssz.DecodeDynamicLength(buf, 4096)
		if err != nil {
			return err
		}
		b.PreviousEpochAttestations = make([]*PendingAttestation, num)
		err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) {
			if b.PreviousEpochAttestations[indx] == nil {
				b.PreviousEpochAttestations[indx] = new(PendingAttestation)
			}
			if err = b.PreviousEpochAttestations[indx].UnmarshalSSZ(buf); err != nil {
				return err
			}
			return nil
		})
		if err != nil {
			return err
		}
	}

	// Field (16) 'CurrentEpochAttestations'
	{
		buf = tail[o16:]
		num, err := ssz.DecodeDynamicLength(buf, 4096)
		if err != nil {
			return err
		}
		b.CurrentEpochAttestations = make([]*PendingAttestation, num)
		err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) {
			if b.CurrentEpochAttestations[indx] == nil {
				b.CurrentEpochAttestations[indx] = new(PendingAttestation)
			}
			if err = b.CurrentEpochAttestations[indx].UnmarshalSSZ(buf); err != nil {
				return err
			}
			return nil
		})
		if err != nil {
			return err
		}
	}
	return err
}

// SizeSSZ returns the ssz encoded size in bytes for the BeaconState object
func (b *BeaconState) SizeSSZ() (size int) {
	size = 2687377

	// Field (7) 'HistoricalRoots'
	size += len(b.HistoricalRoots) * 32

	// Field (9) 'Eth1DataVotes'
	size += len(b.Eth1DataVotes) * 72

	// Field (11) 'Validators'
	size += len(b.Validators) * 121

	// Field (12) 'Balances'
	size += len(b.Balances) * 8

	// Field (15) 'PreviousEpochAttestations'
	for ii := 0; ii < len(b.PreviousEpochAttestations); ii++ {
		size += 4
		size += b.PreviousEpochAttestations[ii].SizeSSZ()
	}

	// Field (16) 'CurrentEpochAttestations'
	for ii := 0; ii < len(b.CurrentEpochAttestations); ii++ {
		size += 4
		size += b.CurrentEpochAttestations[ii].SizeSSZ()
	}

	return
}

// MarshalSSZ ssz marshals the Fork object
func (f *Fork) MarshalSSZ() ([]byte, error) {
	buf := make([]byte, f.SizeSSZ())
	return f.MarshalSSZTo(buf[:0])
}

// MarshalSSZTo ssz marshals the Fork object to a target array
func (f *Fork) MarshalSSZTo(dst []byte) ([]byte, error) {
	var err error

	// Field (0) 'PreviousVersion'
	if dst, err = ssz.MarshalFixedBytes(dst, f.PreviousVersion, 4); err != nil {
		return nil, errMarshalFixedBytes
	}

	// Field (1) 'CurrentVersion'
	if dst, err = ssz.MarshalFixedBytes(dst, f.CurrentVersion, 4); err != nil {
		return nil, errMarshalFixedBytes
	}

	// Field (2) 'Epoch'
	dst = ssz.MarshalUint64(dst, f.Epoch)

	return dst, err
}

// UnmarshalSSZ ssz unmarshals the Fork object
func (f *Fork) UnmarshalSSZ(buf []byte) error {
	var err error
	size := uint64(len(buf))
	if size != 16 {
		return errSize
	}

	// Field (0) 'PreviousVersion'
	f.PreviousVersion = append(f.PreviousVersion, buf[0:4]...)

	// Field (1) 'CurrentVersion'
	f.CurrentVersion = append(f.CurrentVersion, buf[4:8]...)

	// Field (2) 'Epoch'
	f.Epoch = ssz.UnmarshallUint64(buf[8:16])

	return err
}

// SizeSSZ returns the ssz encoded size in bytes for the Fork object
func (f *Fork) SizeSSZ() (size int) {
	size = 16
	return
}

// MarshalSSZ ssz marshals the PendingAttestation object
func (p *PendingAttestation) MarshalSSZ() ([]byte, error) {
	buf := make([]byte, p.SizeSSZ())
	return p.MarshalSSZTo(buf[:0])
}

// MarshalSSZTo ssz marshals the PendingAttestation object to a target array
func (p *PendingAttestation) MarshalSSZTo(dst []byte) ([]byte, error) {
	var err error
	offset := int(148)

	// Offset (0) 'AggregationBits'
	dst = ssz.WriteOffset(dst, offset)
	offset += len(p.AggregationBits)

	// Field (1) 'Data'
	if p.Data == nil {
		p.Data = new(v1alpha1.AttestationData)
	}
	if dst, err = p.Data.MarshalSSZTo(dst); err != nil {
		return nil, err
	}

	// Field (2) 'InclusionDelay'
	dst = ssz.MarshalUint64(dst, p.InclusionDelay)

	// Field (3) 'ProposerIndex'
	dst = ssz.MarshalUint64(dst, p.ProposerIndex)

	// Field (0) 'AggregationBits'
	dst = append(dst, p.AggregationBits...)

	return dst, err
}

// UnmarshalSSZ ssz unmarshals the PendingAttestation object
func (p *PendingAttestation) UnmarshalSSZ(buf []byte) error {
	var err error
	size := uint64(len(buf))
	if size < 148 {
		return errSize
	}

	tail := buf
	var o0 uint64

	// Offset (0) 'AggregationBits'
	if o0 = ssz.ReadOffset(buf[0:4]); o0 > size {
		return errOffset
	}

	// Field (1) 'Data'
	if p.Data == nil {
		p.Data = new(v1alpha1.AttestationData)
	}
	if err = p.Data.UnmarshalSSZ(buf[4:132]); err != nil {
		return err
	}

	// Field (2) 'InclusionDelay'
	p.InclusionDelay = ssz.UnmarshallUint64(buf[132:140])

	// Field (3) 'ProposerIndex'
	p.ProposerIndex = ssz.UnmarshallUint64(buf[140:148])

	// Field (0) 'AggregationBits'
	{
		buf = tail[o0:]
		p.AggregationBits = append(p.AggregationBits, buf...)
	}
	return err
}

// SizeSSZ returns the ssz encoded size in bytes for the PendingAttestation object
func (p *PendingAttestation) SizeSSZ() (size int) {
	size = 148

	// Field (0) 'AggregationBits'
	size += len(p.AggregationBits)

	return
}

// MarshalSSZ ssz marshals the HistoricalBatch object
func (h *HistoricalBatch) MarshalSSZ() ([]byte, error) {
	buf := make([]byte, h.SizeSSZ())
	return h.MarshalSSZTo(buf[:0])
}

// MarshalSSZTo ssz marshals the HistoricalBatch object to a target array
func (h *HistoricalBatch) MarshalSSZTo(dst []byte) ([]byte, error) {
	var err error

	// Field (0) 'BlockRoots'
	if len(h.BlockRoots) != 8192 {
		return nil, errMarshalVector
	}
	for ii := 0; ii < 8192; ii++ {
		if dst, err = ssz.MarshalFixedBytes(dst, h.BlockRoots[ii], 32); err != nil {
			return nil, errMarshalFixedBytes
		}
	}

	// Field (1) 'StateRoots'
	if len(h.StateRoots) != 8192 {
		return nil, errMarshalVector
	}
	for ii := 0; ii < 8192; ii++ {
		if dst, err = ssz.MarshalFixedBytes(dst, h.StateRoots[ii], 32); err != nil {
			return nil, errMarshalFixedBytes
		}
	}

	return dst, err
}

// UnmarshalSSZ ssz unmarshals the HistoricalBatch object
func (h *HistoricalBatch) UnmarshalSSZ(buf []byte) error {
	var err error
	size := uint64(len(buf))
	if size != 524288 {
		return errSize
	}

	// Field (0) 'BlockRoots'
	h.BlockRoots = make([][]byte, 8192)
	for ii := 0; ii < 8192; ii++ {
		h.BlockRoots[ii] = append(h.BlockRoots[ii], buf[0:262144][ii*32:(ii+1)*32]...)
	}

	// Field (1) 'StateRoots'
	h.StateRoots = make([][]byte, 8192)
	for ii := 0; ii < 8192; ii++ {
		h.StateRoots[ii] = append(h.StateRoots[ii], buf[262144:524288][ii*32:(ii+1)*32]...)
	}

	return err
}

// SizeSSZ returns the ssz encoded size in bytes for the HistoricalBatch object
func (h *HistoricalBatch) SizeSSZ() (size int) {
	size = 524288
	return
}

// MarshalSSZ ssz marshals the Status object
func (s *Status) MarshalSSZ() ([]byte, error) {
	buf := make([]byte, s.SizeSSZ())
	return s.MarshalSSZTo(buf[:0])
}

// MarshalSSZTo ssz marshals the Status object to a target array
func (s *Status) MarshalSSZTo(dst []byte) ([]byte, error) {
	var err error

	// Field (0) 'ForkDigest'
	if dst, err = ssz.MarshalFixedBytes(dst, s.ForkDigest, 4); err != nil {
		return nil, errMarshalFixedBytes
	}

	// Field (1) 'FinalizedRoot'
	if dst, err = ssz.MarshalFixedBytes(dst, s.FinalizedRoot, 32); err != nil {
		return nil, errMarshalFixedBytes
	}

	// Field (2) 'FinalizedEpoch'
	dst = ssz.MarshalUint64(dst, s.FinalizedEpoch)

	// Field (3) 'HeadRoot'
	if dst, err = ssz.MarshalFixedBytes(dst, s.HeadRoot, 32); err != nil {
		return nil, errMarshalFixedBytes
	}

	// Field (4) 'HeadSlot'
	dst = ssz.MarshalUint64(dst, s.HeadSlot)

	return dst, err
}

// UnmarshalSSZ ssz unmarshals the Status object
func (s *Status) UnmarshalSSZ(buf []byte) error {
	var err error
	size := uint64(len(buf))
	if size != 84 {
		return errSize
	}

	// Field (0) 'ForkDigest'
	s.ForkDigest = append(s.ForkDigest, buf[0:4]...)

	// Field (1) 'FinalizedRoot'
	s.FinalizedRoot = append(s.FinalizedRoot, buf[4:36]...)

	// Field (2) 'FinalizedEpoch'
	s.FinalizedEpoch = ssz.UnmarshallUint64(buf[36:44])

	// Field (3) 'HeadRoot'
	s.HeadRoot = append(s.HeadRoot, buf[44:76]...)

	// Field (4) 'HeadSlot'
	s.HeadSlot = ssz.UnmarshallUint64(buf[76:84])

	return err
}

// SizeSSZ returns the ssz encoded size in bytes for the Status object
func (s *Status) SizeSSZ() (size int) {
	size = 84
	return
}

// MarshalSSZ ssz marshals the BeaconBlocksByRangeRequest object
func (b *BeaconBlocksByRangeRequest) MarshalSSZ() ([]byte, error) {
	buf := make([]byte, b.SizeSSZ())
	return b.MarshalSSZTo(buf[:0])
}

// MarshalSSZTo ssz marshals the BeaconBlocksByRangeRequest object to a target array
func (b *BeaconBlocksByRangeRequest) MarshalSSZTo(dst []byte) ([]byte, error) {
	var err error

	// Field (0) 'StartSlot'
	dst = ssz.MarshalUint64(dst, b.StartSlot)

	// Field (1) 'Count'
	dst = ssz.MarshalUint64(dst, b.Count)

	// Field (2) 'Step'
	dst = ssz.MarshalUint64(dst, b.Step)

	return dst, err
}

// UnmarshalSSZ ssz unmarshals the BeaconBlocksByRangeRequest object
func (b *BeaconBlocksByRangeRequest) UnmarshalSSZ(buf []byte) error {
	var err error
	size := uint64(len(buf))
	if size != 24 {
		return errSize
	}

	// Field (0) 'StartSlot'
	b.StartSlot = ssz.UnmarshallUint64(buf[0:8])

	// Field (1) 'Count'
	b.Count = ssz.UnmarshallUint64(buf[8:16])

	// Field (2) 'Step'
	b.Step = ssz.UnmarshallUint64(buf[16:24])

	return err
}

// SizeSSZ returns the ssz encoded size in bytes for the BeaconBlocksByRangeRequest object
func (b *BeaconBlocksByRangeRequest) SizeSSZ() (size int) {
	size = 24
	return
}

// MarshalSSZ ssz marshals the BeaconBlocksByRootRequest object
func (b *BeaconBlocksByRootRequest) MarshalSSZ() ([]byte, error) {
	buf := make([]byte, b.SizeSSZ())
	return b.MarshalSSZTo(buf[:0])
}

// MarshalSSZTo ssz marshals the BeaconBlocksByRootRequest object to a target array
func (b *BeaconBlocksByRootRequest) MarshalSSZTo(dst []byte) ([]byte, error) {
	var err error
	offset := int(4)

	// Offset (0) 'BlockRoots'
	dst = ssz.WriteOffset(dst, offset)
	offset += len(b.BlockRoots) * 32

	// Field (0) 'BlockRoots'
	if len(b.BlockRoots) > 1024 {
		return nil, errMarshalList
	}
	for ii := 0; ii < len(b.BlockRoots); ii++ {
		if dst, err = ssz.MarshalFixedBytes(dst, b.BlockRoots[ii], 32); err != nil {
			return nil, errMarshalFixedBytes
		}
	}

	return dst, err
}

// UnmarshalSSZ ssz unmarshals the BeaconBlocksByRootRequest object
func (b *BeaconBlocksByRootRequest) UnmarshalSSZ(buf []byte) error {
	var err error
	size := uint64(len(buf))
	if size < 4 {
		return errSize
	}

	tail := buf
	var o0 uint64

	// Offset (0) 'BlockRoots'
	if o0 = ssz.ReadOffset(buf[0:4]); o0 > size {
		return errOffset
	}

	// Field (0) 'BlockRoots'
	{
		buf = tail[o0:]
		num, ok := ssz.DivideInt(len(buf), 32)
		if !ok {
			return errDivideInt
		}
		if num > 1024 {
			return errListTooBig
		}
		b.BlockRoots = make([][]byte, num)
		for ii := 0; ii < num; ii++ {
			b.BlockRoots[ii] = append(b.BlockRoots[ii], buf[ii*32:(ii+1)*32]...)
		}
	}
	return err
}

// SizeSSZ returns the ssz encoded size in bytes for the BeaconBlocksByRootRequest object
func (b *BeaconBlocksByRootRequest) SizeSSZ() (size int) {
	size = 4

	// Field (0) 'BlockRoots'
	size += len(b.BlockRoots) * 32

	return
}

// MarshalSSZ ssz marshals the ErrorResponse object
func (e *ErrorResponse) MarshalSSZ() ([]byte, error) {
	buf := make([]byte, e.SizeSSZ())
	return e.MarshalSSZTo(buf[:0])
}

// MarshalSSZTo ssz marshals the ErrorResponse object to a target array
func (e *ErrorResponse) MarshalSSZTo(dst []byte) ([]byte, error) {
	var err error
	offset := int(4)

	// Offset (0) 'Message'
	dst = ssz.WriteOffset(dst, offset)
	offset += len(e.Message)

	// Field (0) 'Message'
	if len(e.Message) > 256 {
		return nil, errMarshalDynamicBytes
	}
	dst = append(dst, e.Message...)

	return dst, err
}

// UnmarshalSSZ ssz unmarshals the ErrorResponse object
func (e *ErrorResponse) UnmarshalSSZ(buf []byte) error {
	var err error
	size := uint64(len(buf))
	if size < 4 {
		return errSize
	}

	tail := buf
	var o0 uint64

	// Offset (0) 'Message'
	if o0 = ssz.ReadOffset(buf[0:4]); o0 > size {
		return errOffset
	}

	// Field (0) 'Message'
	{
		buf = tail[o0:]
		e.Message = append(e.Message, buf...)
	}
	return err
}

// SizeSSZ returns the ssz encoded size in bytes for the ErrorResponse object
func (e *ErrorResponse) SizeSSZ() (size int) {
	size = 4

	// Field (0) 'Message'
	size += len(e.Message)

	return
}

// MarshalSSZ ssz marshals the ENRForkID object
func (e *ENRForkID) MarshalSSZ() ([]byte, error) {
	buf := make([]byte, e.SizeSSZ())
	return e.MarshalSSZTo(buf[:0])
}

// MarshalSSZTo ssz marshals the ENRForkID object to a target array
func (e *ENRForkID) MarshalSSZTo(dst []byte) ([]byte, error) {
	var err error

	// Field (0) 'CurrentForkDigest'
	if dst, err = ssz.MarshalFixedBytes(dst, e.CurrentForkDigest, 4); err != nil {
		return nil, errMarshalFixedBytes
	}

	// Field (1) 'NextForkVersion'
	if dst, err = ssz.MarshalFixedBytes(dst, e.NextForkVersion, 4); err != nil {
		return nil, errMarshalFixedBytes
	}

	// Field (2) 'NextForkEpoch'
	dst = ssz.MarshalUint64(dst, e.NextForkEpoch)

	return dst, err
}

// UnmarshalSSZ ssz unmarshals the ENRForkID object
func (e *ENRForkID) UnmarshalSSZ(buf []byte) error {
	var err error
	size := uint64(len(buf))
	if size != 16 {
		return errSize
	}

	// Field (0) 'CurrentForkDigest'
	e.CurrentForkDigest = append(e.CurrentForkDigest, buf[0:4]...)

	// Field (1) 'NextForkVersion'
	e.NextForkVersion = append(e.NextForkVersion, buf[4:8]...)

	// Field (2) 'NextForkEpoch'
	e.NextForkEpoch = ssz.UnmarshallUint64(buf[8:16])

	return err
}

// SizeSSZ returns the ssz encoded size in bytes for the ENRForkID object
func (e *ENRForkID) SizeSSZ() (size int) {
	size = 16
	return
}

// MarshalSSZ ssz marshals the MetaData object
func (m *MetaData) MarshalSSZ() ([]byte, error) {
	buf := make([]byte, m.SizeSSZ())
	return m.MarshalSSZTo(buf[:0])
}

// MarshalSSZTo ssz marshals the MetaData object to a target array
func (m *MetaData) MarshalSSZTo(dst []byte) ([]byte, error) {
	var err error

	// Field (0) 'SeqNumber'
	dst = ssz.MarshalUint64(dst, m.SeqNumber)

	// Field (1) 'Attnets'
	if dst, err = ssz.MarshalFixedBytes(dst, m.Attnets, 8); err != nil {
		return nil, errMarshalFixedBytes
	}

	return dst, err
}

// UnmarshalSSZ ssz unmarshals the MetaData object
func (m *MetaData) UnmarshalSSZ(buf []byte) error {
	var err error
	size := uint64(len(buf))
	if size != 16 {
		return errSize
	}

	// Field (0) 'SeqNumber'
	m.SeqNumber = ssz.UnmarshallUint64(buf[0:8])

	// Field (1) 'Attnets'
	m.Attnets = append(m.Attnets, buf[8:16]...)

	return err
}

// SizeSSZ returns the ssz encoded size in bytes for the MetaData object
func (m *MetaData) SizeSSZ() (size int) {
	size = 16
	return
}
