Skip to content

Commit 927d69a

Browse files
authored
Adding flatfile.RecReader interface - the primary data reading and record matching interface a new flat file format reader should implement. (#164)
1 parent e163197 commit 927d69a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package flatfile
2+
3+
import (
4+
"github.com/jf-tech/omniparser/idr"
5+
)
6+
7+
// RecReader defines an interface for a flat file specific format to read data and match
8+
// a RecDecl.
9+
type RecReader interface {
10+
// MoreUnprocessedData indicates whether there is any unprocessed data left in the input
11+
// stream. Possible return values:
12+
// - (true, nil): more data is available.
13+
// - (false, nil): no more data is available.
14+
// - (_, err): some and most likely fatal IO error has occurred.
15+
// Implementation notes:
16+
// - If some data is read in and io.EOF is encountered, (true, nil) should be returned.
17+
// - If no data is read in and io.EOF is encountered, (false, nil) should be returned.
18+
// - Under no circumstances, io.EOF should be returned.
19+
// - Once a call to this method returns (false, nil), all future calls to it should always
20+
// return (false, nil).
21+
MoreUnprocessedData() (more bool, err error)
22+
23+
// ReadAndMatch matches the passed-in RecDecl to unprocessed data and creates a
24+
// corresponding IDR node if data matches and createIDR flag is turned on.
25+
// Implementation notes:
26+
// - If io.EOF is encountered while there is still unmatched thus unprocessed data,
27+
// io.EOF shouldn't be returned.
28+
// - If a non io.EOF error encountered during IO, return (false, nil, err).
29+
// - If the decl is a Group(), the matching should be using the recursive algorithm
30+
// to match the first-heir-in-line non-group descendent decl. If matched, the returned
31+
// IDR node should be of this group node, and the actual matched record data should be
32+
// internally cached for the next call(s). This logic is similar to the EDI segment
33+
// matching logic:
34+
// https://github.com/jf-tech/omniparser/blob/6802ed98d0e5325a6908ebbc6d2da0e4655ed125/extensions/omniv21/fileformat/edi/seg.go#L87
35+
ReadAndMatch(decl RecDecl, createIDR bool) (matched bool, node *idr.Node, err error)
36+
}

0 commit comments

Comments
 (0)