You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
609 B

11 years ago
  1. package wire
  2. import (
  3. "io"
  4. . "github.com/tendermint/tendermint/common"
  5. )
  6. // String
  7. func WriteString(s string, w io.Writer, n *int64, err *error) {
  8. WriteVarint(len(s), w, n, err)
  9. WriteTo([]byte(s), w, n, err)
  10. }
  11. func ReadString(r io.Reader, n *int64, err *error) string {
  12. length := ReadVarint(r, n, err)
  13. if *err != nil {
  14. return ""
  15. }
  16. if length < 0 {
  17. *err = ErrBinaryReadSizeUnderflow
  18. return ""
  19. }
  20. if MaxBinaryReadSize < MaxInt64(int64(length), *n+int64(length)) {
  21. *err = ErrBinaryReadSizeOverflow
  22. return ""
  23. }
  24. buf := make([]byte, length)
  25. ReadFull(buf, r, n, err)
  26. return string(buf)
  27. }