Skip to content

Commit 887e847

Browse files
authored
Merge pull request #78 from qmuntal/anyr
Rewrite interface{} to any
2 parents 017ccee + a1c4b99 commit 887e847

File tree

20 files changed

+156
-156
lines changed

20 files changed

+156
-156
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func init() {
206206
gltf.RegisterExtension(ExtensionName, Unmarshal)
207207
}
208208

209-
func Unmarshal(data []byte) (interface{}, error) {
209+
func Unmarshal(data []byte) (any, error) {
210210
foo := new(Foo)
211211
err := json.Unmarshal(data, foo)
212212
return foo, err

binary/binary.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99
// they all follow the same `generic` interface, and the only difference is the
1010
// type of the value:
1111
//
12-
// type Component interface {
13-
// Scalar([]byte) interface{}
14-
// Vec2([]byte) [2]interface{}
15-
// Vec3([]byte) [2]interface{}
16-
// Vec4([]byte) [2]interface{}
17-
// Mat2([]byte) [2][2]interface{}
18-
// Mat3([]byte) [3][3]interface{}
19-
// Mat4([]byte) [4][4]interface{}
20-
// PutScalar([]byte, interface{})
21-
// PutVec2([]byte, [2]interface{})
22-
// PutVec3([]byte, [3]interface{})
23-
// PutVec4([]byte, [4]interface{})
24-
// PutMat2([]byte, [2][2]interface{})
25-
// PutMat3([]byte, [3][3]interface{})
26-
// PutMat4([]byte, [4][4]interface{})
27-
// }
12+
// type Component interface {
13+
// Scalar([]byte) any
14+
// Vec2([]byte) [2]any
15+
// Vec3([]byte) [2]any
16+
// Vec4([]byte) [2]any
17+
// Mat2([]byte) [2][2]any
18+
// Mat3([]byte) [3][3]any
19+
// Mat4([]byte) [4][4]any
20+
// PutScalar([]byte, any)
21+
// PutVec2([]byte, [2]any)
22+
// PutVec3([]byte, [3]any)
23+
// PutVec4([]byte, [4]any)
24+
// PutMat2([]byte, [2][2]any)
25+
// PutMat3([]byte, [3][3]any)
26+
// PutMat4([]byte, [4][4]any)
27+
// }
2828
//
2929
// This package favors simplicity and compliance over efficiency,
3030
// but it is still an order of magnitude more performant than using the built-in

binary/encode.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
//
1515
// Data should be a slice of glTF predefined fixed-size types.
1616
// If data length is greater than the length of b, Read returns io.ErrShortBuffer.
17-
func Read(b []byte, byteStride uint32, data interface{}) error {
17+
func Read(b []byte, byteStride uint32, data any) error {
1818
c, t, n := Type(data)
1919
size := gltf.SizeOfElement(c, t)
2020
if byteStride == 0 {
@@ -222,7 +222,7 @@ func Read(b []byte, byteStride uint32, data interface{}) error {
222222
//
223223
// Data must be a slice of glTF predefined fixed-size types,
224224
// else it fallbacks to `encoding/binary.Write`.
225-
func Write(b []byte, stride uint32, data interface{}) error {
225+
func Write(b []byte, stride uint32, data any) error {
226226
c, t, n := Type(data)
227227
if n == 0 {
228228
return binary.Write(bytes.NewBuffer(b), binary.LittleEndian, data)

binary/encode_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ func buildBufferF(n int) []byte {
4949
func TestRead(t *testing.T) {
5050
type args struct {
5151
b []byte
52-
data interface{}
52+
data any
5353
}
5454
tests := []struct {
5555
name string
5656
args args
57-
want interface{}
57+
want any
5858
wantErr bool
5959
}{
6060
{"small", args{[]byte{0, 0}, []int8{1, 2, 3}}, []int8{0, 0}, true},
@@ -179,7 +179,7 @@ func TestRead(t *testing.T) {
179179
func TestWrite(t *testing.T) {
180180
type args struct {
181181
n int
182-
data interface{}
182+
data any
183183
}
184184
tests := []struct {
185185
name string

binary/slice.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
// MakeSliceBuffer returns the slice type associated with c and t and with the given element count.
1212
// If the buffer is an slice which type matches with the expected by the acr then it will
1313
// be used as backing slice.
14-
func MakeSliceBuffer(c gltf.ComponentType, t gltf.AccessorType, count uint32, buffer interface{}) interface{} {
14+
func MakeSliceBuffer(c gltf.ComponentType, t gltf.AccessorType, count uint32, buffer any) any {
1515
if buffer == nil {
1616
return MakeSlice(c, t, count)
1717
}
@@ -32,7 +32,7 @@ func MakeSliceBuffer(c gltf.ComponentType, t gltf.AccessorType, count uint32, bu
3232
// MakeSlice returns the slice type associated with c and t and with the given element count.
3333
// For example, if c is gltf.ComponentFloat and t is gltf.AccessorVec3
3434
// then MakeSlice(c, t, 5) is equivalent to make([][3]float32, 5).
35-
func MakeSlice(c gltf.ComponentType, t gltf.AccessorType, count uint32) interface{} {
35+
func MakeSlice(c gltf.ComponentType, t gltf.AccessorType, count uint32) any {
3636
var tp reflect.Type
3737
switch c {
3838
case gltf.ComponentUbyte:
@@ -68,7 +68,7 @@ func MakeSlice(c gltf.ComponentType, t gltf.AccessorType, count uint32) interfac
6868

6969
// Type returns the associated glTF type data.
7070
// It panics if data is not an slice.
71-
func Type(data interface{}) (c gltf.ComponentType, t gltf.AccessorType, count uint32) {
71+
func Type(data any) (c gltf.ComponentType, t gltf.AccessorType, count uint32) {
7272
v := reflect.ValueOf(data)
7373
if v.Kind() != reflect.Slice {
7474
panic(fmt.Sprintf("go3mf: binary.Type expecting a slice but got %s", v.Kind()))

binary/slice_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestMakeSlice(t *testing.T) {
1616
tests := []struct {
1717
name string
1818
args args
19-
want interface{}
19+
want any
2020
}{
2121
// Scalar
2222
{"[]uint8", args{gltf.ComponentUbyte, gltf.AccessorScalar, 5}, make([]uint8, 5)},
@@ -82,12 +82,12 @@ func TestMakeSliceBuffer(t *testing.T) {
8282
c gltf.ComponentType
8383
t gltf.AccessorType
8484
count uint32
85-
buffer interface{}
85+
buffer any
8686
}
8787
tests := []struct {
8888
name string
8989
args args
90-
want interface{}
90+
want any
9191
}{
9292
{"nil buffer", args{gltf.ComponentUbyte, gltf.AccessorVec2, 2, nil}, make([][2]uint8, 2)},
9393
{"empty buffer", args{gltf.ComponentUbyte, gltf.AccessorVec2, 2, make([][2]uint8, 0)}, make([][2]uint8, 2)},

encode_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ func (f *fakeExt) UnmarshalJSON(data []byte) error {
676676
}
677677

678678
func TestExtensions_UnmarshalJSON(t *testing.T) {
679-
RegisterExtension("fake_ext", func(data []byte) (interface{}, error) {
679+
RegisterExtension("fake_ext", func(data []byte) (any, error) {
680680
e := new(fakeExt)
681681
err := json.Unmarshal(data, e)
682682
return e, err

ext/lightspuntual/lightspuntual.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type envelop struct {
2525
}
2626

2727
// Unmarshal decodes the json data into the correct type.
28-
func Unmarshal(data []byte) (interface{}, error) {
28+
func Unmarshal(data []byte) (any, error) {
2929
var env envelop
3030
if err := json.Unmarshal([]byte(data), &env); err != nil {
3131
return nil, err

ext/lightspuntual/lightspuntual_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestUnmarshal(t *testing.T) {
114114
tests := []struct {
115115
name string
116116
args args
117-
want interface{}
117+
want any
118118
wantErr bool
119119
}{
120120
{"error", args{[]byte(`{"light: 1}`)}, nil, true},

ext/specular/specular.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const (
1313
)
1414

1515
// Unmarshal decodes the json data into the correct type.
16-
func Unmarshal(data []byte) (interface{}, error) {
16+
func Unmarshal(data []byte) (any, error) {
1717
pbr := new(PBRSpecularGlossiness)
1818
err := json.Unmarshal(data, pbr)
1919
return pbr, err

0 commit comments

Comments
 (0)