func (f *Composite) Unpack(data []byte) (int, error) {
	dataLen, offset, err := f.spec.Pref.DecodeLength(f.spec.Length, data)
	if err != nil {
		return 0, fmt.Errorf("failed to decode length: %w", err)
	}
	read, err := f.unpack(data[offset : offset+dataLen])
	if err != nil {
		return 0, err
	}
	if dataLen != read {
		return 0, fmt.Errorf("data length: %v does not match aggregate data read from decoded subfields: %v", dataLen, read)
	}
	return offset + read, nil
}
Unpack takes in a byte array and serializes them into the receiver's
subfields. An offset (unit depends on encoding and prefix values) is
returned on success. A non-nil error is returned on failure.
package field
import (
	"encoding/json"
	"fmt"
	"reflect"
	"github.com/moov-io/iso8583/padding"
	"github.com/moov-io/iso8583/sort"
)
var _ Field = (*Composite)(nil)
var _ json.Marshaler = (*Composite)(nil)
var _ json.Unmarshaler = (*Composite)(nil)
type Composite struct {
	spec *Spec
	orderedSpecFieldTags []string
	tagToSubfieldMap     map[string]Field
	data *reflect.Value
}
func NewComposite(spec *Spec) *Composite {
	f := &Composite{}
	f.SetSpec(spec)
	return f
}
func (f *Composite) Spec() *Spec {
	return f.spec
}
func (f *Composite) SetSpec(spec *Spec) {
	if err := validateCompositeSpec(spec); err != nil {
		panic(err)
	}
	f.spec = spec
	f.tagToSubfieldMap = map[string]Field{}
	f.orderedSpecFieldTags = orderedKeys(spec.Subfields, spec.Tag.Sort)
}
func (f *Composite) SetData(data interface{}) error {
	dataStruct := reflect.ValueOf(data)
	if dataStruct.Kind() == reflect.Ptr || dataStruct.Kind() == reflect.Interface {
		dataStruct = dataStruct.Elem()
	}
	if dataStruct.Kind() != reflect.Struct {
		return fmt.Errorf("failed to set data as struct is expected, got: %s", dataStruct.Kind())
	}
	f.data = &dataStruct
	return nil
}
func (f *Composite) Pack() ([]byte, error) {
	packed, err := f.pack()
	if err != nil {
		return nil, err
	}
	packedLength, err := f.spec.Pref.EncodeLength(f.spec.Length, len(packed))
	if err != nil {
		return nil, fmt.Errorf("failed to encode length: %w", err)
	}
	return append(packedLength, packed...), nil
}