| Index: go/src/infra/libs/infra_util/buf.go
|
| diff --git a/go/src/infra/libs/infra_util/buf.go b/go/src/infra/libs/infra_util/buf.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6dab61e45e6ee6e57912c1bae20bea27d1460a3c
|
| --- /dev/null
|
| +++ b/go/src/infra/libs/infra_util/buf.go
|
| @@ -0,0 +1,35 @@
|
| +package infra_util
|
| +
|
| +import "io"
|
| +
|
| +type Nomable interface {
|
| + ReadString(delim byte) (string, error)
|
| +}
|
| +
|
| +// Returns `func(byte) string` which will read from |buf| until the byte,
|
| +// returning the string read. If an error is encountered, this will panic.
|
| +func Nom(buf Nomable) func(byte) string {
|
| + return func(delim byte) string {
|
| + ret, err := buf.ReadString(delim)
|
| + if err != nil {
|
| + panic(err)
|
| + }
|
| + return ret[:len(ret)-1]
|
| + }
|
| +}
|
| +
|
| +// Returns `func (int) []byte` which will read the specified number of bytes
|
| +// from |buf|, or panic.
|
| +func Yoink(buf io.Reader) func(int) []byte {
|
| + return func(num int) []byte {
|
| + ret := make([]byte, num)
|
| + i, err := io.ReadFull(buf, ret)
|
| + if err != nil {
|
| + panic(err)
|
| + }
|
| + if i != len(ret) {
|
| + panic("yoink: failed to read enough data")
|
| + }
|
| + return ret
|
| + }
|
| +}
|
|
|