Implement chunking.

Move from rpc to separate util package.
This commit is contained in:
Christian Schwarz
2017-04-15 17:07:32 +02:00
parent a790f8ee89
commit 69f8e7cfc3
3 changed files with 133 additions and 27 deletions
-26
View File
@@ -1,26 +0,0 @@
package rpc
struct Unchunker {
In io.Reader
internalBuffer []byte
remainingChunkSize uint
}
func NewUnchunker(conn io.Reader) {
return Unchunker{In: conn} // TODO
}
func (c Unchunker) Read(b []byte) (n int, error) {
// read min(c.internalBuffer.len, b.len) from c.internalBuffer into b
// fill up internalBuffer
// 1 read up to max(remainingChunkSize,internalBuffer.len) from In
// 2 if remainingChunkSize == 0, read next chunk size, update remainingChunkSize
// 3 goto 1
}
struct Chunker {
In io.Reader
MaxChunkSize uint
ChunkBuf []byte // length of buf determines chunk size? --> would be fixed then
}