From 960e40c3581fb3cf379d6136641f70f15a1eedb4 Mon Sep 17 00:00:00 2001 From: Alexander Ivanov Date: Tue, 10 Mar 2020 15:04:21 +0800 Subject: [PATCH 1/2] Rewritten documentation * Added protocol example * Moved bool/cstring/void to primitive type * Added "lvarint" and "int" numeric types * Formatted schemas --- README.md | 3 + doc/datatypes.md | 313 +++-------------------------------- doc/datatypes/conditional.md | 49 ++++++ doc/datatypes/numeric.md | 41 +++++ doc/datatypes/primitives.md | 22 +++ doc/datatypes/structures.md | 62 +++++++ doc/datatypes/utils.md | 86 ++++++++++ doc/protocol.md | 34 +++- schemas/conditional.json | 52 +++--- schemas/datatype.json | 76 +++++---- schemas/definitions.json | 4 +- schemas/numeric.json | 136 ++++++++++++--- schemas/primitives.json | 11 ++ schemas/protocol_schema.json | 32 +++- schemas/structures.json | 76 +++++---- schemas/utils.json | 114 +++++++------ 16 files changed, 645 insertions(+), 466 deletions(-) create mode 100644 doc/datatypes/conditional.md create mode 100644 doc/datatypes/numeric.md create mode 100644 doc/datatypes/primitives.md create mode 100644 doc/datatypes/structures.md create mode 100644 doc/datatypes/utils.md create mode 100644 schemas/primitives.json diff --git a/README.md b/README.md index 2a10864..aa27cb0 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ ProtoDef specification: describe your protocol, and read it with ease. | --- | --- | --- | | [node-protodef](https://github.com/ProtoDef-io/node-protodef) | Node.js | interpretation | | [elixir-protodef](https://github.com/ProtoDef-io/elixir-protodef) | Elixir | compilation | +| [protodefc](https://github.com/ProtoDef-io/protodefc) | Rust | compilation | + + ## Documentation diff --git a/doc/datatypes.md b/doc/datatypes.md index e48cb9f..a8f5a6f 100644 --- a/doc/datatypes.md +++ b/doc/datatypes.md @@ -1,292 +1,21 @@ -# Datatypes - -Protodef has a number of useful default datatypes. - -## Conditional - -### switch - -switch make it possible to choose a datatype depending on the value of an other field. -It is similar to the switch/case syntax. -It takes 3 arguments: - -* compareTo : the value is the other field -* compareToValue : an optional property (it's either compareTo or compareToValue) that allows the comparison to be made with a value instead of an other field -* fields : an object mapping the values to the types -* default : an optional property saying the type taken if the value doesn't fit into the cases - -Example: - -A switch which can encode a byte, a varint, a float or a string depending on "someField". -If the value of someField is different, then the value encoded is of type void. - -```json -[ - "switch", - { - "compareTo": "someField", - "fields": { - "0": "i8", - "1": "varint", - "2": "f32", - "3": "string" - }, - "default": "void" - } -] -``` - -Example of value: `4.5` - -### option - -option represents a simple optional type. It's encoded as a boolean indicating whether the value is there or not. -It's similar to the Optional type in java or Maybe in haskell. -It takes only one argument : the type of the value. - -Example: - -An option of value string - -```json -[ - "option", - "cstring" -] -``` - -Example of value: `"my string"` - -## Numeric - -These datatypes don't take any arguments. They represent numbers. - -| Name | Size in bytes | Example of value | Also called | -| --- | --- | --- | --- | -| i8 | 1 | -125 | byte | -| u8 | 1 | 255 | unsigned byte | -| i16 | 2 | -32000 | short | -| u16 | 2 | 60000 | unsigned short | -| i32 | 4 | -2000000000 | int | -| u32 | 4 | 3000000000 | unsigned int | -| f32 | 4 | 4.5 | float | -| f64 | 8 | 4.5 | double | -| i64 | 8 | 1 | long | -| u64 | 8 | 1 | unsigned long | -| li8 | 1 | -125 | little endian byte | -| lu8 | 1 | 255 | little endian unsigned byte | -| li16 | 2 | -32000 | little endian short | -| lu16 | 2 | 60000 | little endian unsigned short | -| li32 | 4 | -2000000000 | little endian int | -| lu32 | 4 | 3000000000 | little endian unsigned int | -| lf32 | 4 | 4.5 | little endian float | -| lf64 | 8 | 4.5 | little endian double | -| li64 | 8 | 1 | little endian long | -| lu64 | 8 | 1 | little endian unsigned long | - -## Structures - -### array - -array represents a list of values. - -It takes for arguments: - -* type : the type of the element -* countType : the type of the length prefix -* count : optional (either count or countType), a reference to the field counting the elements, or a fixed size (an integer) - -See [Counting](#counting) - -Example: - -An array of int prefixed by a short length. -```json -[ - "array", - { - "countType": "i16", - "type": "i32" - } -] -``` - -Example of value: `[1,2,3,4]` - -### count - -It represents a count field for an array or a buffer. - -Example: - -A count for a field name records, of type short. -```json -[ - "count", - { - "type": "i16", - "countFor": "records" - } -] -``` - -Example of value: `5` - -### container - -It represents a list of named values. It takes for argument these values with their types and names. - -Example: - -A container with fields of type int, int, ushort and ushort. -```json -[ - "container", - [ - { - "name": "x", - "type": "i32" - }, - { - "name": "z", - "type": "i32" - }, - { - "name": "bitMap", - "type": "u16" - }, - { - "name": "addBitMap", - "type": "u16" - } - ] -] -``` - -Example of value: `{"x":10,"z":10,"bitMap":10,"addBitMap":10}` - -## Utils - -### varint - -A variable-length number representation. - -Size: between 1 and 5 - -Example of value : `5` - -### bool - -A boolean, encoded in one byte. - -Example of value : `true` - -### pstring - -A length prefixed string. It takes one argument : the type of the length prefix. -It is usually used to define a "string" type that can be used without argument. - -The count can also be defined in different ways, see [Counting](#counting). - -Example: - -A string length prefixed by a varint. -```json -[ - "pstring",{ - "countType":"varint" - } -] -``` - -Example of value: `"my string"` - -### buffer - -buffer represents a Buffer - -It takes for arguments: - -* countType : the type of the length prefix -* count : optional (either count or countType), a reference to the field counting the elements, or a fixed size (an integer) - -See [Counting](#counting) - -Example: - -An buffer prefixed by a varint length. -```json -[ - "buffer", - { - "countType": "varint" - } -] -``` - -Example of value: `new Buffer([0x01,0x02,0x03])` - -### void - -void represents an empty value. It has a size of 0. - -Example of value: `undefined` - -### bitfield - -bitfield represents a list of value with sizes that are not a multiple of 8bits. -It takes for argument a list of values with: -* a size -* a name -* signed -The sum of the sizes must be a multiple of 8. - -Example: - -3 values, x, y and z with sizes in bits : 26, 12, 26. Notice that 26+12+26=64. -```json -["bitfield", [ - { "name": "x", "size": 26, "signed": true }, - { "name": "y", "size": 12, "signed": true }, - { "name": "z", "size": 26, "signed": true } - ]] -``` - -Example of value: `{"x":10,"y":10,"z":10}` - -### cstring - -cstring represents a null terminated string. Similar to strings in C. - -Example of value: "my string" - -### mapper - -mappers maps values. It takes as argument the type of the input, and a mappings object with the values to map. - -Example: - -Maps a byte to a string, 1 to "byte", 2 to "short", 3 to "int", 4 to "long". -```json -[ - "mapper", - { - "type": "i8", - "mappings": { - "1": "byte", - "2": "short", - "3": "int", - "4": "long" - } - } -] -``` - -Example of value: `3` - -# Common datatypes arguments - -## Counting - -* countType : the type of the length prefix -* count : optional (either count or countType), a reference to the field counting the elements, or a fixed size (an integer) +# Datatypes reference +* [Conditional](./datatypes/conditional.md) +* * [switch](./datatypes/conditional.md#) +* * [option](./datatypes/conditional.md#) +* [Numeric](./datatypes/numeric.md) +* * [i8 / u8 / i16 / u16 / i32 / u32 / i64 / u64 / f32 / f64](./datatypes/numeric.md) +* * [int](./datatypes/numeric.md) +* * [varint](./datatypes/numeric.md) +* [Structures](./datatypes/structures.md) +* * [array](./datatypes/structures.md) +* * [container](./datatypes/structures.md) +* * [count](./datatypes/structures.md) +* [Primitives](./datatypes/primitives.md) +* * [bool](./datatypes/primitives.md) +* * [cstring](./datatypes/primitives.md) +* * [void](./datatypes/primitives.md) +* [Utils](./datatypes/utils.md) +* * [buffer](./datatypes/utils.md) +* * [bitfield](./datatypes/utils.md) +* * [mapper](./datatypes/utils.md) +* * [pstring](./datatypes/utils.md) \ No newline at end of file diff --git a/doc/datatypes/conditional.md b/doc/datatypes/conditional.md new file mode 100644 index 0000000..92f47d3 --- /dev/null +++ b/doc/datatypes/conditional.md @@ -0,0 +1,49 @@ +## Conditional + +### **switch** ({ compareTo: Field, ?compareToValue: Any, fields: { [String]: Any, ... }, ?default: String }) +Arguments: +* compareTo : the value is the other field +* compareToValue : an optional property (it's either compareTo or compareToValue) that allows the comparison to be made with a value instead of an other field +* fields : an object mapping the values to the types +* default : an optional property saying the type taken if the value doesn't fit into the cases + +switch make it possible to choose a datatype depending on the value of an other field. +It is similar to the switch/case syntax. + +Example: + +A switch which can encode a byte, a varint, a float or a string depending on "someField". +If the value of someField is different, then the value encoded is of type void. +```json +[ + "switch", + { + "compareTo": "someField", + "fields": { + "0": "i8", + "1": "varint", + "2": "f32", + "3": "string" + }, + "default": "void" + } +] +``` +Example of value: `4.5` + +### **option** ( Type ) +Arguments: +* [Type] : the type of the value + +Represents a simple optional type. +It's encoded as a boolean indicating whether the value is there or not. +It's similar to the `Optional` type in java or `Maybe` in haskell. + +Example: An option of value string +```json +[ + "option", + "cstring" +] +``` +Example of value: `"my string"` diff --git a/doc/datatypes/numeric.md b/doc/datatypes/numeric.md new file mode 100644 index 0000000..5280087 --- /dev/null +++ b/doc/datatypes/numeric.md @@ -0,0 +1,41 @@ +## Numeric + +These datatypes represent numbers. Most of them don't take any arguments. +To use little-endian, prefix its name with "l". + +| Name | Size in bytes | Example of value | Also called | +| --- | --- | --- | --- | +| i8 | 1 | -125 | byte | +| u8 | 1 | 255 | unsigned byte | +| i16 | 2 | -32000 | short | +| u16 | 2 | 60000 | unsigned short | +| i32 | 4 | -2000000000 | int | +| u32 | 4 | 3000000000 | unsigned int | +| f32 | 4 | 4.5 | float | +| f64 | 8 | 4.5 | double | +| i64 | 8 | 1 | long | +| u64 | 8 | 1 | unsigned long | +| int | (varies) | 16777000 | unsigned var | +| varint | (varies) | 300 | int var | + +### **int** ({ size: Integer }) +Arguments: +* size : fixed size in bytes + +Represents a unsigned integer using `size` bytes. + +Example: +```json +[ + "int", + { "size": "3" } +] +``` +Example of value: `65535` (size = 2) / `16777215` (size = 3) + +### **varint** ( ) +Arguments: None + +[Protobuf](https://developers.google.com/protocol-buffers/docs/encoding#varints)-compatible representation for variable-length integers using one or more bytes. + +Example of value: `300` (size is 2 bytes) diff --git a/doc/datatypes/primitives.md b/doc/datatypes/primitives.md new file mode 100644 index 0000000..88eaed6 --- /dev/null +++ b/doc/datatypes/primitives.md @@ -0,0 +1,22 @@ +## Primitives + +### **bool** ( ) +Arguments: None + +Represents a boolean, encoded in one byte. + +Example of value: `true` / `false` + +### **cstring** ( ) +Arguments: None + +Represents a null terminated string. Similar to strings in C. + +Example of value: `"my string"` + +### **void** ( ) +Arguments: None + +Represents an empty value. + +Example of value: `undefined` / `null` diff --git a/doc/datatypes/structures.md b/doc/datatypes/structures.md new file mode 100644 index 0000000..2abeef3 --- /dev/null +++ b/doc/datatypes/structures.md @@ -0,0 +1,62 @@ +## Structures + +### **array** ({ type: Type, countType: Type, ?count: Countable }) +Arguments: +* type : the type of the elements +* countType : the type of the length prefix +* count : optional (either count or countType), a reference to the field counting the elements, or a fixed size (an integer) + +Represents a list of values with same type. + +Example: An array of int prefixed by a short length. +```json +[ + "array", + { + "countType": "i16", + "type": "i32" + } +] +``` +Example of value: `[1, 2, 3, 4]` (type = [i8](./numeric.md)) / `["ac", "dc"]` (type = [cstring](./utils.md)) + +### **container** ([ { name: String, type: Type }, ... ]) +Arguments: +* [array] : a field +* * name : the name of field +* * type : the type of field + +Represents a list of named values. + +Example: A container with fields of type int, int, ushort and ushort. +```json +[ + "container", + [ + { "name": "x", "type": "i32" }, + { "name": "z", "type": "i32" }, + { "name": "bitMap", "type": "u16" }, + { "name": "addBitMap", "type": "u16" } + ] +] +``` +Example of value: `{"x": 10, "z": 10, "bitMap": 10, "addBitMap": 10}` + +### **count** ({ type: Type, countFor: Field }) +Arguments: +* type : the type of count +* countFor : a field to count for + +Represents a count field for an array or a buffer. + +Example: A count for a field name records, of type short. +```json +[ + "count", + { + "type": "i16", + "countFor": "records" + } +] +``` +Example of value: `4` \ No newline at end of file diff --git a/doc/datatypes/utils.md b/doc/datatypes/utils.md new file mode 100644 index 0000000..1a21489 --- /dev/null +++ b/doc/datatypes/utils.md @@ -0,0 +1,86 @@ +## Utils + +### **buffer** ({ countType: Type, ?count: Countable, ?rest: Boolean }) +Arguments: +* countType : the type of the length prefix +* count : optional (either count or countType), a reference to the field counting the elements, or a fixed size (an integer) +* rest : optional (either rest or count/countType), represent rest bytes as-is + +Represents a raw bytes with count prefix/field or without it. + +Example: An buffer prefixed by a varint length. +```json +[ + "buffer", + { "countType": "varint" } +] +``` + +Example of value: `Buffer <01 02 03>` / `Buffer ` + +### **bitfield** ([ { name: String, size: Integer, signed: Boolean } ]) +Arguments: +* [array] : a field +* * name : the name of field +* * size : the size in bits +* * signed : is value signed + +Represents a list of value with sizes that are not a multiple of 8bits. +The sum of the sizes must be a multiple of 8. + +Example: + +3 values, x, y and z with sizes in bits : 26, 12, 26. Notice that 26+12+26=64. +```json +[ + "bitfield", + [ + { "name": "x", "size": 26, "signed": true }, + { "name": "y", "size": 12, "signed": true }, + { "name": "z", "size": 26, "signed": true } + ] +] +``` + +Example of value: `{"x": 10, "y": 10, "z": 10}` + +### **mapper** ({ type: Type, mappings: { [String]: Any, ... } }) +Arguments: +* type : the type of the input +* mappings : a mappings object + +Maps string to a values. + +Example: + +Maps a byte to a string, 1 to "byte", 2 to "short", 3 to "int", 4 to "long". +```json +[ + "mapper", + { + "type": "i8", + "mappings": { + "1": "byte", + "2": "short", + "3": "int", + "4": "long" + } + } +] +``` +Example of value: `"int"` + +### **pstring** ({ countType: Type, ?count: Countable }) +Arguments: +* countType : the type of the length prefix +* count : optional (either count or countType), a reference to the field counting the elements, or a fixed size (an integer) + +Represents a string. + +Example: A string length prefixed by a varint. +```json +[ + "pstring", { "countType": "varint" } +] +``` +Example of value: `"my string"` \ No newline at end of file diff --git a/doc/protocol.md b/doc/protocol.md index 926b5c4..ca423bb 100644 --- a/doc/protocol.md +++ b/doc/protocol.md @@ -2,9 +2,35 @@ ProtoDef defines a protocol json format. It organizes types in namespaces. -The protocol object is an object with keys `types` and namespace keys. +Example: +```json +{ + "types": { + "pstring": "native", + "varint": "native" + }, + "namespace1": { + "mytype": [ + "pstring", + "varint" + ], + "namespace2": { + "packet": "mytype" + } + } +} +``` -* The value of the `types` key is an object of type name to type definition. -* The value of the namespace key is a protocol object. +## **types** : { [String]: Type | "native", ... } +Arguments: +* [object] : a type definition +* * [key] : the name +* * [value] : the type (or `"native"` if implemented) +* * * 0 : name of used type +* * * 1 : options of used type -See [protocol_schema.json](../schemas/protocol_schema.json) for a json schema definition of this format. +## **[String]** : { [String]: Type | [namespace], ... } +Arguments: +* [object] : A namespace object +* * [key] : type name +* * [value] : namespace or type (see above) definition diff --git a/schemas/conditional.json b/schemas/conditional.json index 78ad12e..95b3de7 100644 --- a/schemas/conditional.json +++ b/schemas/conditional.json @@ -1,29 +1,39 @@ { - "switch":{ + "switch": { "title": "switch", "type": "array", - "items":[ - {"enum":["switch"]}, + "items": [ { - "type":"object", + "enum": ["switch"] + }, + { + "type": "object", "properties": { - "compareTo":{"$ref": "definitions#/definitions/contextualizedFieldName"}, - "compareToValue":{"type":"string"}, - "fields":{ - "type":"object", - "patternProperties" : { - "^[-a-zA-Z0-9 _:]+$":{"$ref": "dataType"} + "compareTo": { + "$ref": "definitions#/definitions/contextualizedFieldName" + }, + "compareToValue": { + "type": "string" + }, + "fields": { + "type": "object", + "patternProperties": { + "^[-a-zA-Z0-9 _:]+$": { + "$ref": "dataType" + } }, "additionalProperties": false }, - "default":{"$ref": "dataType"} + "default": { + "$ref": "dataType" + } }, - "oneOf":[ + "oneOf": [ { - "required":["compareTo","fields"] + "required": ["compareTo", "fields"] }, { - "required":["compareToValue","fields"] + "required": ["compareToValue", "fields"] } ], "additionalProperties": false @@ -31,13 +41,17 @@ ], "additionalItems": false }, - "option":{ + "option": { "title": "option", "type": "array", - "items":[ - {"enum":["option"]}, - {"$ref": "dataType"} + "items": [ + { + "enum": ["option"] + }, + { + "$ref": "dataType" + } ], "additionalItems": false } -} \ No newline at end of file +} diff --git a/schemas/datatype.json b/schemas/datatype.json index e632418..8915b7b 100644 --- a/schemas/datatype.json +++ b/schemas/datatype.json @@ -1,42 +1,46 @@ { "title": "datatype", - "description":"default dataTypes", - "oneOf":[ - {"$ref": "switch"}, - {"$ref": "option"}, + "description": "default dataTypes", + "oneOf": [ + { "$ref": "switch" }, + { "$ref": "option" }, - {"$ref": "i8"}, - {"$ref": "u8"}, - {"$ref": "i16"}, - {"$ref": "u16"}, - {"$ref": "i32"}, - {"$ref": "u32"}, - {"$ref": "f32"}, - {"$ref": "f64"}, - {"$ref": "li8"}, - {"$ref": "lu8"}, - {"$ref": "li16"}, - {"$ref": "lu16"}, - {"$ref": "li32"}, - {"$ref": "lu32"}, - {"$ref": "lf32"}, - {"$ref": "lf64"}, - {"$ref": "i64"}, - {"$ref": "li64"}, - {"$ref": "u64"}, - {"$ref": "lu64"}, + { "$ref": "i8" }, + { "$ref": "u8" }, + { "$ref": "i16" }, + { "$ref": "u16" }, + { "$ref": "i32" }, + { "$ref": "u32" }, + { "$ref": "f32" }, + { "$ref": "f64" }, + { "$ref": "li8" }, + { "$ref": "lu8" }, + { "$ref": "li16" }, + { "$ref": "lu16" }, + { "$ref": "li32" }, + { "$ref": "lu32" }, + { "$ref": "lf32" }, + { "$ref": "lf64" }, + { "$ref": "i64" }, + { "$ref": "li64" }, + { "$ref": "u64" }, + { "$ref": "lu64" }, + { "$ref": "int" }, + { "$ref": "varint" }, + { "$ref": "lint" }, + { "$ref": "lvarint" }, - {"$ref": "array"}, - {"$ref": "count"}, - {"$ref": "container"}, + { "$ref": "array" }, + { "$ref": "container" }, + { "$ref": "count" }, - {"$ref": "varint"}, - {"$ref": "bool"}, - {"$ref": "pstring"}, - {"$ref": "buffer"}, - {"$ref": "void"}, - {"$ref": "bitfield"}, - {"$ref": "cstring"}, - {"$ref": "mapper"} + { "$ref": "bool" }, + { "$ref": "cstring" }, + { "$ref": "void" }, + + { "$ref": "pstring" }, + { "$ref": "buffer" }, + { "$ref": "bitfield" }, + { "$ref": "mapper" } ] -} \ No newline at end of file +} diff --git a/schemas/definitions.json b/schemas/definitions.json index de47ca2..b1df16c 100644 --- a/schemas/definitions.json +++ b/schemas/definitions.json @@ -20,5 +20,5 @@ "pattern": "^[a-zA-Z0-9_]+$" } }, - "type":"object" -} \ No newline at end of file + "type": "object" +} diff --git a/schemas/numeric.json b/schemas/numeric.json index 6e6e04d..76fb6c8 100644 --- a/schemas/numeric.json +++ b/schemas/numeric.json @@ -1,22 +1,116 @@ { - "i8":{"enum":["i8"]}, - "u8":{"enum":["u8"]}, - "i16":{"enum":["i16"]}, - "u16":{"enum":["u16"]}, - "i32":{"enum":["i32"]}, - "u32":{"enum":["u32"]}, - "f32":{"enum":["f32"]}, - "f64":{"enum":["f64"]}, - "li8":{"enum":["li8"]}, - "lu8":{"enum":["lu8"]}, - "li16":{"enum":["li16"]}, - "lu16":{"enum":["lu16"]}, - "li32":{"enum":["li32"]}, - "lu32":{"enum":["lu32"]}, - "lf32":{"enum":["lf32"]}, - "lf64":{"enum":["lf64"]}, - "i64":{"enum":["i64"]}, - "li64":{"enum":["li64"]}, - "u64":{"enum":["u64"]}, - "lu64":{"enum":["lu64"]} -} \ No newline at end of file + "i8": { + "enum": ["i8"] + }, + "u8": { + "enum": ["u8"] + }, + "i16": { + "enum": ["i16"] + }, + "u16": { + "enum": ["u16"] + }, + "i32": { + "enum": ["i32"] + }, + "u32": { + "enum": ["u32"] + }, + "f32": { + "enum": ["f32"] + }, + "f64": { + "enum": ["f64"] + }, + "li8": { + "enum": ["li8"] + }, + "lu8": { + "enum": ["lu8"] + }, + "li16": { + "enum": ["li16"] + }, + "lu16": { + "enum": ["lu16"] + }, + "li32": { + "enum": ["li32"] + }, + "lu32": { + "enum": ["lu32"] + }, + "lf32": { + "enum": ["lf32"] + }, + "lf64": { + "enum": ["lf64"] + }, + "i64": { + "enum": ["i64"] + }, + "li64": { + "enum": ["li64"] + }, + "u64": { + "enum": ["u64"] + }, + "lu64": { + "enum": ["lu64"] + }, + "varint": { + "enum": ["varint"] + }, + "lvarint": { + "enum": ["lvarint"] + }, + "int": { + "title": "int", + "type": "array", + "items": [ + { + "enum": ["int"] + }, + { + "type": "array", + "items": { + "type": "object", + "properties": { + "size": { + "type": "number" + } + }, + "required": ["size"], + "additionalProperties": false + }, + "additionalItems": false + } + ], + "additionalItems": false + }, + "lint": { + "title": "lint", + "type": "array", + "items": [ + { + "enum": ["lint"] + }, + { + "type": "array", + "items": { + "type": "object", + "properties": { + "size": { + "type": "number" + } + }, + "required": ["size"], + "additionalProperties": false + }, + "additionalItems": false + } + ], + "additionalItems": false + } +} diff --git a/schemas/primitives.json b/schemas/primitives.json new file mode 100644 index 0000000..82d8641 --- /dev/null +++ b/schemas/primitives.json @@ -0,0 +1,11 @@ +{ + "bool": { + "enum": ["bool"] + }, + "cstring": { + "enum": ["cstring"] + }, + "void": { + "enum": ["void"] + } +} diff --git a/schemas/protocol_schema.json b/schemas/protocol_schema.json index e102250..c09146b 100644 --- a/schemas/protocol_schema.json +++ b/schemas/protocol_schema.json @@ -1,27 +1,43 @@ { "title": "protocol", "type": "object", - "properties":{ - "types":{ + "properties": { + "types": { "type": "object", "patternProperties": { "^[0-9a-zA-Z_]+$": { - "oneOf":[ - {"type":"string"}, + "oneOf": [ + { + "type": "string" + }, { "type": "array", "items": [ - {"type":"string"}, - {"oneOf":[{"type": "object"},{"type": "array"}]} + { + "type": "string" + }, + { + "oneOf": [ + { + "type": "object" + }, + { + "type": "array" + } + ] + } ] } - ]} + ] + } }, "additionalProperties": false } }, "patternProperties": { - "^(?!types)[a-zA-Z_]+$": {"$ref": "#"} + "^(?!types)[a-zA-Z_]+$": { + "$ref": "#" + } }, "additionalProperties": false } diff --git a/schemas/structures.json b/schemas/structures.json index 52002ff..e9d7182 100644 --- a/schemas/structures.json +++ b/schemas/structures.json @@ -1,44 +1,60 @@ { - "array":{ + "array": { "title": "array", - "type":"array", - "items":[ - {"enum":["array"]}, + "type": "array", + "items": [ + { + "enum": ["array"] + }, { - "oneOf":[ + "oneOf": [ { - "type":"object", - "properties":{ - "type": {"$ref": "dataType"}, - "countType": {"$ref": "dataType"} + "type": "object", + "properties": { + "type": { + "$ref": "dataType" + }, + "countType": { + "$ref": "dataType" + } }, "additionalProperties": false, - "required":["type","countType"] + "required": ["type", "countType"] }, { - "type":"object", - "properties":{ - "type": {"$ref": "dataType"}, - "count": {"$ref": "definitions#/definitions/dataTypeArgsCount"} + "type": "object", + "properties": { + "type": { + "$ref": "dataType" + }, + "count": { + "$ref": "definitions#/definitions/dataTypeArgsCount" + } }, "additionalProperties": false, - "required":["type","count"] + "required": ["type", "count"] } ] } ], "additionalItems": false }, - "count":{ + "count": { "title": "count", "type": "array", - "items":[ - {"enum":["count"]}, + "items": [ + { + "enum": ["count"] + }, { "type": "object", "properties": { - "countFor": {"$ref":"definitions#/definitions/contextualizedFieldName"}, - "type": {"$ref": "dataType"} + "countFor": { + "$ref": "definitions#/definitions/contextualizedFieldName" + }, + "type": { + "$ref": "dataType" + } }, "required": ["countFor", "type"], "additionalProperties": false @@ -46,14 +62,12 @@ ], "additionalItems": false }, - "container":{ + "container": { "title": "container", "type": "array", "items": [ { - "enum": [ - "container" - ] + "enum": ["container"] }, { "type": "array", @@ -72,19 +86,13 @@ }, "oneOf": [ { - "required": [ - "anon" - ] + "required": ["anon"] }, { - "required": [ - "name" - ] + "required": ["name"] } ], - "required": [ - "type" - ], + "required": ["type"], "additionalProperties": false }, "additionalItems": false @@ -92,4 +100,4 @@ ], "additionalItems": false } -} \ No newline at end of file +} diff --git a/schemas/utils.json b/schemas/utils.json index f71398e..267c41f 100644 --- a/schemas/utils.json +++ b/schemas/utils.json @@ -1,85 +1,94 @@ { - "varint":{"enum":["varint"]}, - "bool":{"enum":["bool"]}, - "pstring":{ + "pstring": { "title": "pstring", "type": "array", - "items":[ - {"enum":["pstring"]}, + "items": [ + { + "enum": ["pstring"] + }, { - "oneOf":[ + "oneOf": [ { - "type":"object", - "properties":{ - "countType": {"$ref": "dataType"} + "type": "object", + "properties": { + "countType": { + "$ref": "dataType" + } }, "additionalProperties": false, - "required":["countType"] + "required": ["countType"] }, { - "type":"object", - "properties":{ - "count": {"$ref": "definitions#/definitions/dataTypeArgsCount"} + "type": "object", + "properties": { + "count": { + "$ref": "definitions#/definitions/dataTypeArgsCount" + } }, "additionalProperties": false, - "required":["count"] + "required": ["count"] } ] } ], "additionalItems": false }, - "buffer":{ + "buffer": { "title": "buffer", - "type":"array", - "items":[ - {"enum":["buffer"]}, + "type": "array", + "items": [ { - "oneOf":[ + "enum": ["buffer"] + }, + { + "oneOf": [ { "type": "object", "properties": { - "countType": {"$ref": "dataType"} + "countType": { + "$ref": "dataType" + } }, "additionalProperties": false, - "required": [ - "countType" - ] + "required": ["countType"] }, { "type": "object", "properties": { - "count": {"$ref": "definitions#/definitions/dataTypeArgsCount"} + "count": { + "$ref": "definitions#/definitions/dataTypeArgsCount" + } }, "additionalProperties": false, - "required": [ - "count" - ] + "required": ["count"] } ] } ] }, - "void":{"enum":["void"]}, - "bitfield":{ + "bitfield": { "title": "bitfield", "type": "array", "items": [ - { "enum": ["bitfield"] }, + { + "enum": ["bitfield"] + }, { "type": "array", "items": { "type": "object", "properties": { - "name": {"$ref": "definitions#/definitions/fieldName"}, - "size": {"type": "number"}, - "signed": {"type": "boolean"} + "name": { + "$ref": "definitions#/definitions/fieldName" + }, + "size": { + "type": "number" + }, + "signed": { + "type": "boolean" + } }, - "required": [ - "name", - "size", - "signed" - ], + "required": ["name", "size", "signed"], "additionalProperties": false }, "additionalItems": false @@ -87,28 +96,33 @@ ], "additionalItems": false }, - "cstring":{"enum":["cstring"]}, - "mapper":{ + "mapper": { "title": "mapper", "type": "array", - "items":[ - {"enum":["mapper"]}, + "items": [ + { + "enum": ["mapper"] + }, { - "type":"object", + "type": "object", "properties": { - "type":{"$ref": "dataType"}, - "mappings":{ - "type":"object", - "patternProperties" : { - "^[-a-zA-Z0-9 _]+$":{"type":"string"} + "type": { + "$ref": "dataType" + }, + "mappings": { + "type": "object", + "patternProperties": { + "^[-a-zA-Z0-9 _]+$": { + "type": "string" + } }, "additionalProperties": false } }, - "required":["type","mappings"], + "required": ["type", "mappings"], "additionalProperties": false } ], "additionalItems": false } -} \ No newline at end of file +} From aa34e952aecad47d565e9f9a6a84ad310a510f63 Mon Sep 17 00:00:00 2001 From: Alexander Ivanov <47699394+Saiv46@users.noreply.github.com> Date: Sun, 15 Mar 2020 04:11:30 +0800 Subject: [PATCH 2/2] Update doc/datatypes/numeric.md Co-Authored-By: Robin Lambertz --- doc/datatypes/numeric.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/datatypes/numeric.md b/doc/datatypes/numeric.md index 5280087..a6c0084 100644 --- a/doc/datatypes/numeric.md +++ b/doc/datatypes/numeric.md @@ -1,7 +1,7 @@ ## Numeric These datatypes represent numbers. Most of them don't take any arguments. -To use little-endian, prefix its name with "l". +They default to big-endian encoding. To use little-endian, prefix its name with "l". | Name | Size in bytes | Example of value | Also called | | --- | --- | --- | --- |