Skip to content

Commit 409e409

Browse files
committed
feat(specification): enhance Content Format V3 with improved field efficiency and support for image content in V4
1 parent de35c64 commit 409e409

1 file changed

Lines changed: 90 additions & 115 deletions

File tree

docs/specification.md

Lines changed: 90 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -194,70 +194,53 @@
194194
195195
> [!NOTE]
196196
>
197-
> This format uses a bitmap to indicate which fields are present, making it more efficient than previous versions.
197+
> This format improves efficiency by only including length fields for applicable fields per service type, rather than including all fields with zero lengths.
198198
>
199199
> **All 2-byte length fields are encoded as unsigned little-endian.**
200200
201-
#### Field Bitmap Definition
202-
203-
The bitmap is a single byte where each bit represents the presence of a specific field:
204-
205-
- **Bit 0 (0x01)**: `from` field
206-
- **Bit 1 (0x02)**: `to` field
207-
- **Bit 2 (0x04)**: `cc` field
208-
- **Bit 3 (0x08)**: `bcc` field
209-
- **Bit 4 (0x10)**: `subject` field
210-
- **Bit 5 (0x20)**: `body` field
211-
- **Bit 6 (0x40)**: `access_token` field
212-
- **Bit 7 (0x80)**: `refresh_token` field
213-
214201
1. **Email format**: Binary-encoded fields with the following structure:
215202

216-
- **1 byte**: Field presence bitmap
217-
- **1 byte**: Length of `from` field (if bit 0 is set)
218-
- **2 bytes**: Length of `to` field (if bit 1 is set)
219-
- **2 bytes**: Length of `cc` field (if bit 2 is set)
220-
- **2 bytes**: Length of `bcc` field (if bit 3 is set)
221-
- **1 byte**: Length of `subject` field (if bit 4 is set)
222-
- **2 bytes**: Length of `body` field (if bit 5 is set)
223-
- **2 bytes**: Length of `access_token` field (if bit 6 is set)
224-
- **2 bytes**: Length of `refresh_token` field (if bit 7 is set)
225-
- **Variable**: Value of `from` field (if present)
226-
- **Variable**: Value of `to` field (if present)
227-
- **Variable**: Value of `cc` field (if present)
228-
- **Variable**: Value of `bcc` field (if present)
229-
- **Variable**: Value of `subject` field (if present)
230-
- **Variable**: Value of `body` field (if present)
231-
- **Variable**: Value of `access_token` field (if present)
232-
- **Variable**: Value of `refresh_token` field (if present)
203+
- **1 byte**: Length of `from` field.
204+
- **2 bytes**: Length of `to` field.
205+
- **2 bytes**: Length of `cc` field.
206+
- **2 bytes**: Length of `bcc` field.
207+
- **1 byte**: Length of `subject` field.
208+
- **2 bytes**: Length of `body` field.
209+
- **2 bytes**: Length of `access_token` field (optional).
210+
- **2 bytes**: Length of `refresh_token` field (optional).
211+
- **Variable**: Value of `from` field.
212+
- **Variable**: Value of `to` field.
213+
- **Variable**: Value of `cc` field.
214+
- **Variable**: Value of `bcc` field.
215+
- **Variable**: Value of `subject` field.
216+
- **Variable**: Value of `body` field.
217+
- **Variable**: Value of `access_token` field (if present).
218+
- **Variable**: Value of `refresh_token` field (if present).
233219

234220
2. **Text format**: Binary-encoded fields with the following structure:
235221

236-
- **1 byte**: Field presence bitmap
237-
- **1 byte**: Length of `from` field (if bit 0 is set)
238-
- **2 bytes**: Length of `body` field (if bit 5 is set)
239-
- **2 bytes**: Length of `access_token` field (if bit 6 is set)
240-
- **2 bytes**: Length of `refresh_token` field (if bit 7 is set)
241-
- **Variable**: Value of `from` field (if present)
242-
- **Variable**: Value of `body` field (if present)
243-
- **Variable**: Value of `access_token` field (if present)
244-
- **Variable**: Value of `refresh_token` field (if present)
222+
- **1 byte**: Length of `from` field.
223+
- **2 bytes**: Length of `body` field.
224+
- **2 bytes**: Length of `access_token` field (optional).
225+
- **2 bytes**: Length of `refresh_token` field (optional).
226+
- **Variable**: Value of `from` field.
227+
- **Variable**: Value of `body` field.
228+
- **Variable**: Value of `access_token` field (if present).
229+
- **Variable**: Value of `refresh_token` field (if present).
245230

246231
3. **Message format**: Binary-encoded fields with the following structure:
247232

248-
- **1 byte**: Field presence bitmap
249-
- **1 byte**: Length of `from` field (if bit 0 is set)
250-
- **2 bytes**: Length of `to` field (if bit 1 is set)
251-
- **2 bytes**: Length of `body` field (if bit 5 is set)
252-
- **Variable**: Value of `from` field (if present)
253-
- **Variable**: Value of `to` field (if present)
254-
- **Variable**: Value of `body` field (if present)
233+
- **1 byte**: Length of `from` field.
234+
- **2 bytes**: Length of `to` field.
235+
- **2 bytes**: Length of `body` field.
236+
- **Variable**: Value of `from` field.
237+
- **Variable**: Value of `to` field.
238+
- **Variable**: Value of `body` field.
255239

256240
4. **Test format**: Binary-encoded fields with the following structure:
257241

258-
- **1 byte**: Field presence bitmap
259-
- **1 byte**: Length of `from` field (if bit 0 is set)
260-
- **Variable**: Value of `from` field (considered the test ID, if present)
242+
- **1 byte**: Length of `from` field.
243+
- **Variable**: Value of `from` field (considered the test ID).
261244

262245
### Content Format V4
263246

@@ -267,89 +250,81 @@ The bitmap is a single byte where each bit represents the presence of a specific
267250
268251
> [!NOTE]
269252
>
270-
> This format extends V3 by using a 2-byte bitmap instead of 1-byte, with bits 8 and 9 representing content types.
253+
> This format extends V3 by adding support for image content. A content type indicator determines which content types are present.
271254
>
272255
> **All 2-byte length fields are encoded as unsigned little-endian.**
273256
274-
#### Field Bitmap Definition (2 bytes)
275-
276-
The bitmap is 2 bytes where each bit represents the presence of a specific field:
257+
#### Content Type Indicator
277258

278-
**First byte (bits 0-7) - Standard fields:**
259+
The content type indicator is a single byte where each bit represents the presence of a specific content type:
279260

280-
- **Bit 0 (0x01)**: `from` field
281-
- **Bit 1 (0x02)**: `to` field
282-
- **Bit 2 (0x04)**: `cc` field
283-
- **Bit 3 (0x08)**: `bcc` field
284-
- **Bit 4 (0x10)**: `subject` field
285-
- **Bit 5 (0x20)**: `body` field
286-
- **Bit 6 (0x40)**: `access_token` field
287-
- **Bit 7 (0x80)**: `refresh_token` field
261+
- **Bit 0 (0x01)**: Text content present
262+
- **Bit 1 (0x02)**: Image content present
288263

289-
**Second byte (bits 8-15) - Content type:**
264+
Possible combinations:
290265

291-
- **Bit 8 (0x0100)**: Text content present
292-
- **Bit 9 (0x0200)**: Image content present
266+
- **0x01**: Text-only content
267+
- **0x02**: Image-only content
268+
- **0x03**: Text and image content
293269

294270
1. **Email format**: Binary-encoded fields with the following structure:
295271

296-
- **2 bytes**: Field and content type bitmap
297-
- **1 byte**: Length of `from` field (if bit 0 is set and bit 8 is set)
298-
- **2 bytes**: Length of `to` field (if bit 1 is set and bit 8 is set)
299-
- **2 bytes**: Length of `cc` field (if bit 2 is set and bit 8 is set)
300-
- **2 bytes**: Length of `bcc` field (if bit 3 is set and bit 8 is set)
301-
- **1 byte**: Length of `subject` field (if bit 4 is set and bit 8 is set)
302-
- **2 bytes**: Length of `body` field (if bit 5 is set and bit 8 is set)
303-
- **2 bytes**: Length of `access_token` field (if bit 6 is set and bit 8 is set)
304-
- **2 bytes**: Length of `refresh_token` field (if bit 7 is set and bit 8 is set)
305-
- **2 bytes**: `Image Session ID` (if bit 9 is set)
306-
- **1 byte**: `Image Segment info` (if bit 9 is set)
307-
- **2 bytes**: Length of `Image` (if bit 9 is set)
308-
- **Variable**: Value of `from` field (if present)
309-
- **Variable**: Value of `to` field (if present)
310-
- **Variable**: Value of `cc` field (if present)
311-
- **Variable**: Value of `bcc` field (if present)
312-
- **Variable**: Value of `subject` field (if present)
313-
- **Variable**: Value of `body` field (if present)
314-
- **Variable**: Value of `access_token` field (if present)
315-
- **Variable**: Value of `refresh_token` field (if present)
316-
- **Variable**: Value of `Image` (if present)
272+
- **1 byte**: Content type indicator
273+
- **1 byte**: Length of `from` field (if text content present).
274+
- **2 bytes**: Length of `to` field (if text content present).
275+
- **2 bytes**: Length of `cc` field (if text content present).
276+
- **2 bytes**: Length of `bcc` field (if text content present).
277+
- **1 byte**: Length of `subject` field (if text content present).
278+
- **2 bytes**: Length of `body` field (if text content present).
279+
- **2 bytes**: Length of `access_token` field (if text content present and optional).
280+
- **2 bytes**: Length of `refresh_token` field (if text content present and optional).
281+
- **2 bytes**: `Image Session ID` (if image content present).
282+
- **1 byte**: `Image Segment info` (if image content present).
283+
- **2 bytes**: Length of `Image` (if image content present).
284+
- **Variable**: Value of `from` field (if text content present).
285+
- **Variable**: Value of `to` field (if text content present).
286+
- **Variable**: Value of `cc` field (if text content present).
287+
- **Variable**: Value of `bcc` field (if text content present).
288+
- **Variable**: Value of `subject` field (if text content present).
289+
- **Variable**: Value of `body` field (if text content present).
290+
- **Variable**: Value of `access_token` field (if text content present and token provided).
291+
- **Variable**: Value of `refresh_token` field (if text content present and token provided).
292+
- **Variable**: Value of `Image` (if image content present).
317293

318294
2. **Text format**: Binary-encoded fields with the following structure:
319295

320-
- **2 bytes**: Field and content type bitmap
321-
- **1 byte**: Length of `from` field (if bit 0 is set and bit 8 is set)
322-
- **2 bytes**: Length of `body` field (if bit 5 is set and bit 8 is set)
323-
- **2 bytes**: Length of `access_token` field (if bit 6 is set and bit 8 is set)
324-
- **2 bytes**: Length of `refresh_token` field (if bit 7 is set and bit 8 is set)
325-
- **2 bytes**: `Image Session ID` (if bit 9 is set)
326-
- **1 byte**: `Image Segment info` (if bit 9 is set)
327-
- **2 bytes**: Length of `Image` (if bit 9 is set)
328-
- **Variable**: Value of `from` field (if present)
329-
- **Variable**: Value of `body` field (if present)
330-
- **Variable**: Value of `access_token` field (if present)
331-
- **Variable**: Value of `refresh_token` field (if present)
332-
- **Variable**: Value of `Image` (if present)
296+
- **1 byte**: Content type indicator
297+
- **1 byte**: Length of `from` field (if text content present).
298+
- **2 bytes**: Length of `body` field (if text content present).
299+
- **2 bytes**: Length of `access_token` field (if text content present and optional).
300+
- **2 bytes**: Length of `refresh_token` field (if text content present and optional).
301+
- **2 bytes**: `Image Session ID` (if image content present).
302+
- **1 byte**: `Image Segment info` (if image content present).
303+
- **2 bytes**: Length of `Image` (if image content present).
304+
- **Variable**: Value of `from` field (if text content present).
305+
- **Variable**: Value of `body` field (if text content present).
306+
- **Variable**: Value of `access_token` field (if text content present and token provided).
307+
- **Variable**: Value of `refresh_token` field (if text content present and token provided).
308+
- **Variable**: Value of `Image` (if image content present).
333309

334310
3. **Message format**: Binary-encoded fields with the following structure:
335311

336-
- **2 bytes**: Field and content type bitmap
337-
- **1 byte**: Length of `from` field (if bit 0 is set and bit 8 is set)
338-
- **2 bytes**: Length of `to` field (if bit 1 is set and bit 8 is set)
339-
- **2 bytes**: Length of `body` field (if bit 5 is set and bit 8 is set)
340-
- **2 bytes**: `Image Session ID` (if bit 9 is set)
341-
- **1 byte**: `Image Segment info` (if bit 9 is set)
342-
- **2 bytes**: Length of `Image` (if bit 9 is set)
343-
- **Variable**: Value of `from` field (if present)
344-
- **Variable**: Value of `to` field (if present)
345-
- **Variable**: Value of `body` field (if present)
346-
- **Variable**: Value of `Image` (if present)
312+
- **1 byte**: Content type indicator
313+
- **1 byte**: Length of `from` field (if text content present).
314+
- **2 bytes**: Length of `to` field (if text content present).
315+
- **2 bytes**: Length of `body` field (if text content present).
316+
- **2 bytes**: `Image Session ID` (if image content present).
317+
- **1 byte**: `Image Segment info` (if image content present).
318+
- **2 bytes**: Length of `Image` (if image content present).
319+
- **Variable**: Value of `from` field (if text content present).
320+
- **Variable**: Value of `to` field (if text content present).
321+
- **Variable**: Value of `body` field (if text content present).
322+
- **Variable**: Value of `Image` (if image content present).
347323

348324
4. **Test format**: Binary-encoded fields with the following structure:
349325

350-
- **2 bytes**: Field and content type bitmap
351-
- **1 byte**: Length of `from` field (if bit 0 is set)
352-
- **Variable**: Value of `from` field (considered the test ID, if present)
326+
- **1 byte**: Length of `from` field (if text content present).
327+
- **Variable**: Value of `from` field (considered the test ID, if text content present).
353328

354329
## Supported Payload Versions
355330

@@ -359,7 +334,7 @@ The bitmap is 2 bytes where each bit represents the presence of a specific field
359334
| [v1](#payload-format-v1) | `0x01` | `1` | Introduces version marker, 2-byte ciphertext length, explicit device ID length field, and language code support. Uses Content Format V1 with 1-byte token length fields. |
360335
| [v2](#payload-format-v2) | `0x02` | `2` | Same payload structure as V1 but uses Content Format V2 with 2-byte token length fields for better support of longer access/refresh tokens. |
361336
| [v3](#payload-format-v3) | `0x03` | `3` | Same payload structure as V1/V2 but uses Content Format V3 with bitmap-based field presence indication for more efficient encoding. |
362-
| [v4](#payload-format-v4) | `0x04` | `4` | Same payload structure as V1/V2/V3 but uses Content Format V4 with 2-byte bitmap supporting image content. |
337+
| [v4](#payload-format-v4) | `0x04` | `4` | Same payload structure as V1/V2/V3 but uses Content Format V4 with support for image content. |
363338

364339
## Payload Format V0
365340

0 commit comments

Comments
 (0)