Code Monkey home page Code Monkey logo

Comments (2)

talkol avatar talkol commented on July 18, 2024

I see two use cases:

  1. Developer wants to store complex struct in state and then load it

  2. Developer wants to receive complex struct as argument or return it in the result

I think (1) is more important

This should be implemented using a serialization library of some sort as part of the contract SDK

There are 3 main serialization candidates, we can support all 3:

  1. JSON - developers understand it and like it, although some fuzziness regarding encoding of types like byte arrays, bigints and so forth. JSON doesn't have a good type schema, it's self descriptive with few types. JSON is also very wasteful and results in much larger state than needed (due to being textual for example).

  2. membuffers - it's already a format we use for the Orbs protocol. The difficulty here is where to advertise the schemas. We can use reflection to do encoding/decoding and "understand" the schema from the provided type but this will have a performance penalty. Working without schema will make the API for developers very boilerplaty and hard to read.

  3. Ethereum serialization protocol - will be nice to support it just for compatibility anyways. But it does rely on reflection to its performance is so so.

from orbs-contract-sdk.

talkol avatar talkol commented on July 18, 2024

From a product perspective, what do you say about API like this:

type Person struct {
    Name string
    Age uint32
}

func someFunc() {

schema := "{Name: string, Age: uint32}"

var p Person
person := serializer.Decode(bytes, &p)

bytes := serializer.Encode(p)

The benefit here is that we have clearer expression of the schema for working across languages.. This is very similar to ABI btw.. so maybe just using Ethereum's approach would be good here and no need to do our own

from orbs-contract-sdk.

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.