Skip to content

Commit 14d4535

Browse files
committed
update protocol 1: body's length
1 parent 67c3108 commit 14d4535

File tree

1 file changed

+95
-23
lines changed

1 file changed

+95
-23
lines changed

README.md

Lines changed: 95 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ The IOT_PROTOCOL (*iot://*) request minimum size is 8 bytes withless to require
99
## Preamble Version 1
1010

1111
```js
12-
VERSION\n
13-
METHOD+ID\n
14-
PATH\n
15-
[HEADERS\n]
16-
[B\n BODY]
12+
VERSION \n
13+
METHOD + ID \n
14+
PATH \n
15+
[HEADERS \n]
16+
[BODY_CHAR + BODY_LENGTH \n BODY]
1717
```
1818

1919
### SEPARATOR char
@@ -26,64 +26,136 @@ SEPARATOR char serves to divide pieces of information
2626
* char: `\n`
2727
* hex: `0xA`
2828
* decimal: `10`
29+
* binary: `0b1010`
2930

3031
### [0] VERSION
3132

3233
Version is the version of iot protocol. Used for compatibility.
3334

34-
* Type: `byte` | `uint8_t`. **REQUIRED**
35+
Format: `VERSION + SEPARATOR`. **REQUIRED** | **SINGLE**
36+
37+
* Type: `byte` | `uint8_t`
3538
* Size: 1 byte
36-
* Example: `1`
39+
* Example:
40+
* decimal: `1`
41+
* hex: `0x1`
42+
* binary: `0b00000001`
3743

3844
### [1] METHOD+ID
3945

4046
Method ID identifies the method of request and its id.
4147

42-
Methods:
48+
Format: `METHOD + ID + SEPARATOR`. **REQUIRED** | **SINGLE**
49+
50+
**METHOD**:
4351

44-
* Type: `char`. **REQUIRED**
52+
Method is the reason why the request is made. **REQUIRED**
53+
54+
* Type: `char`.
4555
* Size: 1 byte
4656
* Example: `R`
4757

48-
- `S` | `0x83`: *Signal* method used to send signals like events
49-
- `R` | `0x82`: *Request* method used to do calls needs a response
50-
- `r` | `0x114`: *Response* method used to responds a request
58+
* Methods types:
59+
- *Signal*: method used to send signals like events
60+
* char: `S`
61+
* decimal: `131`
62+
* hex: `0x83`
63+
* binary: `0b10000011`
64+
65+
- *Request*: method used to do calls that needs a response
66+
* char: `R`
67+
* decimal: `130`
68+
* hex: `0x82`
69+
* binary: `0b10000010`
5170

71+
- *Response*: method used to responds a request
72+
* char: `r`
73+
* decimal: `114`
74+
* hex: `0x72`
75+
* binary: `0b1110010`
5276

53-
ID:
77+
**ID**:
5478

55-
Unsigned random number with up to 2^16 that identifies the request.
79+
Unsigned random number with up to 2^16 that identifies the request. **REQUIRED**
5680

57-
* Type: `uint16_t` as Big Endian format. **REQUIRED**
81+
* Type: `uint16_t` as Big Endian format.
5882
* Size: 2 bytes
59-
* Example: `1822`
83+
* Example:
84+
* decimal: `276`
85+
* uint_8[2]: `[ 1 , 20 ]`
86+
* binary: `0b00000001 00010100`
6087

6188
### [2] PATH
6289

6390
The path component contains data, usually organized in hierarchical
64-
form, that, serves to identify a resource [URI > 3.3 Path](https://www.rfc-editor.org/info/rfc3986).
91+
form, that, serves to identify a resource [URI > 3.3 Path](https://www.rfc-editor.org/info/rfc3986).
92+
93+
Format: `PATH + SEPARATOR`. **REQUIRED** | **SINGLE**
6594

66-
* Type: `string`. **REQUIRED**
95+
* Type: `string`
6796
* Example: `/foo/bar`
6897
* Default: `/`
6998

7099
### [3] HEADERS
71100

72-
Key Value Pair joined by `:` char, that, serves to set an attribute value for the request. Multiple headers must be separate by SEPARATOR char (`\n`).
101+
Headers are be Key Value Pair that serves to set an attribute value for the request. Case sensitive.
102+
103+
Format: `HEADER + SEPARATOR`. **OPTIONAL** | **MULTIPLE**
104+
105+
**HEADER**
73106

74-
* Type: `Map<string, string>`. **OPTIONAL**
107+
* Type: `string`
108+
* Format: `KEY + KEY_VALUE_SEPARATOR + VALUE`
109+
* *KEY*:
110+
* Type: `string`
111+
* *VALUE*:
112+
* Type: `string`
113+
* *KEY_VALUE_SEPARATOR*:
114+
* Constant:
115+
* char: `:`
116+
* decimal: `58`
117+
* hex: `0x3a`
118+
* binary: `0b00111010`
75119
* Example:
76120
* Single header: `foo:bar\n`
77121
* Multiple headers: `foo:bar\nlorem:ipsum\n`
78122

79123
### [4] BODY
80124

81-
The final data to be sent for request receiver. Starts with `B\n`.
125+
The final data to be sent for request receiver.
126+
127+
Format: `BODY_CHAR + BODY_LENGTH+SEPARATOR + BODY`. **OPTIONAL** | **SINGLE**
128+
129+
**BODY_CHAR**:
130+
131+
Identifies the body part. **REQUIRED**
132+
133+
* Type: `char`
134+
* Size: 1 byte
135+
* Constant:
136+
* char: `B`
137+
* hex: `0x42`
138+
* decimal: `66`
139+
140+
**BODY_LENGTH**:
141+
142+
The body's length. **REQUIRED**
143+
144+
* Type: `uint16_t` as Big Endian format
145+
* Size: 2 bytes
146+
* Example:
147+
* decimal: `2321`
148+
* uint_8[2]: `[ 9 , 17 ]`
149+
* binary: `0b00001001 00010001`
150+
151+
**BODY**:
152+
153+
The body / contents of request. **REQUIRED**
82154

83155
* Type: `uint8_t[]`
84156
* Example:
85-
* Message: `B\nlorem ipsum message`
86-
* Buffer: `['B', '\n', 0x1, 0x2, 0x3, 0x4]`
157+
* String: `the message`
158+
* Buffer: `[ 116, 104, 101, 32, 109, 101, 115, 115, 97, 103, 101 ]`
87159

88160
## Middlewares
89161

0 commit comments

Comments
 (0)