Skip to content

Commit 6fad7b0

Browse files
authored
Add any support (#350)
Signed-off-by: Janusz Marcinkiewicz <januszm@nvidia.com>
1 parent c029b2c commit 6fad7b0

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

‎gen/elem.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ var primitives = map[string]Primitive{
119119
"int64": Int64,
120120
"bool": Bool,
121121
"interface{}": Intf,
122+
"any": Intf,
122123
"time.Time": Time,
123124
"time.Duration": Duration,
124125
"msgp.Extension": Ext,

‎msgp/read.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ func (m *Reader) ReadTime() (t time.Time, err error) {
12661266
return
12671267
}
12681268

1269-
// ReadIntf reads out the next object as a raw interface{}.
1269+
// ReadIntf reads out the next object as a raw interface{}/any.
12701270
// Arrays are decoded as []interface{}, and maps are decoded
12711271
// as map[string]interface{}. Integers are decoded as int64
12721272
// and unsigned integers are decoded as uint64.

‎tinygotest/testdata/roundtrip/main.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,23 @@ type EmbeddedStruct struct {
1919
// Example provides a decent variety of types and features and
2020
// lets us test for basic functionality in TinyGo.
2121
type Example struct {
22-
Int64 int64 `msg:"int64"`
23-
Uint64 uint64 `msg:"uint64"`
24-
Int32 int32 `msg:"int32"`
25-
Uint32 uint32 `msg:"uint32"`
26-
Int16 int32 `msg:"int16"`
27-
Uint16 uint32 `msg:"uint16"`
28-
Int8 int32 `msg:"int8"`
29-
Byte byte `msg:"byte"`
30-
Float64 float64 `msg:"float64"`
31-
Float32 float32 `msg:"float32"`
32-
String string `msg:"string"`
33-
ByteSlice []byte `msg:"byte_slice"`
34-
StringSlice []string `msg:"string_slice"`
35-
IntArray [2]int `msg:"int_array"`
36-
SomeStruct SomeStruct `msg:"some_struct"`
22+
Interface interface{} `msg:"interface"`
23+
Any any `msg:"any"`
24+
Int64 int64 `msg:"int64"`
25+
Uint64 uint64 `msg:"uint64"`
26+
Int32 int32 `msg:"int32"`
27+
Uint32 uint32 `msg:"uint32"`
28+
Int16 int32 `msg:"int16"`
29+
Uint16 uint32 `msg:"uint16"`
30+
Int8 int32 `msg:"int8"`
31+
Byte byte `msg:"byte"`
32+
Float64 float64 `msg:"float64"`
33+
Float32 float32 `msg:"float32"`
34+
String string `msg:"string"`
35+
ByteSlice []byte `msg:"byte_slice"`
36+
StringSlice []string `msg:"string_slice"`
37+
IntArray [2]int `msg:"int_array"`
38+
SomeStruct SomeStruct `msg:"some_struct"`
3739

3840
EmbeddedStruct
3941

@@ -44,6 +46,8 @@ type Example struct {
4446

4547
// Setup populuates the struct with test data
4648
func (e *Example) Setup() {
49+
e.Interface = 10
50+
e.Any = "any"
4751
e.Int64 = 10
4852
e.Uint64 = 11
4953
e.Int32 = 12
@@ -68,6 +72,12 @@ func (e *Example) Setup() {
6872
}
6973

7074
func (e *Example) Eq(e2 *Example) bool {
75+
if int64(e.Interface.(int)) != e2.Interface.(int64) {
76+
return false
77+
}
78+
if e.Any.(string) != e2.Any.(string) {
79+
return false
80+
}
7181
if e.Int64 != e2.Int64 {
7282
return false
7383
}

0 commit comments

Comments
 (0)