You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
706 B
Go
34 lines
706 B
Go
9 years ago
|
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{}}
|
||
|
}
|