1
2
3
4
5
6
7
8
9
10
11
12
13
|
// Package predictor implements the predictor compression/decompression algorithm
// as specified by RFC1978 - PPP Predictor Compression Protocol
package predictor
import (
bits "0dev.org/bits"
"io"
)
type context struct {
table [1 << 16]byte
input []byte
hash uint16
|
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
// Package predictor implements the predictor compression/decompression algorithm
// as specified by RFC1978 - PPP Predictor Compression Protocol
package predictor
import (
bits "0dev.org/bits"
iou "0dev.org/ioutil"
"io"
)
type context struct {
table [1 << 16]byte
input []byte
hash uint16
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
return nil
}
return write
}
// A function type alias so that it can have methods attached to it
type decompressor func([]byte) (int, error)
// Required to implement io.Reader
func (r decompressor) Read(output []byte) (int, error) {
return r(output)
}
// Returns an io.Reader implementation that wraps the provided io.Reader
// and decompresses data according to the predictor algorithm
func Decompressor(reader io.Reader) io.Reader {
var ctx context
ctx.input = make([]byte, 0, 8)
return decompressor(func(output []byte) (int, error) {
var (
err error
flags, predicted byte
rc, total, copied int
)
// Sanity check for space to read into
|
<
<
<
<
<
<
<
<
|
|
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
return nil
}
return write
}
// Returns an io.Reader implementation that wraps the provided io.Reader
// and decompresses data according to the predictor algorithm
func Decompressor(reader io.Reader) io.Reader {
var ctx context
ctx.input = make([]byte, 0, 8)
return iou.ReaderFunc(func(output []byte) (int, error) {
var (
err error
flags, predicted byte
rc, total, copied int
)
// Sanity check for space to read into
|