package audit type Window struct { Last uint16 HasLast bool Summary Summary } func (w *Window) Observe(sequence uint16) string { if !w.HasLast { w.Last, w.HasLast = sequence, true w.Summary.Accepted++ w.Summary.Latest = sequence return "accepted" } delta := uint16(sequence - w.Last) if delta == 0 { w.Summary.Duplicate++; return "duplicate" } if delta > 32767 { w.Summary.Reordered++; return "reordered" } if delta > 1 { w.Summary.Lost += uint64(delta - 1) } w.Last, w.Summary.Latest = sequence, sequence w.Summary.Accepted++ return "accepted" }