diff options
Diffstat (limited to 'src/pkg/encoding/binary')
| -rw-r--r-- | src/pkg/encoding/binary/binary.go | 12 | ||||
| -rw-r--r-- | src/pkg/encoding/binary/binary_test.go | 5 | ||||
| -rw-r--r-- | src/pkg/encoding/binary/varint.go | 12 | ||||
| -rw-r--r-- | src/pkg/encoding/binary/varint_test.go | 6 |
4 files changed, 17 insertions, 18 deletions
diff --git a/src/pkg/encoding/binary/binary.go b/src/pkg/encoding/binary/binary.go index c58f73694b..65b9f013fc 100644 --- a/src/pkg/encoding/binary/binary.go +++ b/src/pkg/encoding/binary/binary.go @@ -8,9 +8,9 @@ package binary import ( + "errors" "math" "io" - "os" "reflect" ) @@ -124,7 +124,7 @@ func (bigEndian) GoString() string { return "binary.BigEndian" } // or an array or struct containing only fixed-size values. // Bytes read from r are decoded using the specified byte order // and written to successive fields of the data. -func Read(r io.Reader, order ByteOrder, data interface{}) os.Error { +func Read(r io.Reader, order ByteOrder, data interface{}) error { // Fast path for basic types. if n := intDestSize(data); n != 0 { var b [8]byte @@ -161,11 +161,11 @@ func Read(r io.Reader, order ByteOrder, data interface{}) os.Error { case reflect.Slice: v = d default: - return os.NewError("binary.Read: invalid type " + d.Type().String()) + return errors.New("binary.Read: invalid type " + d.Type().String()) } size := TotalSize(v) if size < 0 { - return os.NewError("binary.Read: invalid type " + v.Type().String()) + return errors.New("binary.Read: invalid type " + v.Type().String()) } d := &decoder{order: order, buf: make([]byte, size)} if _, err := io.ReadFull(r, d.buf); err != nil { @@ -183,7 +183,7 @@ func Read(r io.Reader, order ByteOrder, data interface{}) os.Error { // or an array or struct containing only fixed-size values. // Bytes written to w are encoded using the specified byte order // and read from successive fields of the data. -func Write(w io.Writer, order ByteOrder, data interface{}) os.Error { +func Write(w io.Writer, order ByteOrder, data interface{}) error { // Fast path for basic types. var b [8]byte var bs []byte @@ -244,7 +244,7 @@ func Write(w io.Writer, order ByteOrder, data interface{}) os.Error { v := reflect.Indirect(reflect.ValueOf(data)) size := TotalSize(v) if size < 0 { - return os.NewError("binary.Write: invalid type " + v.Type().String()) + return errors.New("binary.Write: invalid type " + v.Type().String()) } buf := make([]byte, size) e := &encoder{order: order, buf: buf} diff --git a/src/pkg/encoding/binary/binary_test.go b/src/pkg/encoding/binary/binary_test.go index 73def50ee9..e3bf17ccc9 100644 --- a/src/pkg/encoding/binary/binary_test.go +++ b/src/pkg/encoding/binary/binary_test.go @@ -6,7 +6,6 @@ package binary import ( "io" - "os" "bytes" "math" "reflect" @@ -99,7 +98,7 @@ var little = []byte{ var src = []byte{1, 2, 3, 4, 5, 6, 7, 8} var res = []int32{0x01020304, 0x05060708} -func checkResult(t *testing.T, dir string, order ByteOrder, err os.Error, have, want interface{}) { +func checkResult(t *testing.T, dir string, order ByteOrder, err error, have, want interface{}) { if err != nil { t.Errorf("%v %v: %v", dir, order, err) return @@ -166,7 +165,7 @@ type byteSliceReader struct { remain []byte } -func (br *byteSliceReader) Read(p []byte) (int, os.Error) { +func (br *byteSliceReader) Read(p []byte) (int, error) { n := copy(p, br.remain) br.remain = br.remain[n:] return n, nil diff --git a/src/pkg/encoding/binary/varint.go b/src/pkg/encoding/binary/varint.go index c98e0e2bf5..d4872eea2c 100644 --- a/src/pkg/encoding/binary/varint.go +++ b/src/pkg/encoding/binary/varint.go @@ -25,8 +25,8 @@ package binary // format incompatible with a varint encoding for larger numbers (say 128-bit). import ( + "errors" "io" - "os" ) // MaxVarintLenN is the maximum length of a varint-encoded N-bit integer. @@ -99,17 +99,17 @@ func Varint(buf []byte) (int64, int) { } // WriteUvarint encodes x and writes the result to w. -func WriteUvarint(w io.Writer, x uint64) os.Error { +func WriteUvarint(w io.Writer, x uint64) error { var buf [MaxVarintLen64]byte n := PutUvarint(buf[:], x) _, err := w.Write(buf[0:n]) return err } -var overflow = os.NewError("binary: varint overflows a 64-bit integer") +var overflow = errors.New("binary: varint overflows a 64-bit integer") // ReadUvarint reads an encoded unsigned integer from r and returns it as a uint64. -func ReadUvarint(r io.ByteReader) (uint64, os.Error) { +func ReadUvarint(r io.ByteReader) (uint64, error) { var x uint64 var s uint for i := 0; ; i++ { @@ -130,7 +130,7 @@ func ReadUvarint(r io.ByteReader) (uint64, os.Error) { } // WriteVarint encodes x and writes the result to w. -func WriteVarint(w io.Writer, x int64) os.Error { +func WriteVarint(w io.Writer, x int64) error { ux := uint64(x) << 1 if x < 0 { ux = ^ux @@ -139,7 +139,7 @@ func WriteVarint(w io.Writer, x int64) os.Error { } // ReadVarint reads an encoded unsigned integer from r and returns it as a uint64. -func ReadVarint(r io.ByteReader) (int64, os.Error) { +func ReadVarint(r io.ByteReader) (int64, error) { ux, err := ReadUvarint(r) // ok to continue in presence of error x := int64(ux >> 1) if ux&1 != 0 { diff --git a/src/pkg/encoding/binary/varint_test.go b/src/pkg/encoding/binary/varint_test.go index ef51f09293..b553d6d4eb 100644 --- a/src/pkg/encoding/binary/varint_test.go +++ b/src/pkg/encoding/binary/varint_test.go @@ -6,7 +6,7 @@ package binary import ( "bytes" - "os" + "io" "testing" ) @@ -131,13 +131,13 @@ func TestBufferTooSmall(t *testing.T) { } x, err := ReadUvarint(bytes.NewBuffer(buf)) - if x != 0 || err != os.EOF { + if x != 0 || err != io.EOF { t.Errorf("ReadUvarint(%v): got x = %d, err = %s", buf, x, err) } } } -func testOverflow(t *testing.T, buf []byte, n0 int, err0 os.Error) { +func testOverflow(t *testing.T, buf []byte, n0 int, err0 error) { x, n := Uvarint(buf) if x != 0 || n != n0 { t.Errorf("Uvarint(%v): got x = %d, n = %d; want 0, %d", buf, x, n, n0) |
