go-hep.org/x/hep@v0.38.1/fwk/internal/fwktest/inputstream.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 fwktest 6 7 import ( 8 "fmt" 9 "io" 10 11 "go-hep.org/x/hep/fwk" 12 ) 13 14 type InputStream struct { 15 output string 16 R io.Reader 17 } 18 19 func (stream *InputStream) Connect(ports []fwk.Port) error { 20 var err error 21 stream.output = ports[0].Name 22 23 return err 24 } 25 26 func (stream *InputStream) Read(ctx fwk.Context) error { 27 var err error 28 store := ctx.Store() 29 var data int64 30 _, err = fmt.Fscanf(stream.R, "%d\n", &data) 31 if err != nil { 32 return err 33 } 34 35 err = store.Put(stream.output, data) 36 if err != nil { 37 return err 38 } 39 40 return err 41 } 42 43 func (stream *InputStream) Disconnect() error { 44 var err error 45 return err 46 }