replace pointer parameters with references

The methods declared in sensorhandler.hpp are all defined with
pointer parameters. Since these parameters should always be valid and
not null, using raw pointers is unnecessary and can be misleading, so
passing them as references makes the API safer and more idiomatic in
modern C++.

Change-Id: Iaec6caeb1e04fcc38cc244dd66634724c62dd0c1
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
diff --git a/dbus-sdr/sensorcommands.cpp b/dbus-sdr/sensorcommands.cpp
index c6a167f..97ab5e5 100644
--- a/dbus-sdr/sensorcommands.cpp
+++ b/dbus-sdr/sensorcommands.cpp
@@ -1905,8 +1905,8 @@
 
     // populate sensor name from path
     auto name = sensor::parseSdrIdFromPath(path);
-    get_sdr::body::set_id_strlen(name.size(), &record.body);
-    get_sdr::body::set_id_type(3, &record.body); // "8-bit ASCII + Latin 1"
+    get_sdr::body::set_id_strlen(name.size(), record.body);
+    get_sdr::body::set_id_type(3, record.body); // "8-bit ASCII + Latin 1"
     std::memcpy(record.body.id_string, name.c_str(),
                 std::min(name.length() + 1, sizeof(record.body.id_string)));
 
@@ -1921,7 +1921,7 @@
         sensorSettable =
             mappedVariant<bool>(mutability->second, "Mutable", false);
     }
-    get_sdr::body::init_settable_state(sensorSettable, &record.body);
+    get_sdr::body::init_settable_state(sensorSettable, record.body);
 
     // Grant write permission to sensors deemed externally settable
     details::sdrWriteTable.setWritePermission(sensorNum, sensorSettable);
@@ -2008,7 +2008,7 @@
     if (ipmi::sensor::Mutability::Write ==
         (sensor->second.mutability & ipmi::sensor::Mutability::Write))
     {
-        get_sdr::body::init_settable_state(true, &(record.body));
+        get_sdr::body::init_settable_state(true, record.body);
     }
 
     auto id_string = sensor->second.sensorName;
@@ -2021,15 +2021,15 @@
     if (id_string.length() > FULL_RECORD_ID_STR_MAX_LENGTH)
     {
         get_sdr::body::set_id_strlen(FULL_RECORD_ID_STR_MAX_LENGTH,
-                                     &(record.body));
+                                     record.body);
     }
     else
     {
-        get_sdr::body::set_id_strlen(id_string.length(), &(record.body));
+        get_sdr::body::set_id_strlen(id_string.length(), record.body);
     }
     get_sdr::body::set_id_type(3, &record.body); // "8-bit ASCII + Latin 1"
     std::strncpy(record.body.id_string, id_string.c_str(),
-                 get_sdr::body::get_id_strlen(&(record.body)));
+                 get_sdr::body::get_id_strlen(record.body));
 }
 #endif
 
@@ -2090,8 +2090,8 @@
     // populate sensor name from path
     auto name = sensor::parseSdrIdFromPath(path);
     int nameSize = std::min(name.size(), sizeof(record.body.id_string));
-    get_sdr::body::set_id_strlen(nameSize, &record.body);
-    get_sdr::body::set_id_type(3, &record.body); // "8-bit ASCII + Latin 1"
+    get_sdr::body::set_id_strlen(nameSize, record.body);
+    get_sdr::body::set_id_type(3, record.body); // "8-bit ASCII + Latin 1"
     std::memset(record.body.id_string, 0x00, sizeof(record.body.id_string));
     std::memcpy(record.body.id_string, name.c_str(), nameSize);
 
diff --git a/dbus-sdr/storagecommands.cpp b/dbus-sdr/storagecommands.cpp
index e0e47e1..84a4449 100644
--- a/dbus-sdr/storagecommands.cpp
+++ b/dbus-sdr/storagecommands.cpp
@@ -1208,7 +1208,7 @@
     data.key.containerEntityId = entity->second.containerEntityId;
     data.key.containerEntityInstance = entity->second.containerEntityInstance;
     get_sdr::key::set_flags(entity->second.isList, entity->second.isLinked,
-                            &(data.key));
+                            data.key);
     data.key.entityId1 = entity->second.containedEntities[0].first;
     data.key.entityInstance1 = entity->second.containedEntities[0].second;
 
diff --git a/sensordatahandler.cpp b/sensordatahandler.cpp
index 60b5c9a..805ebcb 100644
--- a/sensordatahandler.cpp
+++ b/sensordatahandler.cpp
@@ -71,7 +71,7 @@
     sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
     GetSensorResponse response{};
 
-    enableScanning(&response);
+    enableScanning(response);
 
     auto service = ipmi::getService(bus, interface, path);
 
@@ -90,7 +90,7 @@
                 {
                     if (propValue == value.second.assert)
                     {
-                        setOffset(value.first, &response);
+                        setOffset(value.first, response);
                         break;
                     }
                 }
@@ -114,7 +114,7 @@
     sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
     GetSensorResponse response{};
 
-    enableScanning(&response);
+    enableScanning(response);
 
     auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
                                     sensorInfo.sensorPath);
@@ -134,7 +134,7 @@
                 {
                     if (propValue == value.second.assert)
                     {
-                        setReading(value.first, &response);
+                        setReading(value.first, response);
                         break;
                     }
                 }
diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp
index 3d56971..c5dbcfc 100644
--- a/sensordatahandler.hpp
+++ b/sensordatahandler.hpp
@@ -175,7 +175,7 @@
     sdbusplus::bus_t bus{ipmid_get_sd_bus_connection()};
     GetSensorResponse response{};
 
-    enableScanning(&response);
+    enableScanning(response);
     try
     {
         auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
@@ -186,7 +186,7 @@
             sensorInfo.propertyInterfaces.begin()->second.begin()->first);
 
         setAssertionBytes(static_cast<uint16_t>(std::get<T>(propValue)),
-                          &response);
+                          response);
     }
     catch (const std::exception& e)
     {
@@ -214,7 +214,7 @@
 
     GetSensorResponse response{};
 
-    enableScanning(&response);
+    enableScanning(response);
 
     auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
                                     sensorInfo.sensorPath);
@@ -284,7 +284,7 @@
         maxClamp = std::numeric_limits<uint8_t>::max();
     }
     setReading(static_cast<uint8_t>(std::clamp(rawData, minClamp, maxClamp)),
-               &response);
+               response);
 
     if (!std::isfinite(value))
     {
@@ -391,7 +391,7 @@
     uint8_t id, const Info& sensorInfo, const PropertyMap& properties)
 {
     GetSensorResponse response{};
-    enableScanning(&response);
+    enableScanning(response);
 
     auto iter = properties.find(
         sensorInfo.propertyInterfaces.begin()->second.begin()->first);
@@ -401,7 +401,7 @@
     }
 
     setAssertionBytes(static_cast<uint16_t>(std::get<T>(iter->second)),
-                      &response);
+                      response);
 
     if (!sensorCacheMap[id].has_value())
     {
@@ -446,7 +446,7 @@
 
     GetSensorResponse response{};
 
-    enableScanning(&response);
+    enableScanning(response);
 
     iter = properties.find(
         sensorInfo.propertyInterfaces.begin()->second.begin()->first);
@@ -471,7 +471,7 @@
             lg2::error("Value out of range");
             throw std::out_of_range("Value out of range");
         }
-        setReading(static_cast<int8_t>(rawData), &response);
+        setReading(static_cast<int8_t>(rawData), response);
     }
     else
     {
@@ -481,7 +481,7 @@
             lg2::error("Value out of range");
             throw std::out_of_range("Value out of range");
         }
-        setReading(static_cast<uint8_t>(rawData), &response);
+        setReading(static_cast<uint8_t>(rawData), response);
     }
 
     if (!std::isfinite(value))
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index e641a93..f75160e 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -1078,39 +1078,39 @@
     return ipmi::responseSuccess(reservationID);
 }
 
-void setUnitFieldsForObject(const ipmi::sensor::Info* info,
-                            get_sdr::SensorDataFullRecordBody* body)
+void setUnitFieldsForObject(const ipmi::sensor::Info& info,
+                            get_sdr::SensorDataFullRecordBody& body)
 {
     namespace server = sdbusplus::server::xyz::openbmc_project::sensor;
-    body->sensor_units_1 = info->sensorUnits1; // default is 0. unsigned, no
-                                               // rate, no modifier, not a %
+    body.sensor_units_1 = info.sensorUnits1; // default is 0. unsigned, no rate,
+                                             // no modifier, not a %
     try
     {
-        auto unit = server::Value::convertUnitFromString(info->unit);
+        auto unit = server::Value::convertUnitFromString(info.unit);
         // Unit strings defined in
         // phosphor-dbus-interfaces/xyz/openbmc_project/Sensor/Value.interface.yaml
         switch (unit)
         {
             case server::Value::Unit::DegreesC:
-                body->sensor_units_2_base = get_sdr::SENSOR_UNIT_DEGREES_C;
+                body.sensor_units_2_base = get_sdr::SENSOR_UNIT_DEGREES_C;
                 break;
             case server::Value::Unit::RPMS:
-                body->sensor_units_2_base = get_sdr::SENSOR_UNIT_RPM;
+                body.sensor_units_2_base = get_sdr::SENSOR_UNIT_RPM;
                 break;
             case server::Value::Unit::Volts:
-                body->sensor_units_2_base = get_sdr::SENSOR_UNIT_VOLTS;
+                body.sensor_units_2_base = get_sdr::SENSOR_UNIT_VOLTS;
                 break;
             case server::Value::Unit::Meters:
-                body->sensor_units_2_base = get_sdr::SENSOR_UNIT_METERS;
+                body.sensor_units_2_base = get_sdr::SENSOR_UNIT_METERS;
                 break;
             case server::Value::Unit::Amperes:
-                body->sensor_units_2_base = get_sdr::SENSOR_UNIT_AMPERES;
+                body.sensor_units_2_base = get_sdr::SENSOR_UNIT_AMPERES;
                 break;
             case server::Value::Unit::Joules:
-                body->sensor_units_2_base = get_sdr::SENSOR_UNIT_JOULES;
+                body.sensor_units_2_base = get_sdr::SENSOR_UNIT_JOULES;
                 break;
             case server::Value::Unit::Watts:
-                body->sensor_units_2_base = get_sdr::SENSOR_UNIT_WATTS;
+                body.sensor_units_2_base = get_sdr::SENSOR_UNIT_WATTS;
                 break;
             case server::Value::Unit::Percent:
                 get_sdr::body::set_percentage(body);
@@ -1118,7 +1118,7 @@
             default:
                 // Cannot be hit.
                 std::fprintf(stderr, "Unknown value unit type: = %s\n",
-                             info->unit.c_str());
+                             info.unit.c_str());
         }
     }
     catch (const sdbusplus::exception::InvalidEnumString& e)
@@ -1127,27 +1127,27 @@
     }
 }
 
-ipmi::Cc populate_record_from_dbus(get_sdr::SensorDataFullRecordBody* body,
-                                   const ipmi::sensor::Info* info)
+ipmi::Cc populate_record_from_dbus(const ipmi::sensor::Info& info,
+                                   get_sdr::SensorDataFullRecordBody& body)
 {
     /* Functional sensor case */
-    if (isAnalogSensor(info->propertyInterfaces.begin()->first))
+    if (isAnalogSensor(info.propertyInterfaces.begin()->first))
     {
         /* Unit info */
         setUnitFieldsForObject(info, body);
 
-        get_sdr::body::set_b(info->coefficientB, body);
-        get_sdr::body::set_m(info->coefficientM, body);
-        get_sdr::body::set_b_exp(info->exponentB, body);
-        get_sdr::body::set_r_exp(info->exponentR, body);
+        get_sdr::body::set_b(info.coefficientB, body);
+        get_sdr::body::set_m(info.coefficientM, body);
+        get_sdr::body::set_b_exp(info.exponentB, body);
+        get_sdr::body::set_r_exp(info.exponentR, body);
     }
 
     /* ID string */
-    auto id_string = info->sensorName;
+    auto id_string = info.sensorName;
 
     if (id_string.empty())
     {
-        id_string = info->sensorNameFunc(*info);
+        id_string = info.sensorNameFunc(info);
     }
 
     if (id_string.length() > FULL_RECORD_ID_STR_MAX_LENGTH)
@@ -1159,7 +1159,7 @@
         get_sdr::body::set_id_strlen(id_string.length(), body);
     }
     get_sdr::body::set_id_type(3, body); // "8-bit ASCII + Latin 1"
-    strncpy(body->id_string, id_string.c_str(),
+    strncpy(body.id_string, id_string.c_str(),
             get_sdr::body::get_id_strlen(body));
 
     return ipmi::ccSuccess;
@@ -1206,16 +1206,16 @@
     if (deviceID.length() > get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH)
     {
         get_sdr::body::set_device_id_strlen(
-            get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH, &(record.body));
+            get_sdr::FRU_RECORD_DEVICE_ID_MAX_LENGTH, record.body);
     }
     else
     {
-        get_sdr::body::set_device_id_strlen(deviceID.length(), &(record.body));
+        get_sdr::body::set_device_id_strlen(deviceID.length(), record.body);
     }
 
     uint16_t nextRecordId{};
     strncpy(record.body.deviceID, deviceID.c_str(),
-            get_sdr::body::get_device_id_strlen(&(record.body)));
+            get_sdr::body::get_device_id_strlen(record.body));
 
     if (++fru == frus.end())
     {
@@ -1279,7 +1279,7 @@
     record.key.containerEntityId = entity->second.containerEntityId;
     record.key.containerEntityInstance = entity->second.containerEntityInstance;
     get_sdr::key::set_flags(entity->second.isList, entity->second.isLinked,
-                            &(record.key));
+                            record.key);
     record.key.entityId1 = entity->second.containedEntities[0].first;
     record.key.entityInstance1 = entity->second.containedEntities[0].second;
 
@@ -1367,7 +1367,7 @@
         record.header.record_length = sizeof(record.key) + sizeof(record.body);
 
         /* Key */
-        get_sdr::key::set_owner_id_bmc(&(record.key));
+        get_sdr::key::set_owner_id_bmc(record.key);
         record.key.sensor_number = sensor_id;
 
         /* Body */
@@ -1378,11 +1378,11 @@
         if (ipmi::sensor::Mutability::Write ==
             (sensor->second.mutability & ipmi::sensor::Mutability::Write))
         {
-            get_sdr::body::init_settable_state(true, &(record.body));
+            get_sdr::body::init_settable_state(true, record.body);
         }
 
         // Set the type-specific details given the DBus interface
-        populate_record_from_dbus(&(record.body), &(sensor->second));
+        populate_record_from_dbus(sensor->second, record.body);
         sdrCacheMap[sensor_id] = std::move(record);
     }
 
diff --git a/sensorhandler.hpp b/sensorhandler.hpp
index b67dfa6..693ab96 100644
--- a/sensorhandler.hpp
+++ b/sensorhandler.hpp
@@ -149,48 +149,52 @@
 static constexpr uint8_t listOrRangeBit = 7;
 static constexpr uint8_t linkedBit = 6;
 
-inline void set_owner_id_ipmb(SensorDataRecordKey* key)
+inline void set_owner_id_ipmb(SensorDataRecordKey& key)
 {
-    key->owner_id &= ~0x01;
+    key.owner_id &= ~0x01;
 };
 
-inline void set_owner_id_system_sw(SensorDataRecordKey* key)
+inline void set_owner_id_system_sw(SensorDataRecordKey& key)
 {
-    key->owner_id |= 0x01;
+    key.owner_id |= 0x01;
 };
 
-inline void set_owner_id_bmc(SensorDataRecordKey* key)
+inline void set_owner_id_bmc(SensorDataRecordKey& key)
 {
-    key->owner_id |= 0x20;
+    key.owner_id |= 0x20;
 };
 
-inline void set_owner_id_address(uint8_t addr, SensorDataRecordKey* key)
+inline void set_owner_id_address(uint8_t addr, SensorDataRecordKey& key)
 {
-    key->owner_id &= 0x01;
-    key->owner_id |= addr << 1;
+    key.owner_id &= 0x01;
+    key.owner_id |= addr << 1;
 };
 
-inline void set_owner_lun(uint8_t lun, SensorDataRecordKey* key)
+inline void set_owner_lun(uint8_t lun, SensorDataRecordKey& key)
 {
-    key->owner_lun &= ~0x03;
-    key->owner_lun |= (lun & 0x03);
+    key.owner_lun &= ~0x03;
+    key.owner_lun |= (lun & 0x03);
 };
 
-inline void set_owner_lun_channel(uint8_t channel, SensorDataRecordKey* key)
+inline void set_owner_lun_channel(uint8_t channel, SensorDataRecordKey& key)
 {
-    key->owner_lun &= 0x0f;
-    key->owner_lun |= ((channel & 0xf) << 4);
+    key.owner_lun &= 0x0f;
+    key.owner_lun |= ((channel & 0xf) << 4);
 };
 
 inline void set_flags(bool isList, bool isLinked,
-                      SensorDataEntityRecordKey* key)
+                      SensorDataEntityRecordKey& key)
 {
-    key->flags = 0x00;
+    key.flags = 0x00;
     if (!isList)
-        key->flags |= 1 << listOrRangeBit;
+    {
+        key.flags |= 1 << listOrRangeBit;
+    }
 
     if (isLinked)
-        key->flags |= 1 << linkedBit;
+    {
+        key.flags |= 1 << linkedBit;
+    }
 };
 
 } // namespace key
@@ -335,222 +339,244 @@
 {
 
 inline void set_entity_instance_number(uint8_t n,
-                                       SensorDataFullRecordBody* body)
+                                       SensorDataFullRecordBody& body)
 {
-    body->entity_instance &= 1 << 7;
-    body->entity_instance |= (n & ~(1 << 7));
-};
-inline void set_entity_physical_entity(SensorDataFullRecordBody* body)
-{
-    body->entity_instance &= ~(1 << 7);
-};
-inline void set_entity_logical_container(SensorDataFullRecordBody* body)
-{
-    body->entity_instance |= 1 << 7;
+    body.entity_instance &= 1 << 7;
+    body.entity_instance |= (n & ~(1 << 7));
 };
 
-inline void sensor_scanning_state(bool enabled, SensorDataFullRecordBody* body)
+inline void set_entity_physical_entity(SensorDataFullRecordBody& body)
+{
+    body.entity_instance &= ~(1 << 7);
+};
+
+inline void set_entity_logical_container(SensorDataFullRecordBody& body)
+{
+    body.entity_instance |= 1 << 7;
+};
+
+inline void sensor_scanning_state(bool enabled, SensorDataFullRecordBody& body)
 {
     if (enabled)
     {
-        body->sensor_initialization |= 1 << 0;
+        body.sensor_initialization |= 1 << 0;
     }
     else
     {
-        body->sensor_initialization &= ~(1 << 0);
+        body.sensor_initialization &= ~(1 << 0);
     };
 };
-inline void event_generation_state(bool enabled, SensorDataFullRecordBody* body)
+
+inline void event_generation_state(bool enabled, SensorDataFullRecordBody& body)
 {
     if (enabled)
     {
-        body->sensor_initialization |= 1 << 1;
+        body.sensor_initialization |= 1 << 1;
     }
     else
     {
-        body->sensor_initialization &= ~(1 << 1);
-    }
-};
-inline void init_types_state(bool enabled, SensorDataFullRecordBody* body)
-{
-    if (enabled)
-    {
-        body->sensor_initialization |= 1 << 2;
-    }
-    else
-    {
-        body->sensor_initialization &= ~(1 << 2);
-    }
-};
-inline void init_hyst_state(bool enabled, SensorDataFullRecordBody* body)
-{
-    if (enabled)
-    {
-        body->sensor_initialization |= 1 << 3;
-    }
-    else
-    {
-        body->sensor_initialization &= ~(1 << 3);
-    }
-};
-inline void init_thresh_state(bool enabled, SensorDataFullRecordBody* body)
-{
-    if (enabled)
-    {
-        body->sensor_initialization |= 1 << 4;
-    }
-    else
-    {
-        body->sensor_initialization &= ~(1 << 4);
-    }
-};
-inline void init_events_state(bool enabled, SensorDataFullRecordBody* body)
-{
-    if (enabled)
-    {
-        body->sensor_initialization |= 1 << 5;
-    }
-    else
-    {
-        body->sensor_initialization &= ~(1 << 5);
-    }
-};
-inline void init_scanning_state(bool enabled, SensorDataFullRecordBody* body)
-{
-    if (enabled)
-    {
-        body->sensor_initialization |= 1 << 6;
-    }
-    else
-    {
-        body->sensor_initialization &= ~(1 << 6);
-    }
-};
-inline void init_settable_state(bool enabled, SensorDataFullRecordBody* body)
-{
-    if (enabled)
-    {
-        body->sensor_initialization |= 1 << 7;
-    }
-    else
-    {
-        body->sensor_initialization &= ~(1 << 7);
+        body.sensor_initialization &= ~(1 << 1);
     }
 };
 
-inline void set_percentage(SensorDataFullRecordBody* body)
+inline void init_types_state(bool enabled, SensorDataFullRecordBody& body)
 {
-    body->sensor_units_1 |= 1 << 0;
+    if (enabled)
+    {
+        body.sensor_initialization |= 1 << 2;
+    }
+    else
+    {
+        body.sensor_initialization &= ~(1 << 2);
+    }
 };
-inline void unset_percentage(SensorDataFullRecordBody* body)
+
+inline void init_hyst_state(bool enabled, SensorDataFullRecordBody& body)
 {
-    body->sensor_units_1 &= ~(1 << 0);
+    if (enabled)
+    {
+        body.sensor_initialization |= 1 << 3;
+    }
+    else
+    {
+        body.sensor_initialization &= ~(1 << 3);
+    }
 };
-inline void set_modifier_operation(uint8_t op, SensorDataFullRecordBody* body)
+
+inline void init_thresh_state(bool enabled, SensorDataFullRecordBody& body)
 {
-    body->sensor_units_1 &= ~(3 << 1);
-    body->sensor_units_1 |= (op & 0x3) << 1;
+    if (enabled)
+    {
+        body.sensor_initialization |= 1 << 4;
+    }
+    else
+    {
+        body.sensor_initialization &= ~(1 << 4);
+    }
 };
-inline void set_rate_unit(uint8_t unit, SensorDataFullRecordBody* body)
+
+inline void init_events_state(bool enabled, SensorDataFullRecordBody& body)
 {
-    body->sensor_units_1 &= ~(7 << 3);
-    body->sensor_units_1 |= (unit & 0x7) << 3;
+    if (enabled)
+    {
+        body.sensor_initialization |= 1 << 5;
+    }
+    else
+    {
+        body.sensor_initialization &= ~(1 << 5);
+    }
 };
+
+inline void init_scanning_state(bool enabled, SensorDataFullRecordBody& body)
+{
+    if (enabled)
+    {
+        body.sensor_initialization |= 1 << 6;
+    }
+    else
+    {
+        body.sensor_initialization &= ~(1 << 6);
+    }
+};
+
+inline void init_settable_state(bool enabled, SensorDataFullRecordBody& body)
+{
+    if (enabled)
+    {
+        body.sensor_initialization |= 1 << 7;
+    }
+    else
+    {
+        body.sensor_initialization &= ~(1 << 7);
+    }
+};
+
+inline void set_percentage(SensorDataFullRecordBody& body)
+{
+    body.sensor_units_1 |= 1 << 0;
+};
+
+inline void unset_percentage(SensorDataFullRecordBody& body)
+{
+    body.sensor_units_1 &= ~(1 << 0);
+};
+
+inline void set_modifier_operation(uint8_t op, SensorDataFullRecordBody& body)
+{
+    body.sensor_units_1 &= ~(3 << 1);
+    body.sensor_units_1 |= (op & 0x3) << 1;
+};
+
+inline void set_rate_unit(uint8_t unit, SensorDataFullRecordBody& body)
+{
+    body.sensor_units_1 &= ~(7 << 3);
+    body.sensor_units_1 |= (unit & 0x7) << 3;
+};
+
 inline void set_analog_data_format(uint8_t format,
-                                   SensorDataFullRecordBody* body)
+                                   SensorDataFullRecordBody& body)
 {
-    body->sensor_units_1 &= ~(3 << 6);
-    body->sensor_units_1 |= (format & 0x3) << 6;
+    body.sensor_units_1 &= ~(3 << 6);
+    body.sensor_units_1 |= (format & 0x3) << 6;
 };
 
-inline void set_m(uint16_t m, SensorDataFullRecordBody* body)
+inline void set_m(uint16_t m, SensorDataFullRecordBody& body)
 {
-    body->m_lsb = m & 0xff;
-    body->m_msb_and_tolerance &= ~(3 << 6);
-    body->m_msb_and_tolerance |= ((m & (3 << 8)) >> 2);
-};
-inline void set_tolerance(uint8_t tol, SensorDataFullRecordBody* body)
-{
-    body->m_msb_and_tolerance &= ~0x3f;
-    body->m_msb_and_tolerance |= tol & 0x3f;
+    body.m_lsb = m & 0xff;
+    body.m_msb_and_tolerance &= ~(3 << 6);
+    body.m_msb_and_tolerance |= ((m & (3 << 8)) >> 2);
 };
 
-inline void set_b(uint16_t b, SensorDataFullRecordBody* body)
+inline void set_tolerance(uint8_t tol, SensorDataFullRecordBody& body)
 {
-    body->b_lsb = b & 0xff;
-    body->b_msb_and_accuracy_lsb &= ~(3 << 6);
-    body->b_msb_and_accuracy_lsb |= ((b & (3 << 8)) >> 2);
+    body.m_msb_and_tolerance &= ~0x3f;
+    body.m_msb_and_tolerance |= tol & 0x3f;
 };
-inline void set_accuracy(uint16_t acc, SensorDataFullRecordBody* body)
+
+inline void set_b(uint16_t b, SensorDataFullRecordBody& body)
+{
+    body.b_lsb = b & 0xff;
+    body.b_msb_and_accuracy_lsb &= ~(3 << 6);
+    body.b_msb_and_accuracy_lsb |= ((b & (3 << 8)) >> 2);
+};
+
+inline void set_accuracy(uint16_t acc, SensorDataFullRecordBody& body)
 {
     // bottom 6 bits
-    body->b_msb_and_accuracy_lsb &= ~0x3f;
-    body->b_msb_and_accuracy_lsb |= acc & 0x3f;
+    body.b_msb_and_accuracy_lsb &= ~0x3f;
+    body.b_msb_and_accuracy_lsb |= acc & 0x3f;
     // top 4 bits
-    body->accuracy_and_sensor_direction &= 0x0f;
-    body->accuracy_and_sensor_direction |= ((acc >> 6) & 0xf) << 4;
-};
-inline void set_accuracy_exp(uint8_t exp, SensorDataFullRecordBody* body)
-{
-    body->accuracy_and_sensor_direction &= ~(3 << 2);
-    body->accuracy_and_sensor_direction |= (exp & 3) << 2;
-};
-inline void set_sensor_dir(uint8_t dir, SensorDataFullRecordBody* body)
-{
-    body->accuracy_and_sensor_direction &= ~(3 << 0);
-    body->accuracy_and_sensor_direction |= (dir & 3);
+    body.accuracy_and_sensor_direction &= 0x0f;
+    body.accuracy_and_sensor_direction |= ((acc >> 6) & 0xf) << 4;
 };
 
-inline void set_b_exp(uint8_t exp, SensorDataFullRecordBody* body)
+inline void set_accuracy_exp(uint8_t exp, SensorDataFullRecordBody& body)
 {
-    body->r_b_exponents &= 0xf0;
-    body->r_b_exponents |= exp & 0x0f;
-};
-inline void set_r_exp(uint8_t exp, SensorDataFullRecordBody* body)
-{
-    body->r_b_exponents &= 0x0f;
-    body->r_b_exponents |= (exp & 0x0f) << 4;
+    body.accuracy_and_sensor_direction &= ~(3 << 2);
+    body.accuracy_and_sensor_direction |= (exp & 3) << 2;
 };
 
-inline void set_id_strlen(uint8_t len, SensorDataFullRecordBody* body)
+inline void set_sensor_dir(uint8_t dir, SensorDataFullRecordBody& body)
 {
-    body->id_string_info &= ~(0x1f);
-    body->id_string_info |= len & 0x1f;
-};
-inline void set_id_strlen(uint8_t len, SensorDataEventRecordBody* body)
-{
-    body->id_string_info &= ~(0x1f);
-    body->id_string_info |= len & 0x1f;
-};
-inline uint8_t get_id_strlen(SensorDataFullRecordBody* body)
-{
-    return body->id_string_info & 0x1f;
-};
-inline void set_id_type(uint8_t type, SensorDataFullRecordBody* body)
-{
-    body->id_string_info &= ~(3 << 6);
-    body->id_string_info |= (type & 0x3) << 6;
-};
-inline void set_id_type(uint8_t type, SensorDataEventRecordBody* body)
-{
-    body->id_string_info &= ~(3 << 6);
-    body->id_string_info |= (type & 0x3) << 6;
+    body.accuracy_and_sensor_direction &= ~(3 << 0);
+    body.accuracy_and_sensor_direction |= (dir & 3);
 };
 
-inline void set_device_id_strlen(uint8_t len, SensorDataFruRecordBody* body)
+inline void set_b_exp(uint8_t exp, SensorDataFullRecordBody& body)
 {
-    body->deviceIDLen &= ~(LENGTH_MASK);
-    body->deviceIDLen |= len & LENGTH_MASK;
+    body.r_b_exponents &= 0xf0;
+    body.r_b_exponents |= exp & 0x0f;
 };
 
-inline uint8_t get_device_id_strlen(SensorDataFruRecordBody* body)
+inline void set_r_exp(uint8_t exp, SensorDataFullRecordBody& body)
 {
-    return body->deviceIDLen & LENGTH_MASK;
+    body.r_b_exponents &= 0x0f;
+    body.r_b_exponents |= (exp & 0x0f) << 4;
 };
 
-inline void set_readable_mask(uint8_t mask, SensorDataFullRecordBody* body)
+inline void set_id_strlen(uint8_t len, SensorDataFullRecordBody& body)
 {
-    body->discrete_reading_setting_mask[1] = mask & 0x3F;
+    body.id_string_info &= ~(0x1f);
+    body.id_string_info |= len & 0x1f;
+};
+
+inline void set_id_strlen(uint8_t len, SensorDataEventRecordBody& body)
+{
+    body.id_string_info &= ~(0x1f);
+    body.id_string_info |= len & 0x1f;
+};
+
+inline uint8_t get_id_strlen(const SensorDataFullRecordBody& body)
+{
+    return body.id_string_info & 0x1f;
+};
+
+inline void set_id_type(uint8_t type, SensorDataFullRecordBody& body)
+{
+    body.id_string_info &= ~(3 << 6);
+    body.id_string_info |= (type & 0x3) << 6;
+};
+
+inline void set_id_type(uint8_t type, SensorDataEventRecordBody& body)
+{
+    body.id_string_info &= ~(3 << 6);
+    body.id_string_info |= (type & 0x3) << 6;
+};
+
+inline void set_device_id_strlen(uint8_t len, SensorDataFruRecordBody& body)
+{
+    body.deviceIDLen &= ~(LENGTH_MASK);
+    body.deviceIDLen |= len & LENGTH_MASK;
+};
+
+inline uint8_t get_device_id_strlen(const SensorDataFruRecordBody& body)
+{
+    return body.deviceIDLen & LENGTH_MASK;
+};
+
+inline void set_readable_mask(uint8_t mask, SensorDataFullRecordBody& body)
+{
+    body.discrete_reading_setting_mask[1] = mask & 0x3F;
 }
 
 } // namespace body
@@ -638,15 +664,15 @@
  * @param[in] offset - offset number.
  * @param[in/out] resp - get sensor reading response.
  */
-inline void setOffset(uint8_t offset, ipmi::sensor::GetSensorResponse* resp)
+inline void setOffset(uint8_t offset, ipmi::sensor::GetSensorResponse& resp)
 {
     if (offset > 7)
     {
-        resp->discreteReadingSensorStates |= 1 << (offset - 8);
+        resp.discreteReadingSensorStates |= 1 << (offset - 8);
     }
     else
     {
-        resp->thresholdLevelsStates |= 1 << offset;
+        resp.thresholdLevelsStates |= 1 << offset;
     }
 }
 
@@ -656,9 +682,9 @@
  * @param[in] offset - offset number.
  * @param[in/out] resp - get sensor reading response.
  */
-inline void setReading(uint8_t value, ipmi::sensor::GetSensorResponse* resp)
+inline void setReading(uint8_t value, ipmi::sensor::GetSensorResponse& resp)
 {
-    resp->reading = value;
+    resp.reading = value;
 }
 
 /**
@@ -669,10 +695,10 @@
  * @param[in/out] resp - get sensor reading response.
  */
 inline void setAssertionBytes(uint16_t value,
-                              ipmi::sensor::GetSensorResponse* resp)
+                              ipmi::sensor::GetSensorResponse& resp)
 {
-    resp->thresholdLevelsStates = static_cast<uint8_t>(value & 0x00FF);
-    resp->discreteReadingSensorStates = static_cast<uint8_t>(value >> 8);
+    resp.thresholdLevelsStates = static_cast<uint8_t>(value & 0x00FF);
+    resp.discreteReadingSensorStates = static_cast<uint8_t>(value >> 8);
 }
 
 /**
@@ -680,11 +706,11 @@
  *
  * @param[in/out] resp - get sensor reading response.
  */
-inline void enableScanning(ipmi::sensor::GetSensorResponse* resp)
+inline void enableScanning(ipmi::sensor::GetSensorResponse& resp)
 {
-    resp->readingOrStateUnavailable = false;
-    resp->scanningEnabled = true;
-    resp->allEventMessagesEnabled = false;
+    resp.readingOrStateUnavailable = false;
+    resp.scanningEnabled = true;
+    resp.allEventMessagesEnabled = false;
 }
 
 } // namespace sensor