Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsErrFewerThanMinOccurs ¶
IsErrFewerThanMinOccurs tells whether a given err is of ErrFewerThanMinOccurs type.
func IsErrUnexpectedData ¶
IsErrUnexpectedData tells whether a given err is of ErrUnexpectedData type.
Types ¶
type ErrFewerThanMinOccurs ¶
ErrFewerThanMinOccurs indicates the input data doesn't have the required minimum number of instances for a particular record decl.
func (ErrFewerThanMinOccurs) Error ¶
func (e ErrFewerThanMinOccurs) Error() string
Error is to satisfy the error interface. Receivers of this error can/should consider constructing their own file format specific error based on the payload of this error.
type ErrUnexpectedData ¶
type ErrUnexpectedData struct{}
ErrUnexpectedData indicates there is unprocessed and unexpected data from the inpput data stream that no record decl can match.
func (ErrUnexpectedData) Error ¶
func (e ErrUnexpectedData) Error() string
Error is to satisfy the error interface. Receivers of this error can/should consider constructing their own file format specific error based on the payload of this error.
type HierarchyReader ¶
type HierarchyReader struct {
// contains filtered or unexported fields
}
HierarchyReader orchestrates reading, matching, and converting (to IDR) of data streams of various flat file formats that (potentially) contain hierarchically structured records.
func NewHierarchyReader ¶
func NewHierarchyReader( decls []RecDecl, recReader RecReader, targetXPathExpr *xpath.Expr) *HierarchyReader
NewHierarchyReader creates a new instance of a HierarchyReader.
func (*HierarchyReader) Read ¶
func (r *HierarchyReader) Read() (*idr.Node, error)
Read orchestrates reading, matching, and converting (to IDR) of a data stream of a flat file format. Possible return values:
- (node, nil): a target node has been fetched successfully, ready for transformation.
- (nil, io.EOF): no more data to read, all operations completed successfully.
- (nil, ErrFewerThanMinOccurs): a record decl requires a min occurs but isn't satisified by the data stream.
- (nil, ErrUnexpectedData): some unknown/unexpected data encountered that isn't described by any of the record decls.
- (nil, other err): most likely IO failures.
func (*HierarchyReader) Release ¶
func (r *HierarchyReader) Release(n *idr.Node)
Release deallocates/recycles the cached IDR node. If the passed in IDR node happens to be the cached target node, we need to reset/clear the cached target node pointer.
type RecDecl ¶
type RecDecl interface { DeclName() string // to avoid collision, since most decl has Name as a field. Target() bool Group() bool MinOccurs() int MaxOccurs() int ChildDecls() []RecDecl }
RecDecl defines a flat file record. It is meant to be a common facade for all the actual unit of processing from each format, such as envelope from fixed length, segment from EDI, and record from csv, etc.
type RecReader ¶
type RecReader interface { // MoreUnprocessedData indicates whether there is any unprocessed data left in the input // stream. Possible return values: // - (true, nil): more data is available. // - (false, nil): no more data is available. // - (_, err): some and most likely fatal IO error has occurred. // Implementation notes: // - If some data is read in and io.EOF is encountered, (true, nil) should be returned. // - If no data is read in and io.EOF is encountered, (false, nil) should be returned. // - Under no circumstances, io.EOF should be returned. // - Once a call to this method returns (false, nil), all future calls to it should always // return (false, nil). MoreUnprocessedData() (more bool, err error) // ReadAndMatch matches the passed-in *non-group* RecDecl to unprocessed data and creates a // corresponding IDR node if data matches and createIDR flag is turned on. // Implementation notes: // - If io.EOF is encountered while there is still unmatched thus unprocessed data, // io.EOF shouldn't be returned. // - If a non io.EOF error encountered during IO, return (false, nil, err). ReadAndMatch(decl RecDecl, createIDR bool) (matched bool, node *idr.Node, err error) }
RecReader defines an interface for a flat file specific format to read data and match a RecDecl.