Closed caiorcferreira closed 7 months ago
I think it would be sensible to do this along with exposing newIPAddr. I think these names would be fairly Go-idiomatic:
ParseDecimal
and ParseIPAddr
If you want to make a PR, that would be great!
Thanks! -Phil
Description:
The
cedar-go
library uses anint64
data type to represent decimal values, necessitating specific conversion logic to translate string representations of decimals into their numeric counterparts. Currently, this conversion is only accessible through theDecimal.UnmarshalJSON
method.In practice, this implementation poses limitations, especially when integrating with systems that do not use JSON for serialization, such as gRPC. For instance, when receiving data in formats other than the expected JSON structure (
{"__extn": {"fn": "decimal", "arg": "12.5"}}
), there is no straightforward way to utilizecedar-go
's conversion logic directly.To enhance flexibility and usability, I propose making the
newDecimalValue
function publicly accessible. This change would allow developers to directly convert a decimal string like"12.5"
into thecedar.Decimal
format (e.g.,cedar.Decimal(125000)
) without dealing with JSON-specific constraints.Such an enhancement would greatly benefit those of us integrating
cedar-go
with various RPC frameworks and would streamline the handling of decimal data across different platforms.Impact:
cedar-go
more versatile and easier to integrate with non-JSON based systems.Proposed Solution:
Expose the
newDecimalValue
function as a public method, thereby extending the utility of thecedar-go
library to handle decimal conversions more flexibly.