poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: JSON Representation


From: Konstantinos Chasialis
Subject: Re: JSON Representation
Date: Thu, 7 May 2020 22:11:52 +0300
User-agent: SquirrelMail/1.4.23 [email.uoa.gr]

>
>     > Hi kostasch!
>     > Thanks for the update.
>     >
>
>     I believe that I can represent everything you just suggested.
>
>     At first I wasn't sure if my approach for magnitude was correct.
>
>     I mean, what I wanted to represent is that magnitude is an integer
>     (not float for example) but not just any integer, either Integer or
>     UnsignedInteger.
>
>     I think the right way to represent this is by saying that its type is
> a
>     JSON Object and can be oneOf {UnsignedInteger, Integer}.
>
> Sounds like right! :)
>
>

Author: kostasch <address@hidden>
Date:   Thu May 7 22:05:26 2020 +0300

    Changes to json representation

 libpoke/pvm-val.json | 287
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------
 1 file changed, 206 insertions(+), 81 deletions(-)


Hello, I added more stuff to our JSON representation and also run some
validation tests to make sure that things that should not be allowed are
not allowed (e.g. "stringValue" : 5).

Tell me what you think about this representation :).


diff --git a/libpoke/pvm-val.json b/libpoke/pvm-val.json
index b7ea3633..9cda2266 100644
--- a/libpoke/pvm-val.json
+++ b/libpoke/pvm-val.json
@@ -1,89 +1,214 @@
 {
-    "$schema": "http://json-schema.org/draft-06/schema#";,
-    "$id": "",
-    "title" : "Poke values",
-    "description" : "JSON Representation for Poke values",
-    "definitions" : {
-       "UnsignedInteger" : {
-               "type" : "object",
-               "properties" : {
-                       "value" : {
-                               "type" : "integer",
-                               "minimum" : 0
-                       },
-                       "size" : {
-                               "type" : "UnsignedInteger",
-                               "maximum" : 4294967295
-                       }
-               },
-            "required": [
-                "size",
-                "value"
-            ],
-            "title": "UnsignedInteger"
-       },
-        "Integer": {
-            "type": "object",
-            "properties": {
-                "value": {
-                    "type": "integer"
-                },
-                "size" : {
-                       "type" : "UnsignedInteger",
-                       "maximum" : 4294967295
-                }
-
-            },
-            "required": [
-                "size",
-                "value"
-            ],
-            "title": "Integer"
+  "$schema": "http://json-schema.org/draft-06/schema#";,
+  "$id": "",
+  "title": "Poke values",
+  "description": "JSON Representation for Poke values",
+  "definitions": {
+    "UnsignedInteger": {
+      "type": "object",
+      "properties": {
+        "unsignedValue": {
+          "type": "integer",
+          "minimum": 0,
+          "maximum": 18446744073709551615
         },
-        "Null": {
-            "type": "object",
-            "properties": {
-                "nullValue": {
-                    "type": "null"
-                }
-            },
-            "required": [
-                "nullValue"
-            ],
-            "title": "Null"
+        "size": {
+          "type": "integer",
+          "minimum": 1,
+          "maximum": 64
+        }
+      },
+      "required": [
+        "size",
+        "unsignedValue"
+      ],
+      "title": "UnsignedInteger"
+    },
+    "Integer": {
+      "type": "object",
+      "properties": {
+        "signedValue": {
+          "type": "integer",
+          "minimum": -9223372036854775808,
+          "maximum": 9223372036854775807
         },
-        "Offset": {
-            "type": "object",
-            "properties": {
-                "magnitude": {
-                    "type": "integer",
-                    "oneOf" : [
-                       {"type" : "UnsignedInteger"},
-                       {"type" : "Integer"}
-                    ]
-                },
-                "base": {
-                    "type": "UnsignedInteger",
-                    "maximum" : 9223372036854775807
-                }
+        "size": {
+          "type": "integer",
+          "minimum": 1,
+          "maximum": 64
+        }
+      },
+      "required": [
+        "size",
+        "signedValue"
+      ],
+      "title": "Integer"
+    },
+    "Null": {
+      "type": "object",
+      "properties": {
+        "nullValue": {
+          "type": "null"
+        }
+      },
+      "required": [
+        "nullValue"
+      ],
+      "title": "Null"
+    },
+    "Offset": {
+      "type": "object",
+      "properties": {
+        "magnitude": {
+          "type": "object",
+          "anyOf": [
+            {
+              "$ref": "#/definitions/UnsignedInteger"
             },
-            "required": [
-                "magnitude",
-                "base"
-            ],
-            "title": "Offset"
+            {
+              "$ref": "#/definitions/Integer"
+            }
+          ]
         },
-        "String": {
-            "type": "object",
-            "properties": {
-                "value": {
-                    "type": "string"
-                }
+        "base": {
+          "type": "object",
+          "oneOf": [
+            {
+              "$ref": "#/definitions/UnsignedInteger"
+            }
+          ],
+          "size": 64
+        }
+      },
+      "required": [
+        "magnitude",
+        "base"
+      ],
+      "title": "Offset"
+    },
+    "String": {
+      "type": "object",
+      "properties": {
+        "stringValue": {
+          "type": "string"
+        }
+      },
+      "required": [
+        "stringValue"
+      ],
+      "title": "String"
+    },
+    /*(Not sure about this one)
+         Represent poke struct as an object a number of fields plus a Mapping
+    */
+    "Struct": {
+      "type":"object",
+      "properties":{
+        "structFields": {
+          "type" : "array",
+          "items" : {
+            "type" : "object",
+            "anyOf" : [
+              {"$ref": "#/definitions/String"},
+              {"$ref": "#/definitions/Struct"},
+              {"$ref": "#/definitions/Array"},
+              {"$ref": "#/definitions/UnsignedInteger"},
+              {"$ref": "#/definitions/Integer"},
+              {"$ref": "#/definitions/Offset"}
+            ]
+          },
+          "default" : {
+               "type" : "object",
+            "$ref" : "#/definitions/Null"
+          }
+        }
+      },
+      /*Optionally, add a mapping after defining the struct*/
+      "additionalProperties": {
+        "type" : "object",
+        "$ref" : "#/definitions/Mapping"
+      },
+      "required": [
+        "structFields"
+      ],
+      "title": "Struct"
+    },
+    "Mapping": {
+      "type": "object",
+      "properties": {
+        "IOS": {
+          "type": "integer"
+        },
+        "offset": {
+          "type": "object",
+          "$ref": "#/definitions/Offset"
+        }
+      },
+      "required": [
+        "IOS",
+        "offset"
+      ],
+      "title": "Mapping"
+    },
+    "Array": {
+      "type" : "object",
+      "properties" : {
+       /*arrayItems is an array of all defined objects above, except
Mapping which is added at the end*/
+        "arrayItems" : {
+            "type": "array",
+            "items": {
+              "type": "object",
+              "anyOf" : [
+                {"$ref": "#/definitions/String"},
+                {"$ref": "#/definitions/Struct"},
+                {"$ref": "#/definitions/Array"},
+                {"$ref": "#/definitions/UnsignedInteger"},
+                {"$ref": "#/definitions/Integer"},
+                {"$ref": "#/definitions/Offset"}
+              ]
             },
-            "required": [
-                "value"
-            ],
-            "title": "String"
+            "default" : {
+               "type" : "object",
+               "$ref": "#/definitions/Null"
+            }
         }
-       }
+      },
+      /*Optionally, add a mapping after defining the array*/
+      "additionalProperties": {
+        "type": "object",
+        "$ref": "#/definitions/Mapping"
+      },
+      "required" : [
+       "arrayItems"
+      ]
+    }
+  },
+  "type": "object",
+  "properties": {
+    "UnsignedInteger": {
+      "$ref": "#/definitions/UnsignedInteger"
+    },
+    "Integer": {
+      "$ref": "#/definitions/Integer"
+    },
+    "Offset": {
+      "$ref": "#/definitions/Offset"
+    },
+    "String": {
+      "$ref": "#/definitions/String"
+    },
+    "Mapping": {
+      "$ref": "#/definitions/Mapping"
+    },
+    "Null": {
+      "$ref": "#/definitions/Null"
+    },
+    "Struct": {
+      "$ref": "#/definitions/Struct"
+    },
+    "Array": {
+      "$ref": "#/definitions/Array"
+    }
+  },
+  "additionalProperties": false





reply via email to

[Prev in Thread] Current Thread [Next in Thread]