-
Notifications
You must be signed in to change notification settings - Fork 39
/
inputMessageAccountabilityData.go
127 lines (114 loc) · 4.04 KB
/
inputMessageAccountabilityData.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
// 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"
)
// InputMessageAccountabilityData (IMAD) {1520}
type InputMessageAccountabilityData struct {
// tag
tag string
// InputCycleDate CCYYMMDD
InputCycleDate string `json:"inputCycleDate"`
// InputSource
InputSource string `json:"inputSource"`
// InputSequenceNumber
InputSequenceNumber string `json:"inputSequenceNumber"`
// validator is composed for data validation
validator
// converters is composed for WIRE to GoLang Converters
converters
}
// NewInputMessageAccountabilityData returns a new InputMessageAccountabilityData
func NewInputMessageAccountabilityData() *InputMessageAccountabilityData {
imad := &InputMessageAccountabilityData{
tag: TagInputMessageAccountabilityData,
}
return imad
}
// Parse takes the input string and parses the InputMessageAccountabilityData 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 (imad *InputMessageAccountabilityData) Parse(record string) error {
if utf8.RuneCountInString(record) != 28 {
return NewTagWrongLengthErr(28, len(record))
}
imad.tag = record[:6]
imad.InputCycleDate = imad.parseStringField(record[6:14])
imad.InputSource = imad.parseStringField(record[14:22])
imad.InputSequenceNumber = imad.parseStringField(record[22:28])
return nil
}
func (imad *InputMessageAccountabilityData) UnmarshalJSON(data []byte) error {
type Alias InputMessageAccountabilityData
aux := struct {
*Alias
}{
(*Alias)(imad),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
imad.tag = TagInputMessageAccountabilityData
return nil
}
// String writes InputMessageAccountabilityData
func (imad *InputMessageAccountabilityData) String() string {
var buf strings.Builder
buf.Grow(22)
buf.WriteString(imad.tag)
buf.WriteString(imad.InputCycleDateField())
buf.WriteString(imad.InputSourceField())
buf.WriteString(imad.InputSequenceNumberField())
return buf.String()
}
// Validate performs WIRE format rule checks on InputMessageAccountabilityData and returns an error if not Validated
// The first error encountered is returned and stops that parsing.
func (imad *InputMessageAccountabilityData) Validate() error {
if err := imad.fieldInclusion(); err != nil {
return err
}
if imad.tag != TagInputMessageAccountabilityData {
return fieldError("tag", ErrValidTagForType, imad.tag)
}
if err := imad.validateDate(imad.InputCycleDate); err != nil {
return fieldError("InputCycleDate", err, imad.InputCycleDate)
}
if err := imad.isAlphanumeric(imad.InputSource); err != nil {
return fieldError("InputSource", err, imad.InputSource)
}
if err := imad.isNumeric(imad.InputSequenceNumber); err != nil {
return fieldError("InputSequenceNumber", err, imad.InputSequenceNumber)
}
return nil
}
// fieldInclusion validate mandatory fields. If fields are
// invalid the WIRE will return an error.
func (imad *InputMessageAccountabilityData) fieldInclusion() error {
if imad.InputCycleDate == "" {
return fieldError("InputCycleDate", ErrFieldRequired, imad.InputCycleDate)
}
if imad.InputSource == "" {
return fieldError("InputSource", ErrFieldRequired, imad.InputSource)
}
if imad.InputSequenceNumber == "" {
return fieldError("InputSequenceNumber", ErrFieldRequired, imad.InputSequenceNumber)
}
return nil
}
// InputCycleDateField gets a string of the InputCycleDate field
func (imad *InputMessageAccountabilityData) InputCycleDateField() string {
return imad.alphaField(imad.InputCycleDate, 8)
}
// InputSourceField gets a string of the InputSource field
func (imad *InputMessageAccountabilityData) InputSourceField() string {
return imad.alphaField(imad.InputSource, 8)
}
// InputSequenceNumberField gets a string of the InputSequenceNumber field
func (imad *InputMessageAccountabilityData) InputSequenceNumberField() string {
return imad.alphaField(imad.InputSequenceNumber, 6)
}