2014-06-04 01:39:50 -07:00
|
|
|
package binary
|
2014-05-19 20:46:41 -07:00
|
|
|
|
2014-06-03 17:03:29 -07:00
|
|
|
import "io"
|
2014-05-19 20:46:41 -07:00
|
|
|
|
2014-05-22 18:08:49 -07:00
|
|
|
// String
|
|
|
|
|
2014-12-09 18:49:04 -08:00
|
|
|
func WriteString(s string, w io.Writer, n *int64, err *error) {
|
|
|
|
WriteUInt32(uint32(len(s)), w, n, err)
|
|
|
|
WriteTo([]byte(s), w, n, err)
|
2014-06-30 16:53:04 -07:00
|
|
|
}
|
|
|
|
|
2014-09-03 19:21:19 -07:00
|
|
|
func ReadString(r io.Reader, n *int64, err *error) string {
|
|
|
|
length := ReadUInt32(r, n, err)
|
|
|
|
if *err != nil {
|
|
|
|
return ""
|
2014-07-28 01:41:25 -07:00
|
|
|
}
|
2014-09-03 19:21:19 -07:00
|
|
|
buf := make([]byte, int(length))
|
2014-12-09 18:49:04 -08:00
|
|
|
ReadFull(buf, r, n, err)
|
2014-09-03 19:21:19 -07:00
|
|
|
return string(buf)
|
2014-08-30 16:28:51 -07:00
|
|
|
}
|