go-hep.org/x/hep@v0.38.1/fwk/internal/fwktest/outputstream.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 "io" 9 "strconv" 10 11 "go-hep.org/x/hep/fwk" 12 ) 13 14 type OutputStream struct { 15 input string 16 17 W io.Writer 18 } 19 20 func (out *OutputStream) Connect(ports []fwk.Port) error { 21 var err error 22 out.input = ports[0].Name 23 return err 24 } 25 26 func (out *OutputStream) Write(ctx fwk.Context) error { 27 var err error 28 store := ctx.Store() 29 v, err := store.Get(out.input) 30 if err != nil { 31 return err 32 } 33 34 data := v.(int64) 35 _, err = out.W.Write([]byte(strconv.FormatInt(data, 10) + "\n")) 36 if err != nil { 37 return err 38 } 39 40 return err 41 } 42 43 func (out *OutputStream) Disconnect() error { 44 var err error 45 46 return err 47 }