-
Notifications
You must be signed in to change notification settings - Fork 115
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
Proposal: use Go's native types for getting/setting ISO 8583 message data #277
Comments
I enjoy the simplicity Are their any particular types such as |
We might be able to detect of the field was set with Go ast/parser tools, but that's likely too complex. Is this going to be a change limited to the code reading |
The underlying value for both type AuthorizationRequest struct {
// ...
SomeEncryptedData []byte `index:"99"`
} We can do some convenient things to work with hex like this: // in the spec, field 99 is `field.Binary`
type AuthorizationRequest struct {
// ...
SomeEncryptedData string `index:"99"`
}
err := message.Marshal(&AuthorizationRequest{
// this is a hex and it will be decoded into []byte when value is assigned to the message field
SomeEncryptedData: "16ddf39d3d8a4a99"
}) |
The change will impact Marshal/Unmarshal methods of the This is how the change inside simple field will look like: https://github.com/moov-io/iso8583/pull/273/files#diff-79ac174d65bca7ada39659ad4ae9fb2ae82b4532ca22f9392010bad81638708cR129 This is the change in the |
The Marshal/Unmarshal changes make sense to me. It's a nice cleanup. We're just going to assume string -> []byte is hex, binary string, or raw bytes? (In that order) |
I think we can limit string to only hex. The rest will return an error. If we support other not trivial conversions, that may lead to confusion. I'm not sure 100% about this, though. |
It doesn't seem we are adding complex validation or anything fancy in the type conversations. It makes the code more readable. Approved |
Great! Thanks for the review @adamdecaf @wadearnold! |
Background:
Introduce a new way to handle ISO 8583 message data using Go's native types, while retaining the current mechanism for compatibility and flexibility.
Proposed Changes:
Currently, we use
field.String
,field.Numerci
, and other field types to work with ISO 8583 message data:Allow to use use Go's native types like this:
The message field such as
String
will be capable to handlestring
,int
types. The same is forNumeric
. If thestring
type is used for the value, theMarshal
method will try to convert it intoint
.Motivation:
Concerns
In the current approach, when a struct field is set with a pointer to an instance of
field.String
orNumeric
,Binary
, etc., the marshaller understands that a value has been assigned to the message field, even if the actual value inside thefield.String
is0
or an empty string""
. This provides clarity that the field has been intentionally populated, even if with a zero value:However, when directly using the
string
type, if we don't provide a value (resulting in the default zero value of""
), our intention becomes ambiguous:The ambiguity here can lead to unintended outcomes, making it crucial to define how the marshaller should interpret such scenarios.
To address this ambiguity, I propose skipping all zero values by default. Practically speaking, it's infrequent to utilize zero values for message fields, barring some exceptions such as transaction amounts, which can be
0
.For developers who wish to prevent fields with zero values from being skipped, we suggest several alternatives:
string
type with a value of "0", ensuring the field remains present.The text was updated successfully, but these errors were encountered: