fixed algorithm

This commit is contained in:
Jae Kwon
2014-09-14 15:37:32 -07:00
parent c73f40b844
commit 8e452aa0d2
35 changed files with 2637 additions and 2295 deletions

View File

@ -4,8 +4,6 @@ import (
"io"
)
// ByteSlice
func WriteByteSlice(w io.Writer, bz []byte, n *int64, err *error) {
WriteUInt32(w, uint32(len(bz)), n, err)
WriteTo(w, bz, n, err)
@ -20,3 +18,31 @@ func ReadByteSlice(r io.Reader, n *int64, err *error) []byte {
ReadFull(r, buf, n, err)
return buf
}
//-----------------------------------------------------------------------------
func WriteByteSlices(w io.Writer, bzz [][]byte, n *int64, err *error) {
WriteUInt32(w, uint32(len(bzz)), n, err)
for _, bz := range bzz {
WriteByteSlice(w, bz, n, err)
if *err != nil {
return
}
}
}
func ReadByteSlices(r io.Reader, n *int64, err *error) [][]byte {
length := ReadUInt32(r, n, err)
if *err != nil {
return nil
}
bzz := make([][]byte, length)
for i := uint32(0); i < length; i++ {
bz := ReadByteSlice(r, n, err)
if *err != nil {
return nil
}
bzz[i] = bz
}
return bzz
}