Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

track 2 spec added #314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}),
},
}
Loading