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(w io.Writer, s string, n *int64, err *error) {
  5. WriteUInt32(w, uint32(len(s)), n, err)
  6. WriteTo(w, []byte(s), n, err)
  7. }
  8. func ReadString(r io.Reader, n *int64, err *error) string {
  9. length := ReadUInt32(r, n, err)
  10. if *err != nil {
  11. return ""
  12. }
  13. buf := make([]byte, int(length))
  14. ReadFull(r, buf, n, err)
  15. return string(buf)
  16. }