You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the project initially started, Tinygo's support for reflection was very limited. Therefore, using types that implemented a specific interface with an 'Encode()' method did not require extensive reliance on reflection calls. Thus, instead of using the built-in types (bool, uint8, ..., structs, arrays, slices, and maps), wrapper types were introduced to satisfy the interface.
Currently, there is a helper function 'EncodeEach()' that relies on an Encode() method and interface, which simply calls each field's Encode() method.
Pros:
Does not require extensive reflection calls.
Works for custom-defined types.
Ensures type safety (requires the Encode() method to be implemented for each field).
Cons:
Not idiomatic (requires wrapper types); does not work for built-in types.
Cannot differentiate properly between arrays and slices (both are encoded as slices).
There are different approaches that may allow switching to Go built-in types instead of the wrapper types. Here are some of the most convenient ones:
A. Fork Gossamer's Scale Codec
Make the necessary changes to eliminate the need for certain unsupported reflection calls, see #210.
B. Refactor Our Goscale Codec
Use the helper function 'EncodeEach()', which relies on an encoding function for built-in types and on an interface and encode method for custom-defined types.
Research if we can remove the wrapper types and instead, switch to the built-in Go types, which is more idiomatic.
The text was updated successfully, but these errors were encountered: