# Parser Folder

##### `<span class="editor-theme-code">components/driving_board/parser</span>`<span style="white-space: pre-wrap;"> </span>

**This page:**<span style="white-space: pre-wrap;"> structure of message encoding in parser.c </span>

#### <span style="white-space: pre-wrap;">The encoding logic includes: </span>

##### **copy\_motor\_to\_pb():**<span style="white-space: pre-wrap;"> </span>

<span style="white-space: pre-wrap;">Copies each motor from internal MotorDiagnostic struct into protobuf MotorInformation. </span>

##### **DBMDiagnosticsEncode():**<span style="white-space: pre-wrap;"> </span>

<span style="white-space: pre-wrap;">Encodes full diagnostics data into a protobuf message. </span>

<span style="white-space: pre-wrap;">This function: Initializes the protobuf message Copies board state Copies all 10 motors into the protobuf structure Calls pb\_message\_encode to serialize data </span>

**The diagnostics message contains 10 motors:**

<span style="white-space: pre-wrap;">front\_left, middle\_left, back\_left, front\_right, middle\_right, back\_right, steering\_front\_left, steering\_back\_left, steering\_front\_right, steering\_back\_right, </span>

<span style="white-space: pre-wrap;">Each motor is copied using a loop into the protobuf message. </span>

##### **message\_add\_envelope():**

<span style="white-space: pre-wrap;">This method wraps a protobuf message into a PBEnvelope using the same pb\_message\_encode function. </span>

It: Takes a populated protobuf message (e.g. DrivingBoardDiagnostics) Initializes a PBEnvelope Sets the correct oneof field (e.g. drive\_diag) Calls pb\_message\_encode on the envelope struct Returns encoded envelope buffer and length