Changes in this PR are not backward compatible! Few things have changed. Hopefully, migration will not be painful for you. If you have any questions, please, let us know here or in our community Slack channel.
You can install and test it using v0.10.0-beta: go get github.com/moov-io/iso8583@v0.10.0-beta
Changes:
added message.Marshal(data) which sets values of message fields using values provided in the data struct.
added support of index tag for both message.Marshal() and message.Unmarshal(). Now you can name your fields as you want and use index tag to specify the field index matching the ISO8583 specification. Examples are here and here.
removed iso8583.Unmarshal. Please, use message.Unmarshal instead.
removed message.Data()
deprecated message.SetData(data). Use message.Marshal() instead.
deprecated field.SetData(data). Use field.Marshal(data) instead.
changed current behavior of message.SetData(data). Before it could be used to get values into a struct after calling message.Unpack() like this:
data := &ISOMessage{}
mesage.SetData(data)
message.Unpack(rawMessage)
data.F1.Value // in previous versions, values were populated during unpacking, but now they are not
Now `message.SetData(data)` only sets field values and you can't get values back to the struct using it. In order to get values into the struct you have to use `message.Unmarshal(data)` like this:
```go
message.Unpack(rawMessage)
data := &ISOMessage{}
mesage.Unmarshall(data)
data.F1.Value // now you can get the value
Migration Guide
Two main changes that you may need to do in your code:
Replace message.SetData(data) with message.Marshal(data). Latter simply sets field values with values provided in the data struct. Without any side effects.
Replace message.Data()(*YouMessageTypehere) with message.Unmarshal(data). It sets data struct values with message field values. No side-effects.
If you used SetData() with Unpack to get access to message field values, then you have to replace it with just message.Unmarshal(data).
You have to change your code from this
type ISO87Data struct {
F0 *field.String
F2 *field.String
F4 *field.String
}
message := NewMessage(spec)
data := &ISO87Data{}
err := message.SetData(data) // you "link" data internally
err = message.Unpack(rawMsg) // here values are populated into linked data struct. it will not work anymore.
// access field values
data.F0.Value
data.F2.Value
data.F4.Value
to this:
type ISO87Data struct {
F0 *field.String
F2 *field.String
F4 *field.String
}
message := NewMessage(spec)
err := message.Unpack(rawMsg)
data := &ISO87Data{}
err = message.Unmarshal(data)
// access field values
data.F0.Value
data.F2.Value
data.F4.Value
Changes in this PR are not backward compatible! Few things have changed. Hopefully, migration will not be painful for you. If you have any questions, please, let us know here or in our community Slack channel.
You can install and test it using
v0.10.0-beta
:go get github.com/moov-io/iso8583@v0.10.0-beta
Changes:
message.Marshal(data)
which sets values of message fields using values provided in thedata
struct.index
tag for bothmessage.Marshal()
andmessage.Unmarshal()
. Now you can name your fields as you want and useindex
tag to specify the field index matching the ISO8583 specification. Examples are here and here.iso8583.Unmarshal
. Please, usemessage.Unmarshal
instead.message.SetData(data)
. Usemessage.Marshal()
instead.field.SetData(data)
. Usefield.Marshal(data)
instead.message.SetData(data)
. Before it could be used to get values into a struct after callingmessage.Unpack()
like this:data.F1.Value // in previous versions, values were populated during unpacking, but now they are not
Migration Guide
Two main changes that you may need to do in your code:
message.SetData(data)
withmessage.Marshal(data)
. Latter simply sets field values with values provided in thedata
struct. Without any side effects.message.Data()(*YouMessageTypehere)
withmessage.Unmarshal(data)
. It setsdata
struct values with message field values. No side-effects.SetData()
withUnpack
to get access to message field values, then you have to replace it with justmessage.Unmarshal(data)
.You have to change your code from this
to this: