File: recent.go

package info (click to toggle)
golang-github-protonmail-gluon 0.17.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,020 kB
  • sloc: sh: 55; makefile: 5
file content (54 lines) | stat: -rw-r--r-- 843 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package response

import (
	"fmt"
)

type recent struct {
	count uint32
}

func Recent() *recent {
	return &recent{}
}

func (r *recent) WithCount(n uint32) *recent {
	r.count = n
	return r
}

func (r *recent) Send(s Session) error {
	return s.WriteResponse(r.String())
}

func (r *recent) String() string {
	return fmt.Sprintf("* %v RECENT", r.count)
}

func (r *recent) canSkip(other Response) bool {
	if _, isExists := other.(*exists); isExists {
		return true
	}

	if _, isFetch := other.(*fetch); isFetch {
		return true
	}

	return false
}

func (r *recent) mergeWith(other Response) Response {
	otherRecent, ok := other.(*recent)
	if !ok {
		return nil
	}

	if otherRecent.count > r.count {
		panic(fmt.Sprintf(
			"consecutive recents must be non-decreasing, but had %d and new %d",
			otherRecent.count, r.count,
		))
	}

	return r
}