architecting peer

This commit is contained in:
Jae Kwon
2014-06-24 17:28:40 -07:00
parent 12c12b1a72
commit 002cfc8f75
14 changed files with 986 additions and 1043 deletions

View File

@ -40,3 +40,11 @@ func ReadByteSlice(r io.Reader) ByteSlice {
if err != nil { panic(err) }
return ByteSlice(bytes)
}
func ReadByteSliceSafe(r io.Reader) (ByteSlice, error) {
length := int(ReadUInt32(r))
bytes := make([]byte, length)
_, err := io.ReadFull(r, bytes)
if err != nil { return nil, err }
return ByteSlice(bytes), nil
}