Add encoders for state sensor/effecter PDRs and sensor event data

Change-Id: I736d1b7b1c124faf8fbf86bb3b760cc9b48c1e2b
Signed-off-by: Zach Clark <zach@ibm.com>
diff --git a/libpldm/platform.h b/libpldm/platform.h
index 5d80511..be55d4f 100644
--- a/libpldm/platform.h
+++ b/libpldm/platform.h
@@ -316,6 +316,29 @@
 	uint8_t possible_states[1];
 } __attribute__((packed));
 
+/** @brief Encode PLDM state sensor PDR
+ *
+ * @param[in/out] sensor                 Structure to encode. All members of
+ * sensor, except those mentioned in the @note below, should be initialized by
+ * the caller.
+ * @param[in]     allocation_size        Size of sensor allocation in bytes
+ * @param[in]     possible_states        Possible sensor states
+ * @param[in]     possible_states_size   Size of possible sensor states in bytes
+ * @param[out]    actual_size            Size of sensor PDR. Set to 0 on error.
+ * @return int    pldm_completion_codes
+ *                PLDM_SUCCESS/PLDM_ERROR/PLDM_ERROR_INVALID_LENGTH
+ *
+ * @note The sensor parameter will be encoded in place.
+ * @note Caller is responsible for allocation of the sensor parameter. Caller
+ *       must allocate enough space for the base structure and the
+ *       sensor->possible_states array, otherwise the function will fail.
+ * @note sensor->hdr.length, .type, and .version will be set appropriately.
+ */
+int encode_state_sensor_pdr(
+    struct pldm_state_sensor_pdr *sensor, size_t allocation_size,
+    const struct state_sensor_possible_states *possible_states,
+    size_t possible_states_size, size_t *actual_size);
+
 /** @union union_effecter_data_size
  *
  *  The bit width and format of reading and threshold values that the effecter
@@ -399,6 +422,32 @@
 	bitfield8_t states[1];
 } __attribute__((packed));
 
+/** @brief Encode PLDM state effecter PDR
+ *
+ * @param[in/out] effecter               Structure to encode. All members of
+ *                                       effecter, except those mentioned in
+ *                                       the @note below, should be initialized
+ *                                       by the caller.
+ * @param[in]     allocation_size        Size of effecter allocation in bytes
+ * @param[in]     possible_states        Possible effecter states
+ * @param[in]     possible_states_size   Size of possible effecter states in
+ *                                       bytes
+ * @param[out]    actual_size            Size of effecter PDR. Set to 0 on
+ *                                       error.
+ * @return int    pldm_completion_codes
+ *                PLDM_SUCCESS/PLDM_ERROR/PLDM_ERROR_INVALID_LENGTH
+ *
+ * @note The effecter parameter will be encoded in place.
+ * @note Caller is responsible for allocation of the effecter parameter. Caller
+ *       must allocate enough space for the base structure and the
+ *       effecter->possible_states array, otherwise the function will fail.
+ * @note effecter->hdr.length, .type, and .version will be set appropriately.
+ */
+int encode_state_effecter_pdr(
+    struct pldm_state_effecter_pdr *effecter, size_t allocation_size,
+    const struct state_effecter_possible_states *possible_states,
+    size_t possible_states_size, size_t *actual_size);
+
 /** @struct set_effecter_state_field
  *
  *  Structure representing a stateField in SetStateEffecterStates command */
@@ -1273,6 +1322,29 @@
     struct pldm_pdr_repository_chg_event_data *event_data,
     size_t *actual_change_records_size, size_t max_change_records_size);
 
+/** @brief Encode event data for a PLDM Sensor Event
+ *
+ *  @param[out] event_data              The object to store the encoded event in
+ *  @param[in] event_data_size          Size of the allocation for event_data
+ *  @param[in] sensor_id                Sensor ID
+ *  @param[in] sensor_event_class       Sensor event class
+ *  @param[in] sensor_offset            Offset
+ *  @param[in] event_state              Event state
+ *  @param[in] previous_event_state     Previous event state
+ *  @param[out] actual_event_data_size  The real size in bytes of the event_data
+ *  @return int pldm_completion_codes   PLDM_SUCCESS/PLDM_ERROR_INVALID_LENGTH
+ *  @note If event_data is NULL, then *actual_event_data_size will be set to
+ *        reflect the size of the event data, and PLDM_SUCCESS will be returned.
+ *  @note The caller is responsible for allocating and deallocating the
+ *        event_data
+ */
+int encode_sensor_event_data(struct pldm_sensor_event_data *event_data,
+			     size_t event_data_size, uint16_t sensor_id,
+			     enum sensor_event_class_states sensor_event_class,
+			     uint8_t sensor_offset, uint8_t event_state,
+			     uint8_t previous_event_state,
+			     size_t *actual_event_data_size);
+
 /** @brief Decode PldmPDRRepositoryChangeRecord response data
  *
  *  @param[in] change_record_data - changeRecordData for