Rename Results encoding functions

This commit is contained in:
Tomás Senart
2013-09-22 17:29:59 +02:00
parent 97aa7561a2
commit 0bc9d0ccbe
4 changed files with 8 additions and 8 deletions

View File

@@ -68,7 +68,7 @@ func attack(rate uint64, duration time.Duration, targetsf, ordering, output stri
results := vegeta.Attack(targets, rate, duration) results := vegeta.Attack(targets, rate, duration)
log.Println("Done!") log.Println("Done!")
log.Printf("Writing results to '%s'...", output) log.Printf("Writing results to '%s'...", output)
if err := results.WriteTo(out); err != nil { if err := results.Encode(out); err != nil {
return err return err
} }
return nil return nil

View File

@@ -22,15 +22,15 @@ type Result struct {
// decoding and sorting behavior attached // decoding and sorting behavior attached
type Results []Result type Results []Result
// WriteTo encodes the results and writes it to an io.Writer // Encode encodes the results and writes it to an io.Writer
// returning an error in case of failure // returning an error in case of failure
func (r Results) WriteTo(out io.Writer) error { func (r Results) Encode(out io.Writer) error {
return gob.NewEncoder(out).Encode(r) return gob.NewEncoder(out).Encode(r)
} }
// ReadFrom reads data from an io.Reader and decodes it into a Results struct // Decode reads data from an io.Reader and decodes it into a Results struct
// returning an error in case of failure // returning an error in case of failure
func (r *Results) ReadFrom(in io.Reader) error { func (r *Results) Decode(in io.Reader) error {
return gob.NewDecoder(in).Decode(r) return gob.NewDecoder(in).Decode(r)
} }

View File

@@ -15,12 +15,12 @@ func TestEncoding(t *testing.T) {
} }
buffer := &bytes.Buffer{} buffer := &bytes.Buffer{}
if err := results.WriteTo(buffer); err != nil { if err := results.Encode(buffer); err != nil {
t.Fatalf("Failed WriteTo: %s", err) t.Fatalf("Failed WriteTo: %s", err)
} }
decoded := Results{} decoded := Results{}
if err := decoded.ReadFrom(buffer); err != nil { if err := decoded.Decode(buffer); err != nil {
t.Fatalf("Failed ReadFrom: %s", err) t.Fatalf("Failed ReadFrom: %s", err)
} }

View File

@@ -43,7 +43,7 @@ func report(reporter, input, output string) error {
} }
defer in.Close() defer in.Close()
results := vegeta.Results{} results := vegeta.Results{}
if err := results.ReadFrom(in); err != nil { if err := results.Decode(in); err != nil {
return err return err
} }
all = append(all, results...) all = append(all, results...)