tendermint/wire/string.go

34 lines
609 B
Go
Raw Normal View History

2015-07-25 15:45:45 -07:00
package wire
import (
"io"
. "github.com/tendermint/tendermint/common"
)
2014-05-22 18:08:49 -07:00
// 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
2015-07-07 18:35:21 -07:00
return ""
}
buf := make([]byte, length)
ReadFull(buf, r, n, err)
return string(buf)
2014-08-30 16:28:51 -07:00
}