Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add any support #350

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gen/elem.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ var primitives = map[string]Primitive{
"int64": Int64,
"bool": Bool,
"interface{}": Intf,
"any": Intf,
"time.Time": Time,
"time.Duration": Duration,
"msgp.Extension": Ext,
Expand Down
2 changes: 1 addition & 1 deletion msgp/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ func (m *Reader) ReadTime() (t time.Time, err error) {
return
}

// ReadIntf reads out the next object as a raw interface{}.
// ReadIntf reads out the next object as a raw interface{}/any.
// Arrays are decoded as []interface{}, and maps are decoded
// as map[string]interface{}. Integers are decoded as int64
// and unsigned integers are decoded as uint64.
Expand Down
40 changes: 25 additions & 15 deletions tinygotest/testdata/roundtrip/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@ type EmbeddedStruct struct {
// Example provides a decent variety of types and features and
// lets us test for basic functionality in TinyGo.
type Example struct {
Int64 int64 `msg:"int64"`
Uint64 uint64 `msg:"uint64"`
Int32 int32 `msg:"int32"`
Uint32 uint32 `msg:"uint32"`
Int16 int32 `msg:"int16"`
Uint16 uint32 `msg:"uint16"`
Int8 int32 `msg:"int8"`
Byte byte `msg:"byte"`
Float64 float64 `msg:"float64"`
Float32 float32 `msg:"float32"`
String string `msg:"string"`
ByteSlice []byte `msg:"byte_slice"`
StringSlice []string `msg:"string_slice"`
IntArray [2]int `msg:"int_array"`
SomeStruct SomeStruct `msg:"some_struct"`
Interface interface{} `msg:"interface"`
Any any `msg:"any"`
Int64 int64 `msg:"int64"`
Uint64 uint64 `msg:"uint64"`
Int32 int32 `msg:"int32"`
Uint32 uint32 `msg:"uint32"`
Int16 int32 `msg:"int16"`
Uint16 uint32 `msg:"uint16"`
Int8 int32 `msg:"int8"`
Byte byte `msg:"byte"`
Float64 float64 `msg:"float64"`
Float32 float32 `msg:"float32"`
String string `msg:"string"`
ByteSlice []byte `msg:"byte_slice"`
StringSlice []string `msg:"string_slice"`
IntArray [2]int `msg:"int_array"`
SomeStruct SomeStruct `msg:"some_struct"`

EmbeddedStruct

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

// Setup populuates the struct with test data
func (e *Example) Setup() {
e.Interface = 10
e.Any = "any"
e.Int64 = 10
e.Uint64 = 11
e.Int32 = 12
Expand All @@ -68,6 +72,12 @@ func (e *Example) Setup() {
}

func (e *Example) Eq(e2 *Example) bool {
if int64(e.Interface.(int)) != e2.Interface.(int64) {
return false
}
if e.Any.(string) != e2.Any.(string) {
return false
}
if e.Int64 != e2.Int64 {
return false
}
Expand Down
Loading