go-hep.org/x/hep@v0.38.1/fwk/job/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 job 6 7 // Encoder encodes data into the underlying io.Writer 8 type Encoder interface { 9 Encode(data any) error 10 } 11 12 // Save saves a job's configuration description using the Encoder enc. 13 func Save(stmts []Stmt, enc Encoder) error { 14 return enc.Encode(stmts) 15 } 16 17 // Decoder decodes data from the unerlying io.Reader 18 type Decoder interface { 19 Decode(ptr any) error 20 } 21 22 // Load loads a job's configuration description using the Decoder dec. 23 func Load(dec Decoder) ([]Stmt, error) { 24 stmts := make([]Stmt, 0) 25 err := dec.Decode(&stmts) 26 if err != nil { 27 return nil, err 28 } 29 30 return stmts, nil 31 }