-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbytes.go
More file actions
42 lines (34 loc) · 747 Bytes
/
bytes.go
File metadata and controls
42 lines (34 loc) · 747 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
41
42
package concurrent
import (
"sync"
)
// NewBytes creates a new concurrent slice of bytes
func NewBytes() *Bytes {
return &Bytes{}
}
// Bytes implements a cuncurrent slice of bytes
type Bytes struct {
byte []byte
byteMutex sync.RWMutex
//chSet chan []byte
//chAppend chan []byte
//chGet chan chan []byte
}
// Set sets the byte to given value
func (s *Bytes) Set(b []byte) {
s.byteMutex.Lock()
s.byte = b
s.byteMutex.Unlock()
}
// Get gets the byte value
func (s *Bytes) Get() []byte {
s.byteMutex.RLock()
defer s.byteMutex.RUnlock()
return s.byte
}
// Append appends the slice of bytes value to byte
func (s *Bytes) Append(m []byte) {
s.byteMutex.Lock()
defer s.byteMutex.Unlock()
s.byte = append(s.byte, m...)
}