@@ -17,10 +17,23 @@ import (
1717 "github.com/moov-io/iso8583/utils"
1818)
1919
20+ // CompositeWithSubfields provides methods to manipulate subfields
21+ // and used when composite field is created without
22+ // calling NewComposite e.g. in iso8583.NewMessage(...)
23+ type CompositeWithSubfields interface {
24+ ConstructSubfields ()
25+ GetSubfields () map [string ]Field
26+ SetSubfields (idPath string , value string ) error
27+ SetSubfield (id string , value string ) error
28+ UnsetSubfields (idPaths ... string ) error
29+ UnsetSubfield (id string )
30+ }
31+
2032var (
21- _ Field = (* Composite )(nil )
22- _ json.Marshaler = (* Composite )(nil )
23- _ json.Unmarshaler = (* Composite )(nil )
33+ _ Field = (* Composite )(nil )
34+ _ json.Marshaler = (* Composite )(nil )
35+ _ json.Unmarshaler = (* Composite )(nil )
36+ _ CompositeWithSubfields = (* Composite )(nil )
2437)
2538
2639// Composite is a wrapper object designed to hold ISO8583 TLVs, subfields and
@@ -93,12 +106,6 @@ func NewComposite(spec *Spec) *Composite {
93106 return f
94107}
95108
96- // CompositeWithSubfields is used when composite field is created without
97- // calling NewComposite e.g. in iso8583.NewMessage(...)
98- type CompositeWithSubfields interface {
99- ConstructSubfields ()
100- }
101-
102109// ConstructSubfields creates subfields according to the spec
103110// this method is used when composite field is created without
104111// calling NewComposite (when we create message spec and composite spec)
@@ -732,7 +739,7 @@ func (m *Composite) UnsetSubfields(idPaths ...string) error {
732739 return fmt .Errorf ("subfield %s does not exist" , id )
733740 }
734741
735- composite , ok := f .(* Composite )
742+ composite , ok := f .(CompositeWithSubfields )
736743 if ! ok {
737744 return fmt .Errorf ("field %s is not a composite field and its subfields %s cannot be unset" , id , path )
738745 }
@@ -767,7 +774,7 @@ func (m *Composite) SetSubfields(idPath string, value string) error {
767774 }
768775
769776 // If there's a further path, the subfield must be a composite
770- composite , ok := subfield .(* Composite )
777+ composite , ok := subfield .(CompositeWithSubfields )
771778 if ! ok {
772779 return fmt .Errorf ("subfield %s is not a composite field and cannot have nested subfields" , id )
773780 }
0 commit comments