moov-io / iso8583

A golang implementation to marshal and unmarshal iso8583 message.
https://moov.io
Apache License 2.0
349 stars 104 forks source link

Dump ISO8583 data to string output for debugging. #72

Closed wadearnold closed 3 years ago

wadearnold commented 3 years ago

Create a function that dumps the iso8583 message into labels for debugging and logging.

<Property Name> <Field Length> <tab> :<Field Value>

isomessage = iso8583.NewMessage(iso8583.Spec87)
err = isomessage.Unpack(Unpack([]byte("0800A23800000080000004000000000000000000000706082419005835082419070620390059000"))
if err != nil {
    t.Errorf("failed to pack unpacked message: %v", err)
}
isomessage.stringDump()
asciiMessage                  :0800A23800000080000004000000000000000000000706082419005835082419070620390059000
Header                  :
MessageType                   :0800
Bitmap                        :A2380000008000000400000000000000 bits:10100010001110000000000000000000000000001000000000000000000000000000010000000000000000000000000000000000000000000000000000000000
F03_ProcessingCode            :000000
F07_TransmissionDateTime      :0706082419
F11_SystemTraceAuditNumber    :005835
F12_DateTimeLocalTransaction  :082419
F13_DateLocalTxn              :0706
F41_CardAcceptorTerminalIdenti:20390059
F70_AuthInstCntryCode         :000

I would like to name this "stringDump" or some variation so that we could add hexDump() and others in the future.

This function plus a simple string input CLI would be a nice tool utility tool. This would be like the achcli for describing a file. This should be a separate issue. https://github.com/moov-io/ach#command-line

Juniornewxt commented 3 years ago

If that works, you guys are the best. :)

alovak commented 3 years ago

@Juniornewxt you can try it from this PR: https://github.com/moov-io/iso8583/pull/80

Juniornewxt commented 3 years ago

Do you have any examples? I tried it, to no avail :(

Juniornewxt commented 3 years ago

package main

import ( "fmt" "github.com/moov-io/iso8583" "github.com/moov-io/iso8583/encoding" "github.com/moov-io/iso8583/field" "github.com/moov-io/iso8583/padding" "github.com/moov-io/iso8583/prefix"

)

func NewSpec() *iso8583.MessageSpec { return &iso8583.MessageSpec{ Fields: map[int]field.Field{ 0: field.NewString(&field.Spec{ Length: 8, Description: "Message Type Indicator", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, }), 1: field.NewBitmap(&field.Spec{ Description: "Bitmap", Enc: encoding.Hex, Pref: prefix.Hex.Fixed, }), 3: field.NewNumeric(&field.Spec{ Length: 6, Description: "Processing Code", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, Pad: padding.Left('0'), }), 4: field.NewNumeric(&field.Spec{ Length: 12, Description: "Transaction Amount", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, Pad: padding.Left('0'), }), 7: field.NewNumeric(&field.Spec{ Length: 10, Description: "Transaction Amount", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, Pad: padding.Left('0'), }), 11: field.NewNumeric(&field.Spec{ Length: 6, Description: "Transaction Amount", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, Pad: padding.Left('0'), }), 12: field.NewNumeric(&field.Spec{ Length: 6, Description: "Transaction Amount", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, Pad: padding.Left('0'), }), 13: field.NewNumeric(&field.Spec{ Length: 4, Description: "Transaction Amount", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, Pad: padding.Left('0'), }), 32: field.NewString(&field.Spec{ Length: 11, Description: "Field 32", Enc: encoding.ASCII, Pref: prefix.ASCII.LL, }), 37: field.NewNumeric(&field.Spec{ Length: 12, Description: "NSU", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, Pad: padding.Left('0'), }), 39: field.NewString(&field.Spec{ Length: 2, Description: "Field 39", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, Pad: padding.Left('0'), }), 41: field.NewString(&field.Spec{ Length: 8, Description: "Field 42", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, }),
42: field.NewString(&field.Spec{ Length: 15, Description: "Field 42", Enc: encoding.ASCII, Pref: prefix.ASCII.Fixed, }), 61: field.NewString(&field.Spec{ Length: 999, Description: " ADC", Enc: encoding.ASCII, Pref: prefix.ASCII.LLL, }), }, }

}

func main() { test() }

func test() { want := "01150210323800010AC000080030000000000006630706101623000001101623070604008910162341603896JUNI0SIM00000000000999900504.10"

message := iso8583.NewMessage(iso8583.Spec87)

message.Unpack([]byte(want))

c, err := message.Pack()
if err != nil {
    panic(err)

}

fmt.Printf("% x\n", c)

}

alovak commented 3 years ago

CLI with describe method is released in v0.4.1.

Not included in the release:

wadearnold commented 3 years ago

@alovak can you add issues for those items that were not included for enhancements.