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.

20 lines
386 B

10 years ago
  1. package binary
  2. import "io"
  3. // String
  4. func WriteString(s string, w io.Writer, n *int64, err *error) {
  5. WriteUvarint(uint(len(s)), w, n, err)
  6. WriteTo([]byte(s), w, n, err)
  7. }
  8. func ReadString(r io.Reader, n *int64, err *error) string {
  9. length := ReadUvarint(r, n, err)
  10. if *err != nil {
  11. return ""
  12. }
  13. buf := make([]byte, int(length))
  14. ReadFull(buf, r, n, err)
  15. return string(buf)
  16. }