diff --git a/flags.go b/flags.go index 09e3e7fb3..a7fbecdf5 100644 --- a/flags.go +++ b/flags.go @@ -45,8 +45,8 @@ var symbolLength = flag.Int("symbollength", 72, "symbol length in samples, see - var decimation = flag.Int("decimation", 1, "integer decimation factor, keep every nth sample") var timeLimit = flag.Duration("duration", 0, "time to run for, 0 for infinite, ex. 1h5m10s") -var meterID UintMap -var meterType UintMap +var meterID MeterIDFilter +var meterType MeterTypeFilter var unique = flag.Bool("unique", false, "suppress duplicate messages from each meter") @@ -58,8 +58,8 @@ var quiet = flag.Bool("quiet", false, "suppress printing state information at st var single = flag.Bool("single", false, "one shot execution") func RegisterFlags() { - meterID = make(UintMap) - meterType = make(UintMap) + meterID = MeterIDFilter{make(UintMap)} + meterType = MeterTypeFilter{make(UintMap)} flag.Var(meterID, "filterid", "display only messages matching an id in a comma-separated list of ids.") flag.Var(meterType, "filtertype", "display only messages matching a type in a comma-separated list of types.") @@ -171,16 +171,20 @@ func (m UintMap) Set(value string) error { return nil } -type MeterIDFilter UintMap +type MeterIDFilter struct { + UintMap +} func (m MeterIDFilter) Filter(msg parse.Message) bool { - return m[uint(msg.MeterID())] + return m.UintMap[uint(msg.MeterID())] } -type MeterTypeFilter UintMap +type MeterTypeFilter struct { + UintMap +} func (m MeterTypeFilter) Filter(msg parse.Message) bool { - return m[uint(msg.MeterType())] + return m.UintMap[uint(msg.MeterType())] } type UniqueFilter map[uint][]byte diff --git a/parse/parse.go b/parse/parse.go index 565585fb8..0b283fbe1 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -78,9 +78,9 @@ func (msg LogMessage) Record() (r []string) { return r } -type FilterChain []Filter +type FilterChain []MessageFilter -func (fc *FilterChain) Add(filter Filter) { +func (fc *FilterChain) Add(filter MessageFilter) { *fc = append(*fc, filter) } @@ -90,7 +90,7 @@ func (fc FilterChain) Match(msg Message) bool { } for _, filter := range fc { - if !filter.Filter(msg) { + if !filter.MessageFilter(msg) { return false } } @@ -98,6 +98,6 @@ func (fc FilterChain) Match(msg Message) bool { return true } -type Filter interface { +type MessageFilter interface { Filter(Message) bool } diff --git a/recv.go b/recv.go index d99ac189c..bf7702bc7 100644 --- a/recv.go +++ b/recv.go @@ -85,9 +85,9 @@ func (rcvr *Receiver) NewReceiver() { case "unique": rcvr.fc.Add(NewUniqueFilter()) case "filterid": - rcvr.fc.Add(MeterIDFilter(meterID)) + rcvr.fc.Add(meterID) case "filtertype": - rcvr.fc.Add(MeterTypeFilter(meterType)) + rcvr.fc.Add(meterType) default: fmt.Println(f.Name) }