[AbiCoder] Provide coerceFunc for encode / Writer
#1950
silasdavis
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
The
coerceFuncprovides a useful visitor pattern for transforming how values are returned from adecode. Its utility lies in the factAbiCoderknows how to walk the tree of type definitions so you can decide how to format a value based on the primitive type in a nested array or tuple.However there is no corresponding facility on the
decodeside, but the same functionality would be useful. For example I have code like:These functions are crude though because they don't actually understand compound/complex types. They match using a regular expression then have a best effort attempt at converting recursively but they cannot handle mixed types in tuples.
The latter function could be replaced by the existing
coerceFunc, but I cannot replace the first in the same way.Describe the solution you'd like
For symmetry it would be nice to have
new AbiCoder({ coerce?: { encode?: CoerceFunc, decode?: CoerceFunc }), whereby you can supply a coerce function that is run before encoding a value in a similar way to which existing coerce functions runs after decoding a value.Describe alternatives you've considered
See regex hack above. Also not needing to coerce before encoding, but I am dealing with types from a separate GRPC schema that gives types that are in a difference schema.
Additional context
It would be nice to have access to parsed out elements of a type (for
CoerceFuncand more generally). For examplebitWidthandlength, e.g. for the typebytes16[4]you would have16and4. Then I wouldn't have to dirty my hands with string parsing at all ;-)See #915 for original motivation for
coerceFuncBeta Was this translation helpful? Give feedback.
All reactions