-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathoutputMessageAccountabilityData.go
212 lines (178 loc) · 6.91 KB
/
outputMessageAccountabilityData.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package wire
import (
"encoding/json"
"strings"
"unicode/utf8"
)
// OutputMessageAccountabilityData is the Output Message Accountability Data (OMAD) of the wire
type OutputMessageAccountabilityData struct {
// tag
tag string
// OutputCycleDate (CCYYMMDD)
OutputCycleDate string `json:"outputCycleDate,omitempty"`
// OutputDestinationID
OutputDestinationID string `json:"outputDestinationID,omitempty"`
// OutputOutputSequenceNumber
OutputSequenceNumber string `json:"outputSequenceNumber,omitempty"`
// OutputDate is the output date
OutputDate string `json:"outputDate,omitempty"`
// OutputTime is OutputTime
OutputTime string `json:"outputTime,omitempty"`
// OutputFRBApplicationIdentification
OutputFRBApplicationIdentification string `json:"outputFRBApplicationIdentification,omitempty"`
// validator is composed for data validation
// validator
// converters is composed for WIRE to GoLang Converters
converters
}
// NewOutputMessageAccountabilityData returns a new OutputMessageAccountabilityData
func NewOutputMessageAccountabilityData() *OutputMessageAccountabilityData {
omad := &OutputMessageAccountabilityData{
tag: TagOutputMessageAccountabilityData,
}
return omad
}
// Parse takes the input string and parses the OutputMessageAccountabilityData values
//
// Parse provides no guarantee about all fields being filled in. Callers should make a Validate() call to confirm
// successful parsing and data validity.
func (omad *OutputMessageAccountabilityData) Parse(record string) error {
if utf8.RuneCountInString(record) < 14 {
return NewTagMinLengthErr(14, len(record))
}
omad.tag = record[:6]
length := 6
value, read, err := omad.parseFixedStringField(record[length:], 8)
if err != nil {
return fieldError("OutputCycleDate", err)
}
omad.OutputCycleDate = value
length += read
value, read, err = omad.parseFixedStringField(record[length:], 8)
if err != nil {
return fieldError("OutputDestinationID", err)
}
omad.OutputDestinationID = value
length += read
if len(record) < length+6 {
return fieldError("OutputSequenceNumber", ErrValidLength)
}
omad.OutputSequenceNumber = record[length : length+6]
length += 6
value, read, err = omad.parseFixedStringField(record[length:], 4)
if err != nil {
return fieldError("OutputDate", err)
}
omad.OutputDate = value
length += read
value, read, err = omad.parseFixedStringField(record[length:], 4)
if err != nil {
return fieldError("OutputTime", err)
}
omad.OutputTime = value
length += read
value, read, err = omad.parseFixedStringField(record[length:], 4)
if err != nil {
return fieldError("OutputFRBApplicationIdentification", err)
}
omad.OutputFRBApplicationIdentification = value
length += read
if err := omad.verifyDataWithReadLength(record, length); err != nil {
return NewTagMaxLengthErr(err)
}
return nil
}
func (omad *OutputMessageAccountabilityData) UnmarshalJSON(data []byte) error {
type Alias OutputMessageAccountabilityData
aux := struct {
*Alias
}{
(*Alias)(omad),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
omad.tag = TagOutputMessageAccountabilityData
return nil
}
// String returns a fixed-width OutputMessageAccountabilityData record
func (omad *OutputMessageAccountabilityData) String() string {
return omad.Format(FormatOptions{
VariableLengthFields: false,
})
}
// Format returns a OutputMessageAccountabilityData record formatted according to the FormatOptions
func (omad *OutputMessageAccountabilityData) Format(options FormatOptions) string {
var buf strings.Builder
buf.Grow(40)
// All fields are fixed fields
options.VariableLengthFields = false
buf.WriteString(omad.tag)
buf.WriteString(omad.OutputCycleDateField())
buf.WriteString(omad.OutputDestinationIDField())
buf.WriteString(omad.OutputSequenceNumberField())
buf.WriteString(omad.OutputDateField())
buf.WriteString(omad.OutputTimeField())
buf.WriteString(omad.OutputFRBApplicationIdentificationField())
if options.VariableLengthFields {
return omad.stripDelimiters(buf.String())
} else {
return buf.String()
}
}
// Validate performs WIRE format rule checks on OutputMessageAccountabilityData and returns an error if not Validated
// The first error encountered is returned and stops that parsing.
func (omad *OutputMessageAccountabilityData) Validate() error {
// Currently no validation as the FED is responsible for the values
if omad.tag != TagOutputMessageAccountabilityData {
return fieldError("tag", ErrValidTagForType, omad.tag)
}
return nil
}
// OutputCycleDateField
func (omad *OutputMessageAccountabilityData) OutputCycleDateField() string {
return omad.parseAlphaField(omad.OutputCycleDate, 8)
}
// FormatOutputCycleDate returns OutputCycleDate formatted according to the FormatOptions
func (omad *OutputMessageAccountabilityData) FormatOutputCycleDate(options FormatOptions) string {
return omad.formatAlphaField(omad.OutputCycleDate, 8, options)
}
// OutputDestinationIDField
func (omad *OutputMessageAccountabilityData) OutputDestinationIDField() string {
return omad.parseAlphaField(omad.OutputDestinationID, 8)
}
// FormatOutputDestinationID returns OutputDestinationID formatted according to the FormatOptions
func (omad *OutputMessageAccountabilityData) FormatOutputDestinationID(options FormatOptions) string {
return omad.formatAlphaField(omad.OutputDestinationID, 8, options)
}
// OutputSequenceNumberField gets a string of the OutputSequenceNumber field
func (omad *OutputMessageAccountabilityData) OutputSequenceNumberField() string {
return omad.numericStringField(omad.OutputSequenceNumber, 6)
}
// OutputDateField
func (omad *OutputMessageAccountabilityData) OutputDateField() string {
return omad.parseAlphaField(omad.OutputDate, 4)
}
// FormatOutputDate returns OutputDate formatted according to the FormatOptions
func (omad *OutputMessageAccountabilityData) FormatOutputDate(options FormatOptions) string {
return omad.formatAlphaField(omad.OutputDate, 4, options)
}
// OutputTimeField
func (omad *OutputMessageAccountabilityData) OutputTimeField() string {
return omad.parseAlphaField(omad.OutputTime, 4)
}
// FormatOutputTime returns OutputTime formatted according to the FormatOptions
func (omad *OutputMessageAccountabilityData) FormatOutputTime(options FormatOptions) string {
return omad.formatAlphaField(omad.OutputTime, 4, options)
}
// OutputFRBApplicationIdentificationField
func (omad *OutputMessageAccountabilityData) OutputFRBApplicationIdentificationField() string {
return omad.parseAlphaField(omad.OutputFRBApplicationIdentification, 4)
}
// FormatOutputFRBApplicationIdentification returns OutputFRBApplicationIdentification formatted according to the FormatOptions
func (omad *OutputMessageAccountabilityData) FormatOutputFRBApplicationIdentification(options FormatOptions) string {
return omad.formatAlphaField(omad.OutputFRBApplicationIdentification, 4, options)
}