-
Notifications
You must be signed in to change notification settings - Fork 26
/
data_encoding.go
33 lines (27 loc) · 706 Bytes
/
data_encoding.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
package dmr
import (
"golang.org/x/text/encoding"
"golang.org/x/text/transform"
)
type binaryCoder struct{ transform.NopResetter }
func (e binaryCoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) {
// The decoder can only make the input larger, not smaller.
n := len(src)
if len(dst) < n {
err = transform.ErrShortDst
n = len(dst)
atEOF = false
} else {
copy(dst[:n], src)
nDst = n
nSrc = n
}
return
}
type binaryEncoding struct{}
func (e binaryEncoding) NewDecoder() *encoding.Decoder {
return &encoding.Decoder{Transformer: binaryCoder{}}
}
func (e binaryEncoding) NewEncoder() *encoding.Encoder {
return &encoding.Encoder{Transformer: binaryCoder{}}
}