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
373 B

11 years ago
  1. package binary
  2. import "io"
  3. // String
  4. func WriteString(s string, w io.Writer, n *int64, err *error) {
  5. WriteVarint(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 := ReadVarint(r, n, err)
  10. if *err != nil {
  11. return ""
  12. }
  13. buf := make([]byte, length)
  14. ReadFull(buf, r, n, err)
  15. return string(buf)
  16. }