Coder Social home page Coder Social logo

Support Compact types about scale-info HOT 2 CLOSED

ascjones avatar ascjones commented on July 26, 2024
Support Compact types

from scale-info.

Comments (2)

Robbepop avatar Robbepop commented on July 26, 2024

Let me quickly concretize what those 3 different approaches could look like:

Examples

Following are 3 scale-info encoded JSON example showing a composite type:

pub struct Foo(Compact<i32>);

Using a built-in scale-info compact type:

{
    "strings": [
        "Foo", # ID 1
    ],
    "types": [
        { # ID 1
            "compact": 2
        },
        { # ID 2
            "primitive": "i32"
        },
        { # ID 3
            "composite": {
                "path": [ 1 ],
                "fields": [
                    { "type": 1 }
                ]
            }
        }
    ]
}

Using a built-in flag for compact types:

{
    "strings": [
        "Foo", # ID 1
    ],
    "types": [
        { # ID 1
            "primitive": "i32"
        },
        { # ID 2
            "composite": {
                "path": [ 1 ],
                "fields": [
                    { "type": 1, "compact": true }
                ]
            }
        }
    ]
}

Using a special custom type for compact types: (Taking the one from scale library)

{
    "strings": [
        "scale",   # ID 1
        "Compact", # ID 2
        "T",       # ID 3
        "Foo",     # ID 4
    ],
    "types": [
        { # ID 1
            "primitive": "i32"
        },
        { # ID 2
            "composite": {
                "path": [ 1, 2 ],
                "params": [ 3 ],
                "fields": [
                    {
                        "type": {
                            "parameter": 3
                        }
                    }
                ]
            }
        },
        { # ID 3
            "composite": {
                "path": [ 4 ],
                "fields": [
                    {
                        "type": {
                            "generic": {
                                "type": 2,
                                "params": [ 1 ],
                            }
                        }
                    }
                ]
            }
        }
    ]
}

from scale-info.

Robbepop avatar Robbepop commented on July 26, 2024

I am leaning towards the last example even though it seems to be the most convoluted solution because it plays nice with our other proposal for generics support (#6) and does not introduce yet another concept for the protocol but uses what is already there. Also due to the design of the generics proposal there will be at most one Compact type definition per metadata so it won't be as convoluted at scale.

from scale-info.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.