-
Notifications
You must be signed in to change notification settings - Fork 279
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
refactor: encode JsonString as object in scale #5084
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not much to say, I'm not really into this change, but I'll approve if people think this is the way
"JsonString": { | ||
"Enum": [ | ||
{ | ||
"tag": "Null", | ||
"discriminant": 0 | ||
}, | ||
{ | ||
"tag": "String", | ||
"discriminant": 1, | ||
"type": "String" | ||
}, | ||
{ | ||
"tag": "Bool", | ||
"discriminant": 2, | ||
"type": "bool" | ||
}, | ||
{ | ||
"tag": "Array", | ||
"discriminant": 3, | ||
"type": "Vec<JsonString>" | ||
}, | ||
{ | ||
"tag": "Number", | ||
"discriminant": 4, | ||
"type": "String" | ||
}, | ||
{ | ||
"tag": "Object", | ||
"discriminant": 5, | ||
"type": "SortedMap<String, JsonString>" | ||
} | ||
] | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"JsonString": { | |
"Enum": [ | |
{ | |
"tag": "Null", | |
"discriminant": 0 | |
}, | |
{ | |
"tag": "String", | |
"discriminant": 1, | |
"type": "String" | |
}, | |
{ | |
"tag": "Bool", | |
"discriminant": 2, | |
"type": "bool" | |
}, | |
{ | |
"tag": "Array", | |
"discriminant": 3, | |
"type": "Vec<JsonString>" | |
}, | |
{ | |
"tag": "Number", | |
"discriminant": 4, | |
"type": "String" | |
}, | |
{ | |
"tag": "Object", | |
"discriminant": 5, | |
"type": "SortedMap<String, JsonString>" | |
} | |
] | |
}, | |
"JsonValue: "JsonValue" |
There was an idea that we can introduce a new json
type into schema. It would be up to the sdk to know how to handle this type like it is for Option<T>
or Vec<T>
. What happened with this suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not aware of this idea.
I think the main difference is that Vec and Option has native representation in scale and json doesn't.
#[display(fmt = "{_0}")] | ||
pub struct JsonString(String); | ||
#[serde(transparent)] | ||
pub struct JsonString(Value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct JsonString(Value); | |
pub struct JsonValue(Value); |
if we're to proceed with this change we'll have to rename it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, made a draft with minimal changes
2e95196
to
f64ca4e
Compare
Signed-off-by: Shanin Roman <[email protected]>
f64ca4e
to
5e6935c
Compare
Context
Aim to close differences between
scale
andjson
by encodingJsonString
as enum in scale and not justString
.Closes #5024
Solution
Approach is to manually implement encode and decode for
JsonString
and describe it in schema.Review notes
I am not sure that this will help since there is anyway not 1 to 1 mapping between
scale
andjson
.And in the
json
we still expect arbitrary json object and not smt encoded using schema...