-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffer.go
57 lines (48 loc) · 809 Bytes
/
buffer.go
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
55
56
57
package loggo
import (
"bytes"
"io"
"sync"
)
type Buffer interface {
Bytes() []byte
String() string
Len() int
}
var (
buffer_pool = &sync.Pool{
New: func() interface{} {
return &bytes.Buffer{}
},
}
)
type ByteWarp []byte
func (b ByteWarp) Bytes() []byte {
return b
}
func (b ByteWarp) String() string {
return string(b)
}
func (b ByteWarp) Len() int {
return len(b)
}
type StringWarp string
func (s StringWarp) Bytes() []byte {
return []byte(s)
}
func (s StringWarp) String() string {
return string(s)
}
func (s StringWarp) Len() int {
return len(s)
}
type BufferWriter interface {
WriteBuffer(Buffer) (int, error)
}
type BufferWriterWarp struct {
w io.Writer
}
func (ww *BufferWriterWarp) WriteBuffer(b Buffer) (int, error) {
n, err := ww.w.Write(b.Bytes())
return n, err
}