tendermint/binary -> tendermint/wire

This commit is contained in:
Jae Kwon
2015-07-25 15:45:45 -07:00
parent 0ef5c3ad07
commit 3be3647dc8
64 changed files with 371 additions and 371 deletions

33
wire/string.go Normal file
View File

@ -0,0 +1,33 @@
package wire
import (
"io"
. "github.com/tendermint/tendermint/common"
)
// String
func WriteString(s string, w io.Writer, n *int64, err *error) {
WriteVarint(len(s), w, n, err)
WriteTo([]byte(s), w, n, err)
}
func ReadString(r io.Reader, n *int64, err *error) string {
length := ReadVarint(r, n, err)
if *err != nil {
return ""
}
if length < 0 {
*err = ErrBinaryReadSizeUnderflow
return ""
}
if MaxBinaryReadSize < MaxInt64(int64(length), *n+int64(length)) {
*err = ErrBinaryReadSizeOverflow
return ""
}
buf := make([]byte, length)
ReadFull(buf, r, n, err)
return string(buf)
}