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

import (
	ssz "github.com/prysmaticlabs/fastssz"
)

// MarshalSSZ ssz marshals the FixedNestedContainer object
func (f *FixedNestedContainer) MarshalSSZ() ([]byte, error) {
	return ssz.MarshalSSZ(f)
}

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

	// Field (0) 'Value1'
	dst = ssz.MarshalUint64(dst, f.Value1)

	// Field (1) 'Value2'
	if size := len(f.Value2); size != 32 {
		err = ssz.ErrBytesLengthFn("--.Value2", size, 32)
		return
	}
	dst = append(dst, f.Value2...)

	return
}

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

	// Field (0) 'Value1'
	f.Value1 = ssz.UnmarshallUint64(buf[0:8])

	// Field (1) 'Value2'
	if cap(f.Value2) == 0 {
		f.Value2 = make([]byte, 0, len(buf[8:40]))
	}
	f.Value2 = append(f.Value2, buf[8:40]...)

	return err
}

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

// HashTreeRoot ssz hashes the FixedNestedContainer object
func (f *FixedNestedContainer) HashTreeRoot() ([32]byte, error) {
	return ssz.HashWithDefaultHasher(f)
}

// HashTreeRootWith ssz hashes the FixedNestedContainer object with a hasher
func (f *FixedNestedContainer) HashTreeRootWith(hh *ssz.Hasher) (err error) {
	indx := hh.Index()

	// Field (0) 'Value1'
	hh.PutUint64(f.Value1)

	// Field (1) 'Value2'
	if size := len(f.Value2); size != 32 {
		err = ssz.ErrBytesLengthFn("--.Value2", size, 32)
		return
	}
	hh.PutBytes(f.Value2)

	hh.Merkleize(indx)
	return
}

// MarshalSSZ ssz marshals the FixedTestContainer object
func (f *FixedTestContainer) MarshalSSZ() ([]byte, error) {
	return ssz.MarshalSSZ(f)
}

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

	// Field (0) 'FieldUint32'
	dst = ssz.MarshalUint32(dst, f.FieldUint32)

	// Field (1) 'FieldUint64'
	dst = ssz.MarshalUint64(dst, f.FieldUint64)

	// Field (2) 'FieldBool'
	dst = ssz.MarshalBool(dst, f.FieldBool)

	// Field (3) 'FieldBytes32'
	if size := len(f.FieldBytes32); size != 32 {
		err = ssz.ErrBytesLengthFn("--.FieldBytes32", size, 32)
		return
	}
	dst = append(dst, f.FieldBytes32...)

	// Field (4) 'Nested'
	if f.Nested == nil {
		f.Nested = new(FixedNestedContainer)
	}
	if dst, err = f.Nested.MarshalSSZTo(dst); err != nil {
		return
	}

	// Field (5) 'VectorField'
	if size := len(f.VectorField); size != 24 {
		err = ssz.ErrVectorLengthFn("--.VectorField", size, 24)
		return
	}
	for ii := 0; ii < 24; ii++ {
		dst = ssz.MarshalUint64(dst, f.VectorField[ii])
	}

	// Field (6) 'TrailingField'
	if size := len(f.TrailingField); size != 56 {
		err = ssz.ErrBytesLengthFn("--.TrailingField", size, 56)
		return
	}
	dst = append(dst, f.TrailingField...)

	return
}

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

	// Field (0) 'FieldUint32'
	f.FieldUint32 = ssz.UnmarshallUint32(buf[0:4])

	// Field (1) 'FieldUint64'
	f.FieldUint64 = ssz.UnmarshallUint64(buf[4:12])

	// Field (2) 'FieldBool'
	f.FieldBool, err = ssz.DecodeBool(buf[12:13])
	if err != nil {
		return err
	}

	// Field (3) 'FieldBytes32'
	if cap(f.FieldBytes32) == 0 {
		f.FieldBytes32 = make([]byte, 0, len(buf[13:45]))
	}
	f.FieldBytes32 = append(f.FieldBytes32, buf[13:45]...)

	// Field (4) 'Nested'
	if f.Nested == nil {
		f.Nested = new(FixedNestedContainer)
	}
	if err = f.Nested.UnmarshalSSZ(buf[45:85]); err != nil {
		return err
	}

	// Field (5) 'VectorField'
	f.VectorField = ssz.ExtendUint64(f.VectorField, 24)
	for ii := 0; ii < 24; ii++ {
		f.VectorField[ii] = ssz.UnmarshallUint64(buf[85:277][ii*8 : (ii+1)*8])
	}

	// Field (6) 'TrailingField'
	if cap(f.TrailingField) == 0 {
		f.TrailingField = make([]byte, 0, len(buf[277:333]))
	}
	f.TrailingField = append(f.TrailingField, buf[277:333]...)

	return err
}

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

// HashTreeRoot ssz hashes the FixedTestContainer object
func (f *FixedTestContainer) HashTreeRoot() ([32]byte, error) {
	return ssz.HashWithDefaultHasher(f)
}

// HashTreeRootWith ssz hashes the FixedTestContainer object with a hasher
func (f *FixedTestContainer) HashTreeRootWith(hh *ssz.Hasher) (err error) {
	indx := hh.Index()

	// Field (0) 'FieldUint32'
	hh.PutUint32(f.FieldUint32)

	// Field (1) 'FieldUint64'
	hh.PutUint64(f.FieldUint64)

	// Field (2) 'FieldBool'
	hh.PutBool(f.FieldBool)

	// Field (3) 'FieldBytes32'
	if size := len(f.FieldBytes32); size != 32 {
		err = ssz.ErrBytesLengthFn("--.FieldBytes32", size, 32)
		return
	}
	hh.PutBytes(f.FieldBytes32)

	// Field (4) 'Nested'
	if err = f.Nested.HashTreeRootWith(hh); err != nil {
		return
	}

	// Field (5) 'VectorField'
	{
		if size := len(f.VectorField); size != 24 {
			err = ssz.ErrVectorLengthFn("--.VectorField", size, 24)
			return
		}
		subIndx := hh.Index()
		for _, i := range f.VectorField {
			hh.AppendUint64(i)
		}
		hh.Merkleize(subIndx)
	}

	// Field (6) 'TrailingField'
	if size := len(f.TrailingField); size != 56 {
		err = ssz.ErrBytesLengthFn("--.TrailingField", size, 56)
		return
	}
	hh.PutBytes(f.TrailingField)

	hh.Merkleize(indx)
	return
}
