|
|
|
@ -10,19 +10,19 @@ import (
|
|
|
|
|
|
|
|
|
|
// ChunkSizeDecoder is a utility class to decode size value from bytes.
|
|
|
|
|
type ChunkSizeDecoder interface { |
|
|
|
|
SizeBytes() int |
|
|
|
|
SizeBytes() int32 |
|
|
|
|
Decode([]byte) (uint16, error) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ChunkSizeEncoder is a utility class to encode size value into bytes.
|
|
|
|
|
type ChunkSizeEncoder interface { |
|
|
|
|
SizeBytes() int |
|
|
|
|
SizeBytes() int32 |
|
|
|
|
Encode(uint16, []byte) []byte |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type PlainChunkSizeParser struct{} |
|
|
|
|
|
|
|
|
|
func (PlainChunkSizeParser) SizeBytes() int { |
|
|
|
|
func (PlainChunkSizeParser) SizeBytes() int32 { |
|
|
|
|
return 2 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -38,8 +38,8 @@ type AEADChunkSizeParser struct {
|
|
|
|
|
Auth *AEADAuthenticator |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (p *AEADChunkSizeParser) SizeBytes() int { |
|
|
|
|
return 2 + p.Auth.Overhead() |
|
|
|
|
func (p *AEADChunkSizeParser) SizeBytes() int32 { |
|
|
|
|
return 2 + int32(p.Auth.Overhead()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (p *AEADChunkSizeParser) Encode(size uint16, b []byte) []byte { |
|
|
|
@ -125,7 +125,7 @@ func (w *ChunkStreamWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|
|
|
|
b := buf.New() |
|
|
|
|
common.Must(b.Reset(func(buffer []byte) (int, error) { |
|
|
|
|
w.sizeEncoder.Encode(uint16(slice.Len()), buffer[:0]) |
|
|
|
|
return w.sizeEncoder.SizeBytes(), nil |
|
|
|
|
return int(w.sizeEncoder.SizeBytes()), nil |
|
|
|
|
})) |
|
|
|
|
mb2Write.Append(b) |
|
|
|
|
mb2Write.AppendMulti(slice) |
|
|
|
|