Permalink
Browse files

Use replay and source function wrappers.

  • Loading branch information...
1 parent 258bd57 commit eea5b83ca1d397fdb07d24bed6f3c82f5d0f7faf @dustin dustin committed Jun 7, 2012
Showing with 20 additions and 30 deletions.
  1. +20 −30 replay.go
View
@@ -49,43 +49,33 @@ func (r *replayEvent) TS() time.Time {
return r.Timestamp
}
-type replaySource struct {
- d *json.Decoder
-}
-
-func (r *replaySource) Next() replay.Event {
- rv := replayEvent{}
- err := r.d.Decode(&rv)
- if err != nil {
- if err != io.EOF {
- log.Printf("Error decoding: %v", err)
- }
- return nil
- }
- return &rv
-}
-
-type replayAction struct {
-}
-
-func (r *replayAction) Process(ev replay.Event) {
- re := ev.(*replayEvent)
- log.Printf("Got thing as of %v", re.TS())
- currentState.statech <- re
-}
-
func replayFile(replaySpeed float64, path string) {
r := replay.New(replaySpeed)
f, err := os.Open(path)
maybefatal(err, "Error opening replay data: %v", err)
defer f.Close()
g, err := gzip.NewReader(f)
maybefatal(err, "Error starting decompression stream: %v", err)
-
- rs := &replaySource{json.NewDecoder(g)}
- a := &replayAction{}
-
- toff := r.Run(rs, a)
+ d := json.NewDecoder(g)
+
+ src := replay.FunctionSource(func() replay.Event {
+ rv := replayEvent{}
+ err := d.Decode(&rv)
+ if err != nil {
+ if err != io.EOF {
+ log.Printf("Error decoding: %v", err)
+ }
+ return nil
+ }
+ return &rv
+ })
+
+ toff := r.Run(src,
+ replay.FunctionAction(func(ev replay.Event) {
+ re := ev.(*replayEvent)
+ log.Printf("Got thing as of %v", re.TS())
+ currentState.statech <- re
+ }))
tlbl := "early"
if int64(toff) < 0 {

0 comments on commit eea5b83

Please sign in to comment.