-
Notifications
You must be signed in to change notification settings - Fork 6
/
snappy.go
53 lines (41 loc) · 878 Bytes
/
snappy.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
package main
import (
"net"
"time"
"github.com/golang/snappy"
)
type snappyConn struct {
c net.Conn
sr *snappy.Reader
sw *snappy.Writer
}
func (s *snappyConn) Close() error {
return s.c.Close()
}
func (s *snappyConn) LocalAddr() net.Addr {
return s.c.LocalAddr()
}
func (s *snappyConn) RemoteAddr() net.Addr {
return s.c.RemoteAddr()
}
func (s *snappyConn) Read(b []byte) (int, error) {
if s.sr == nil {
s.sr = snappy.NewReader(s.c)
}
return s.sr.Read(b)
}
func (s *snappyConn) Write(b []byte) (int, error) {
if s.sw == nil {
s.sw = snappy.NewWriter(s.c)
}
return s.sw.Write(b)
}
func (s *snappyConn) SetDeadline(t time.Time) error {
return s.c.SetDeadline(t)
}
func (s *snappyConn) SetReadDeadline(t time.Time) error {
return s.c.SetReadDeadline(t)
}
func (s *snappyConn) SetWriteDeadline(t time.Time) error {
return s.c.SetWriteDeadline(t)
}