forked from flowchartsman/boltqueue
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmessage.go
More file actions
36 lines (29 loc) · 846 Bytes
/
Copy pathmessage.go
File metadata and controls
36 lines (29 loc) · 846 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
package boltqueue
// Message represents a message in the priority queue
type Message struct {
key []byte
value []byte
priority int
}
// NewMessage generates a new priority queue message
func NewMessage(value string) *Message {
return &Message{nil, []byte(value), -1}
}
func NewBytesMessage(value []byte) *Message {
return &Message{nil, value, -1}
}
// Priority returns the priority the message had in the queue in the range of
// 0-255 or -1 if the message is new.
func (m *Message) Priority() int {
return m.priority
}
// ToString outputs the string representation of the message's value
func (m *Message) ToString() string {
return string(m.value)
}
func (m *Message) Bytes() []byte {
return m.value
}
func (m *Message) SetValue(value []byte) { // ease setting the value of previously dequeued message
m.value = value
}