Skip to content

Commit

Permalink
Add any support
Browse files Browse the repository at this point in the history
Signed-off-by: Janusz Marcinkiewicz <[email protected]>
  • Loading branch information
VirrageS committed Jul 1, 2024
1 parent c029b2c commit 4a556cb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
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
43 changes: 28 additions & 15 deletions tinygotest/testdata/roundtrip/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"fmt"

"github.com/tinylib/msgp/msgp"
)
Expand All @@ -19,21 +20,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 +47,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 +73,14 @@ func (e *Example) Setup() {
}

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

0 comments on commit 4a556cb

Please sign in to comment.