Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/datatypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
* * [bitfield](./datatypes/utils.md)
* * [mapper](./datatypes/utils.md)
* * [pstring](./datatypes/utils.md)
* * [hash](./datatypes/utils.md)
22 changes: 22 additions & 0 deletions doc/datatypes/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,25 @@ Example: A string length prefixed by a varint.
]
```
Example of value: `"my string"`

### **hash** ({ alg: String, type: Type, body: Type })
Arguments:
* alg : the hash algorithm, one of : `crc32c` (CRC-32C, the Castagnoli polynomial, reflected, all-ones init and final xor, a 4 byte digest)
* type : the type the hash is written and read as, of constant size and at least as wide as the digest
* body : the name of the type the value is serialized as before being hashed

Represents a hash of a value instead of the value itself : writing serializes the value as `body`, hashes those bytes and writes the digest as `type`; reading reads `type` and yields the digest. When `type` is signed the digest is written in two's complement.

Example: A CRC32C of an item component, written as a signed int.
```json
[
"hash",
{
"alg": "crc32c",
"type": "i32",
"body": "ItemComponent"
}
]
```

Example of value: `{ "id": 5, "level": 3 }`, serializing to `05 03` / reads as `-1088848499`
3 changes: 2 additions & 1 deletion schemas/datatype.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
{ "$ref": "buffer" },
{ "$ref": "bitfield" },
{ "$ref": "bitflags" },
{ "$ref": "mapper" }
{ "$ref": "mapper" },
{ "$ref": "hash" }
]
}
26 changes: 26 additions & 0 deletions schemas/utils.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,31 @@
}
],
"additionalItems": false
},
"hash": {
"title": "hash",
"type": "array",
"items": [
{
"enum": ["hash"]
},
{
"type": "object",
"properties": {
"alg": {
"enum": ["crc32c"]
},
"type": {
"$ref": "dataType"
},
"body": {
"type": "string"
}
},
"required": ["alg", "type", "body"],
"additionalProperties": false
}
],
"additionalItems": false
}
}