go-hep.org/x/hep@v0.38.1/fwk/io.go (about)

     1  // Copyright ©2017 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package fwk
     6  
     7  // StreamControl provides concurrency-safe control to input and output streamers.
     8  type StreamControl struct {
     9  	Ports []Port        // list of ports streamers will read-from or write-to
    10  	Ctx   chan Context  // contexts to read-from or write-to
    11  	Err   chan error    // errors encountered during reading-from or writing-to
    12  	Quit  chan struct{} // closed to signify in/out-streamers should stop reading-from/writing-to
    13  }
    14  
    15  // InputStreamer reads data from the underlying io.Reader
    16  // and puts it into fwk's Context
    17  type InputStreamer interface {
    18  
    19  	// Connect connects the InputStreamer to the underlying io.Reader,
    20  	// and configure it to only read-in the data specified in ports.
    21  	Connect(ports []Port) error
    22  
    23  	// Read reads the data from the underlying io.Reader
    24  	// and puts it in the store associated with the fwk.Context ctx
    25  	Read(ctx Context) error
    26  
    27  	// Disconnect disconnects the InputStreamer from the underlying io.Reader,
    28  	// possibly computing some statistics data.
    29  	// It does not (and can not) close the underlying io.Reader.
    30  	Disconnect() error
    31  }
    32  
    33  // OutputStreamer gets data from the Context
    34  // and writes it to the underlying io.Writer
    35  type OutputStreamer interface {
    36  
    37  	// Connect connects the OutputStreamer to the underlying io.Writer,
    38  	// and configure it to only write-out the data specified in ports.
    39  	Connect(ports []Port) error
    40  
    41  	// Write gets the data from the store associated with the fwk.Context ctx
    42  	// and writes it to the underlying io.Writer
    43  	Write(ctx Context) error
    44  
    45  	// Disconnect disconnects the OutputStreamer from the underlying io.Writer,
    46  	// possibly computing some statistics data.
    47  	// It does not (and can not) close the underlying io.Writer.
    48  	Disconnect() error
    49  }