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

xchg::Explicit tagging doesn't make "0.99" roundtrip when decimal precision is 1 #9

Open
catb0t opened this issue Oct 5, 2019 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@catb0t
Copy link
Owner

catb0t commented Oct 5, 2019

$ sidef -P1 tests/06_xchg_tagging.sf 
{
   "l" : {
      "__XT" : "!B!Array.Array",
      "__XS" : "!B!String.String",
      "__XV" : [
         {
            "__XV" : "0.99"
         },
         {
            "__XV" : "1.0123123123123123123123"
         }
      ]
   },
   ...
}

Hash(
    "l" => Hash(
        "__XS" => "!B!String.String",
        "__XT" => "!B!Array.Array",
        "__XV" => [Hash("__XV" => 99/100), Hash("__XV" => 10123123123123123123123/10000000000000000000000)]
    ),
    ...
)
assert_eq(Hash(
    "l" => ["1e0", "1e0"],
    ...
), Hash(
    "l" => ["0.99", "1.0123123123123123123123"],
    ...
)) failed at tests/06_xchg_tagging.sf line 94
@catb0t catb0t added the bug Something isn't working label Oct 5, 2019
@catb0t catb0t added this to the 0.3 milestone Oct 5, 2019
@catb0t catb0t self-assigned this Oct 5, 2019
@catb0t
Copy link
Owner Author

catb0t commented Oct 5, 2019

there are two options to fix this with JSON::{XS,PP}'s allow_tags and FREEZE/THAW (which are the only solution short of a new JSON parser in Sidef)

  1. Alias FREEZE to ABCs::Serializable.serialize and THAW to ABCs::Serializable.unserialize, in the definition of Serializable, much simpler

  2. Add another layer of wrapping to Explicit::tag_hash / untag_hash, which uses a special class TagObject { has val; has type; has subtype; -> FREEZE {} -> THAW {} }, so that all inputs to tag_hash / untag_hash are first genericised to TagObject, which is then given to JSON::XS.allow_tags, a solution which keeps all JSON-related implementaion details out of ABCs::Serializable

There is quite a large problem still, which is that relying on allow_tags means the database JSON will not be standard syntax (("classname")[objects...])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant