pull/700/head v2.46.1
Darien Raymond 2017-11-08 11:11:13 +01:00
parent 143488ad8c
commit 9cc9a76b71
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 3 additions and 1 deletions

View File

@ -8,11 +8,13 @@ import (
"v2ray.com/core/common/serial" "v2ray.com/core/common/serial"
) )
// ChunkSizeDecoder is an utility class to decode size value from bytes.
type ChunkSizeDecoder interface { type ChunkSizeDecoder interface {
SizeBytes() int SizeBytes() int
Decode([]byte) (uint16, error) Decode([]byte) (uint16, error)
} }
// ChunkSizeEncoder is an utility class to encode size value into bytes.
type ChunkSizeEncoder interface { type ChunkSizeEncoder interface {
SizeBytes() int SizeBytes() int
Encode(uint16, []byte) []byte Encode(uint16, []byte) []byte
@ -134,7 +136,7 @@ func (w *ChunkStreamWriter) Write(mb buf.MultiBuffer) error {
slice := mb.SliceBySize(sliceSize) slice := mb.SliceBySize(sliceSize)
b := buf.New() b := buf.New()
common.Must(b.AppendSupplier(func(buffer []byte) (int, error) { common.Must(b.Reset(func(buffer []byte) (int, error) {
w.sizeEncoder.Encode(uint16(slice.Len()), buffer[:0]) w.sizeEncoder.Encode(uint16(slice.Len()), buffer[:0])
return w.sizeEncoder.SizeBytes(), nil return w.sizeEncoder.SizeBytes(), nil
})) }))