aboutsummaryrefslogtreecommitdiff
path: root/gd/packet/parser/README
blob: df9e99fca08763f315d8f42c27edd96281a10a21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
This file just contains some notes about the design and usage of the PDL language.

-------
 TERMS
-------
.pdl
  The file type that defines packet definitions. You may think of each pdl file
  as its own translation unit.

Packet Views and Builders
  Generated from a packet definition. Views are used to validate packets and
  extract the fields that are defined in the pdl file.  Builders check the input
  arguments and can be serialized.

Checksum types
  checksum MyChecksumClass : 16 "path/to/the/class/"
  Checksum fields need to implement the following three methods:
    void Initialize(MyChecksumClass&);
    void AddByte(MyChecksumClass&, uint8_t);
    // Assuming a 16-bit (uint16_t) checksum:
    uint16_t GetChecksum(MyChecksumClass&);
-------------
 LIMITATIONS
-------------
  - Size fields for a variable length field MUST come before the definition
    of said field.

  - Payload fields must be byte-aligned unless they have an unknown size.
    Body fields are allowed to not be byte aligned.

  - No conditionals

  - Can not have to fields with the same name anywhere in the in an inheritence chain

  - Can't handle size for Body type fields yet since they might not be byte aligned.

  - Currently no arrays of custom types (might change later)

-------
 NOTES
-------
All field names should be in snake_case.  Types should be in CamelCase.

The _payload_ keyword generates a getter but _body_ doesn't. Therefore, a
_payload_ must be byte aligned.

Supports constraints on grandparents
Supports multiple constraints
Every field handles its own generation.
One pdl file will result in one header file with all the packets

Things to cover -
  Constraints
  Inheritance vs Contains

Custom fields with fixed size must extend and implement:
  packet::CustomFieldFixedSizeInterface

Custom fields with variable size need the following functions:
  static void Serialize(const Type&, MutableView&);
  static std::optional<size_t> Size(Iterator);
  static Type Parse(Iterator);
  std::string ToString();