Skip to content

Commit

Permalink
track 2 spec added (#314)
Browse files Browse the repository at this point in the history
Co-authored-by: wisely11 <wisely.samuel@gmail.com>
  • Loading branch information
wisely11 and wisely11 authored Jul 12, 2024
1 parent 8523963 commit edc9020
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/fields/track2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "ISO 8583 v1987 Track2",
"fields": {
"35": {
"type": "Track2",
"length": 37,
"description": "TRACK 2 DATA",
"prefix": "Binary.L",
"enc": "ASCIIToHex"
}
}
}
1 change: 1 addition & 0 deletions specs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down
9 changes: 9 additions & 0 deletions specs/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions specs/track2.go
Original file line number Diff line number Diff line change
@@ -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,
}),
},
}

0 comments on commit edc9020

Please sign in to comment.