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

Changed field types to native types[Issue #341] #342

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,20 +246,20 @@ First, you need to define a struct with fields you want to set. Fields should co
// list fields you want to set, add `index` tag with field index or tag (for
// composite subfields) use the same types from message specification
type NetworkManagementRequest struct {
MTI *field.String `index:"0"`
TransmissionDateTime *field.String `index:"7"`
STAN *field.String `index:"11"`
InformationCode *field.String `index:"70"`
MTI string `index:"0"`
TransmissionDateTime string `index:"7"`
STAN string `index:"11"`
InformationCode string `index:"70"`
}

message := NewMessage(spec)

// now, pass data with fields into the message
err := message.Marshal(&NetworkManagementRequest{
MTI: field.NewStringValue("0800"),
TransmissionDateTime: field.NewStringValue(time.Now().UTC().Format("060102150405")),
STAN: field.NewStringValue("000001"),
InformationCode: field.NewStringValue("001"),
MTI: "0800",
TransmissionDateTime: time.Now().UTC().Format("060102150405"),
STAN: "000001",
InformationCode: "001",
})

// pack the message and send it to your provider
Expand Down Expand Up @@ -301,10 +301,10 @@ To get values of multiple fields with their types just pass a pointer to a struc
// list fields you want to set, add `index` tag with field index or tag (for
// composite subfields) use the same types from message specification
type NetworkManagementRequest struct {
MTI *field.String `index:"0"`
TransmissionDateTime *field.String `index:"7"`
STAN *field.String `index:"11"`
InformationCode *field.String `index:"70"`
MTI string `index:"0"`
TransmissionDateTime string `index:"7"`
STAN string `index:"11"`
InformationCode string `index:"70"`
}

message := NewMessage(spec)
Expand All @@ -320,10 +320,10 @@ err = message.Unmarshal(data)
// handle error

// now you can access field values
data.MTI.Value() // "0100"
data.TransmissionDateTime.Value() // "220102103212"
data.STAN.Value() // "000001"
data.InformationCode.Value() // "001"
data.MTI // "0100"
data.TransmissionDateTime // "220102103212"
data.STAN // "000001"
data.InformationCode // "001"
```

For complete code samples please check [./message_test.go](./message_test.go).
Expand Down