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.

22 lines
388 B

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. package binary
  2. import (
  3. "io"
  4. )
  5. // ByteSlice
  6. func WriteByteSlice(w io.Writer, bz []byte, n *int64, err *error) {
  7. WriteUInt32(w, uint32(len(bz)), n, err)
  8. WriteTo(w, bz, n, err)
  9. }
  10. func ReadByteSlice(r io.Reader, n *int64, err *error) []byte {
  11. length := ReadUInt32(r, n, err)
  12. if *err != nil {
  13. return nil
  14. }
  15. buf := make([]byte, int(length))
  16. ReadFull(r, buf, n, err)
  17. return buf
  18. }