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.

38 lines
681 B

11 years ago
11 years ago
11 years ago
  1. package binary
  2. import "io"
  3. type Binary interface {
  4. WriteTo(w io.Writer) (int64, error)
  5. }
  6. func WriteBinary(w io.Writer, b Binary, n *int64, err *error) {
  7. if *err != nil {
  8. return
  9. }
  10. n_, err_ := b.WriteTo(w)
  11. *n += int64(n_)
  12. *err = err_
  13. }
  14. // Write all of bz to w
  15. // Increment n and set err accordingly.
  16. func WriteTo(w io.Writer, bz []byte, n *int64, err *error) {
  17. if *err != nil {
  18. return
  19. }
  20. n_, err_ := w.Write(bz)
  21. *n += int64(n_)
  22. *err = err_
  23. }
  24. // Read len(buf) from r
  25. // Increment n and set err accordingly.
  26. func ReadFull(r io.Reader, buf []byte, n *int64, err *error) {
  27. if *err != nil {
  28. return
  29. }
  30. n_, err_ := io.ReadFull(r, buf)
  31. *n += int64(n_)
  32. *err = err_
  33. }