diff --git a/examples/fields/track2.json b/examples/fields/track2.json new file mode 100644 index 00000000..1a42af08 --- /dev/null +++ b/examples/fields/track2.json @@ -0,0 +1,12 @@ +{ + "name": "ISO 8583 v1987 Track2", + "fields": { + "35": { + "type": "Track2", + "length": 37, + "description": "TRACK 2 DATA", + "prefix": "Binary.L", + "enc": "ASCIIToHex" + } + } +} \ No newline at end of file diff --git a/specs/builder.go b/specs/builder.go index 259df806..1840000f 100644 --- a/specs/builder.go +++ b/specs/builder.go @@ -24,6 +24,7 @@ type FieldConstructorFunc func(spec *field.Spec) field.Field var ( FieldConstructor = map[string]FieldConstructorFunc{ "String": func(spec *field.Spec) field.Field { return field.NewString(spec) }, + "Track2": func(spec *field.Spec) field.Field { return field.NewTrack2(spec) }, "Numeric": func(spec *field.Spec) field.Field { return field.NewNumeric(spec) }, "Binary": func(spec *field.Spec) field.Field { return field.NewBinary(spec) }, "Bitmap": func(spec *field.Spec) field.Field { return field.NewBitmap(spec) }, diff --git a/specs/builder_test.go b/specs/builder_test.go index 87a689f9..c2d0fb11 100644 --- a/specs/builder_test.go +++ b/specs/builder_test.go @@ -32,6 +32,15 @@ func TestBuilder(t *testing.T) { require.Exactly(t, Spec87Hex.Name, hexSpec.Name) } +func TestImportingJSONWithTrack2Spec(t *testing.T) { + track2Json, err := os.ReadFile("../examples/fields/track2.json") + require.NoError(t, err) + + track2Spec, err := Builder.ImportJSON(track2Json) + require.NoError(t, err) + require.Exactly(t, Spec87Track2, track2Spec) +} + func TestExampleJSONSpec(t *testing.T) { asciiJson, err := os.ReadFile("../examples/specs/spec87ascii.json") require.NoError(t, err) diff --git a/specs/track2.go b/specs/track2.go new file mode 100644 index 00000000..383cbc16 --- /dev/null +++ b/specs/track2.go @@ -0,0 +1,21 @@ +package specs + +import ( + "github.com/moov-io/iso8583" + "github.com/moov-io/iso8583/encoding" + "github.com/moov-io/iso8583/field" + "github.com/moov-io/iso8583/prefix" +) + +// we keep it for compatibility reasons +var Spec87Track2 *iso8583.MessageSpec = &iso8583.MessageSpec{ + Name: "ISO 8583 v1987 Track2", + Fields: map[int]field.Field{ + 35: field.NewTrack2(&field.Spec{ + Length: 37, + Description: "TRACK 2 DATA", + Enc: encoding.ASCIIHexToBytes, + Pref: prefix.Binary.L, + }), + }, +}