-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
40 lines (34 loc) · 838 Bytes
/
types.go
File metadata and controls
40 lines (34 loc) · 838 Bytes
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
package cbytecache
import (
"github.com/koykov/byteconv"
)
/*
* Exportable types to use in subpackages.
*/
// Enqueuer is the interface that wraps the basic Enqueue method.
//
// Uses for queue.DumpWriter and queue.Listener that contains underlying queue.
type Enqueuer interface {
Enqueue(any) error
}
// Entry represent external entry object.
type Entry struct {
Key string
Body []byte
Expire uint32
}
// Copy copies entry to avoid overwrite entry data.
func (e Entry) Copy() Entry {
buf := make([]byte, 0, len(e.Key)+len(e.Body))
buf = append(buf, e.Key...)
buf = append(buf, e.Body...)
var cpy Entry
cpy.Key = byteconv.B2S(buf[:len(e.Key)])
cpy.Body = buf[len(e.Key):]
cpy.Expire = e.Expire
return cpy
}
// Size returns entry size in bytes.
func (e Entry) Size() int {
return len(e.Key) + len(e.Body) + 4
}