aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/binary
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-12-01 12:15:45 -0500
committerRuss Cox <rsc@golang.org>2021-12-13 18:45:54 +0000
commit2580d0e08d5e9f979b943758d3c49877fb2324cb (patch)
tree3aafccfd81087734156a1778ce2321adf345f271 /src/encoding/binary
parent083ef5462494e81ee23316245c5d65085a3f62d9 (diff)
downloadgo-2580d0e08d5e9f979b943758d3c49877fb2324cb.tar.xz
all: gofmt -w -r 'interface{} -> any' src
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/encoding/binary')
-rw-r--r--src/encoding/binary/binary.go8
-rw-r--r--src/encoding/binary/binary_test.go16
-rw-r--r--src/encoding/binary/example_test.go2
3 files changed, 13 insertions, 13 deletions
diff --git a/src/encoding/binary/binary.go b/src/encoding/binary/binary.go
index 52417a7933..ee933461ee 100644
--- a/src/encoding/binary/binary.go
+++ b/src/encoding/binary/binary.go
@@ -159,7 +159,7 @@ func (bigEndian) GoString() string { return "binary.BigEndian" }
// The error is EOF only if no bytes were read.
// If an EOF happens after reading some but not all the bytes,
// Read returns ErrUnexpectedEOF.
-func Read(r io.Reader, order ByteOrder, data interface{}) error {
+func Read(r io.Reader, order ByteOrder, data any) error {
// Fast path for basic types and slices.
if n := intDataSize(data); n != 0 {
bs := make([]byte, n)
@@ -268,7 +268,7 @@ func Read(r io.Reader, order ByteOrder, data interface{}) error {
// and read from successive fields of the data.
// When writing structs, zero values are written for fields
// with blank (_) field names.
-func Write(w io.Writer, order ByteOrder, data interface{}) error {
+func Write(w io.Writer, order ByteOrder, data any) error {
// Fast path for basic types and slices.
if n := intDataSize(data); n != 0 {
bs := make([]byte, n)
@@ -392,7 +392,7 @@ func Write(w io.Writer, order ByteOrder, data interface{}) error {
// Size returns how many bytes Write would generate to encode the value v, which
// must be a fixed-size value or a slice of fixed-size values, or a pointer to such data.
// If v is neither of these, Size returns -1.
-func Size(v interface{}) int {
+func Size(v any) int {
return dataSize(reflect.Indirect(reflect.ValueOf(v)))
}
@@ -696,7 +696,7 @@ func (e *encoder) skip(v reflect.Value) {
// intDataSize returns the size of the data required to represent the data when encoded.
// It returns zero if the type cannot be implemented by the fast path in Read or Write.
-func intDataSize(data interface{}) int {
+func intDataSize(data any) int {
switch data := data.(type) {
case bool, int8, uint8, *bool, *int8, *uint8:
return 1
diff --git a/src/encoding/binary/binary_test.go b/src/encoding/binary/binary_test.go
index 83af89e8a7..9e1b5f12db 100644
--- a/src/encoding/binary/binary_test.go
+++ b/src/encoding/binary/binary_test.go
@@ -113,7 +113,7 @@ var src = []byte{1, 2, 3, 4, 5, 6, 7, 8}
var res = []int32{0x01020304, 0x05060708}
var putbuf = []byte{0, 0, 0, 0, 0, 0, 0, 0}
-func checkResult(t *testing.T, dir string, order ByteOrder, err error, have, want interface{}) {
+func checkResult(t *testing.T, dir string, order ByteOrder, err error, have, want any) {
if err != nil {
t.Errorf("%v %v: %v", dir, order, err)
return
@@ -123,13 +123,13 @@ func checkResult(t *testing.T, dir string, order ByteOrder, err error, have, wan
}
}
-func testRead(t *testing.T, order ByteOrder, b []byte, s1 interface{}) {
+func testRead(t *testing.T, order ByteOrder, b []byte, s1 any) {
var s2 Struct
err := Read(bytes.NewReader(b), order, &s2)
checkResult(t, "Read", order, err, s2, s1)
}
-func testWrite(t *testing.T, order ByteOrder, b []byte, s1 interface{}) {
+func testWrite(t *testing.T, order ByteOrder, b []byte, s1 any) {
buf := new(bytes.Buffer)
err := Write(buf, order, s1)
checkResult(t, "Write", order, err, buf.Bytes(), b)
@@ -175,7 +175,7 @@ func TestReadBoolSlice(t *testing.T) {
}
// Addresses of arrays are easier to manipulate with reflection than are slices.
-var intArrays = []interface{}{
+var intArrays = []any{
&[100]int8{},
&[100]int16{},
&[100]int32{},
@@ -304,7 +304,7 @@ func TestSizeStructCache(t *testing.T) {
count := func() int {
var i int
- structSize.Range(func(_, _ interface{}) bool {
+ structSize.Range(func(_, _ any) bool {
i++
return true
})
@@ -329,7 +329,7 @@ func TestSizeStructCache(t *testing.T) {
}
testcases := []struct {
- val interface{}
+ val any
want int
}{
{new(foo), 1},
@@ -376,7 +376,7 @@ func TestUnexportedRead(t *testing.T) {
func TestReadErrorMsg(t *testing.T) {
var buf bytes.Buffer
- read := func(data interface{}) {
+ read := func(data any) {
err := Read(&buf, LittleEndian, data)
want := "binary.Read: invalid type " + reflect.TypeOf(data).String()
if err == nil {
@@ -457,7 +457,7 @@ func TestReadInvalidDestination(t *testing.T) {
}
func testReadInvalidDestination(t *testing.T, order ByteOrder) {
- destinations := []interface{}{
+ destinations := []any{
int8(0),
int16(0),
int32(0),
diff --git a/src/encoding/binary/example_test.go b/src/encoding/binary/example_test.go
index b994b897ce..4c10daaf68 100644
--- a/src/encoding/binary/example_test.go
+++ b/src/encoding/binary/example_test.go
@@ -24,7 +24,7 @@ func ExampleWrite() {
func ExampleWrite_multi() {
buf := new(bytes.Buffer)
- var data = []interface{}{
+ var data = []any{
uint16(61374),
int8(-54),
uint8(254),