Skip to content

Commit 5dc47c4

Browse files
Follow-up octet-stream codec - short explanation #1194 (#1209)
* docs: add `octet-stream` codec documentation * fix: statisfy prettier * fix: adjust bit offset Co-authored-by: danielpeintner <daniel.peintner@gmail.com> --------- Co-authored-by: danielpeintner <daniel.peintner@gmail.com>
1 parent 84327e3 commit 5dc47c4

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

packages/core/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,40 @@ see binding examples such as
2121
- https://github.com/eclipse-thingweb/node-wot/blob/master/packages/binding-http
2222
- https://github.com/eclipse-thingweb/node-wot/blob/master/packages/binding-coap
2323

24+
## Codecs
25+
26+
### Octet-Stream
27+
28+
The octet-stream codec enables deserialization and serialization of binary data. To encode and decode sequences of bytes, the octet-stream codec uses the following content type parameters:
29+
| Parameter | Description | Default |
30+
| --- | --- | --- |
31+
| `length` | Number of bytes produced during serialization or consumed during deserialization | |
32+
| `signed` | Signedness of the data type, `true` or `false` | `true` |
33+
| `byteSeq` | Endianness, enum of `BIG_ENDIAN`, `LITTLE_ENDIAN`, `BIG_ENDIAN_BYTE_SWAP`, `LITTLE_ENDIAN_BYTE_SWAP` | `BIG_ENDIAN` |
34+
35+
Additionally, the octet-stream codec supports the data schema terms below for addressing bit-fields:
36+
| Term | Description | Default |
37+
| --- | --- | --- |
38+
| `ex:bitLength` | Number of bits produced during serialization or consumed during deserialization | |
39+
| `ex:bitOffset` | Offset in bits from the beginning of the byte sequence | `0` |
40+
41+
With the help of the terms and parameters above, the octet-stream codec can be used to serialize and deserialize objects containing bit-fields and sequences of bytes, like in the following example.
42+
43+
#### Example
44+
45+
To serialize the object `{ flag1: true, numberProperty: 99, stringProperty: "Web" }` to a sequence of bytes, the content type `application/octet-stream;length=4;signed=false;`, along with the following data schema can be used:
46+
47+
```json
48+
{
49+
"type": "object",
50+
"properties": {
51+
"flag1": { "type": "boolean", "ex:bitOffset": 0, "ex:bitLength": 1 },
52+
"numberProperty": { "type": "integer", "ex:bitOffset": 1, "ex:bitLength": 7 },
53+
"stringProperty": { "type": "string", "ex:bitOffset": 8, "ex:bitLength": 24 }
54+
}
55+
}
56+
```
57+
2458
## More Details
2559

2660
See <https://github.com/eclipse-thingweb/node-wot/>

0 commit comments

Comments
 (0)