98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
var enc encoder
enc.target = target
return &enc
}
type encoder struct {
target io.Writer
remaining byte
length byte
}
// Implements io.Writer
func (e *encoder) Write(input []byte) (int, error) {
var (
|
>
|
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
var enc encoder
enc.target = target
return &enc
}
type encoder struct {
target io.Writer
buffer [2]byte
remaining byte
length byte
}
// Implements io.Writer
func (e *encoder) Write(input []byte) (int, error) {
var (
|
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
continue
}
// Clearing e.length is not necessary as it will be overwritten later
// Stage the complete byte for writing
buffer := make([]byte, 1, 2)
buffer[0] = byte(e.remaining)
// Stage every full byte from the encoded value for writing
//
// The bitlength of the largest encoded byte value, 255, is 13.
// Even with 7 bits already in the buffer this leaves [7+1], [8]
// and 4 bits remaining => a single if is enough instead of a for.
|
|
|
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
continue
}
// Clearing e.length is not necessary as it will be overwritten later
// Stage the complete byte for writing
buffer := e.buffer[:1]
buffer[0] = byte(e.remaining)
// Stage every full byte from the encoded value for writing
//
// The bitlength of the largest encoded byte value, 255, is 13.
// Even with 7 bits already in the buffer this leaves [7+1], [8]
// and 4 bits remaining => a single if is enough instead of a for.
|