Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some const to TLVReader get methods #28167

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/lib/core/TLVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ uint32_t TLVReader::GetLength() const
return 0;
}

CHIP_ERROR TLVReader::Get(bool & v)
CHIP_ERROR TLVReader::Get(bool & v) const
{
TLVElementType elemType = ElementType();
if (elemType == TLVElementType::BooleanFalse)
Expand All @@ -129,7 +129,7 @@ CHIP_ERROR TLVReader::Get(bool & v)
return CHIP_NO_ERROR;
}

CHIP_ERROR TLVReader::Get(int8_t & v)
CHIP_ERROR TLVReader::Get(int8_t & v) const
{
int64_t v64 = 0;
CHIP_ERROR err = Get(v64);
Expand All @@ -141,7 +141,7 @@ CHIP_ERROR TLVReader::Get(int8_t & v)
return err;
}

CHIP_ERROR TLVReader::Get(int16_t & v)
CHIP_ERROR TLVReader::Get(int16_t & v) const
{
int64_t v64 = 0;
CHIP_ERROR err = Get(v64);
Expand All @@ -153,7 +153,7 @@ CHIP_ERROR TLVReader::Get(int16_t & v)
return err;
}

CHIP_ERROR TLVReader::Get(int32_t & v)
CHIP_ERROR TLVReader::Get(int32_t & v) const
{
int64_t v64 = 0;
CHIP_ERROR err = Get(v64);
Expand All @@ -165,7 +165,7 @@ CHIP_ERROR TLVReader::Get(int32_t & v)
return err;
}

CHIP_ERROR TLVReader::Get(int64_t & v)
CHIP_ERROR TLVReader::Get(int64_t & v) const
{
// Internal callers of this method depend on it not modifying "v" on failure.
switch (ElementType())
Expand All @@ -189,7 +189,7 @@ CHIP_ERROR TLVReader::Get(int64_t & v)
return CHIP_NO_ERROR;
}

CHIP_ERROR TLVReader::Get(uint8_t & v)
CHIP_ERROR TLVReader::Get(uint8_t & v) const
{
uint64_t v64 = 0;
CHIP_ERROR err = Get(v64);
Expand All @@ -201,7 +201,7 @@ CHIP_ERROR TLVReader::Get(uint8_t & v)
return err;
}

CHIP_ERROR TLVReader::Get(uint16_t & v)
CHIP_ERROR TLVReader::Get(uint16_t & v) const
{
uint64_t v64 = 0;
CHIP_ERROR err = Get(v64);
Expand All @@ -213,7 +213,7 @@ CHIP_ERROR TLVReader::Get(uint16_t & v)
return err;
}

CHIP_ERROR TLVReader::Get(uint32_t & v)
CHIP_ERROR TLVReader::Get(uint32_t & v) const
{
uint64_t v64 = 0;
CHIP_ERROR err = Get(v64);
Expand All @@ -225,7 +225,7 @@ CHIP_ERROR TLVReader::Get(uint32_t & v)
return err;
}

CHIP_ERROR TLVReader::Get(uint64_t & v)
CHIP_ERROR TLVReader::Get(uint64_t & v) const
{
// Internal callers of this method depend on it not modifying "v" on failure.
switch (ElementType())
Expand Down Expand Up @@ -256,7 +256,7 @@ float BitCastToFloat(const uint64_t elemLenOrVal)
// between float and double wherever possible, because these conversions are
// relatively expensive on platforms that use soft-float instruction sets.

CHIP_ERROR TLVReader::Get(float & v)
CHIP_ERROR TLVReader::Get(float & v) const
{
switch (ElementType())
{
Expand All @@ -270,7 +270,7 @@ CHIP_ERROR TLVReader::Get(float & v)
return CHIP_NO_ERROR;
}

CHIP_ERROR TLVReader::Get(double & v)
CHIP_ERROR TLVReader::Get(double & v) const
{
switch (ElementType())
{
Expand Down
23 changes: 11 additions & 12 deletions src/lib/core/TLVReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <lib/core/Optional.h>

#include "TLVCommon.h"

#include "TLVWriter.h"

/**
Expand Down Expand Up @@ -283,7 +282,7 @@ class DLL_EXPORT TLVReader
* @retval #CHIP_ERROR_WRONG_TLV_TYPE If the current element is not a TLV boolean type, or the
* reader is not positioned on an element.
*/
CHIP_ERROR Get(bool & v);
CHIP_ERROR Get(bool & v) const;

/**
* Get the value of the current element as an 8-bit signed integer.
Expand All @@ -298,7 +297,7 @@ class DLL_EXPORT TLVReader
* unsigned), or the reader is not positioned on an element.
*
*/
CHIP_ERROR Get(int8_t & v);
CHIP_ERROR Get(int8_t & v) const;

/**
* Get the value of the current element as a 16-bit signed integer.
Expand All @@ -313,7 +312,7 @@ class DLL_EXPORT TLVReader
* unsigned), or the reader is not positioned on an element.
*
*/
CHIP_ERROR Get(int16_t & v);
CHIP_ERROR Get(int16_t & v) const;

/**
* Get the value of the current element as a 32-bit signed integer.
Expand All @@ -328,7 +327,7 @@ class DLL_EXPORT TLVReader
* unsigned), or the reader is not positioned on an element.
*
*/
CHIP_ERROR Get(int32_t & v);
CHIP_ERROR Get(int32_t & v) const;

/**
* Get the value of the current element as a 64-bit signed integer.
Expand All @@ -343,7 +342,7 @@ class DLL_EXPORT TLVReader
* unsigned), or the reader is not positioned on an element.
*
*/
CHIP_ERROR Get(int64_t & v);
CHIP_ERROR Get(int64_t & v) const;

/**
* Get the value of the current element as an 8-bit unsigned integer.
Expand All @@ -359,7 +358,7 @@ class DLL_EXPORT TLVReader
* unsigned), or the reader is not positioned on an element.
*
*/
CHIP_ERROR Get(uint8_t & v);
CHIP_ERROR Get(uint8_t & v) const;

/**
* Get the value of the current element as a 16-bit unsigned integer.
Expand All @@ -375,7 +374,7 @@ class DLL_EXPORT TLVReader
* unsigned), or the reader is not positioned on an element.
*
*/
CHIP_ERROR Get(uint16_t & v);
CHIP_ERROR Get(uint16_t & v) const;

/**
* Get the value of the current element as a 32-bit unsigned integer.
Expand All @@ -391,7 +390,7 @@ class DLL_EXPORT TLVReader
unsigned), or the reader is not positioned on an element.
*
*/
CHIP_ERROR Get(uint32_t & v);
CHIP_ERROR Get(uint32_t & v) const;

/**
* Get the value of the current element as a 64-bit unsigned integer.
Expand All @@ -405,7 +404,7 @@ class DLL_EXPORT TLVReader
* unsigned), or the reader is not positioned on an element.
*
*/
CHIP_ERROR Get(uint64_t & v);
CHIP_ERROR Get(uint64_t & v) const;

/**
* Get the value of the current element as a double-precision floating point number.
Expand All @@ -417,7 +416,7 @@ class DLL_EXPORT TLVReader
* the reader is not positioned on an element.
*
*/
CHIP_ERROR Get(double & v);
CHIP_ERROR Get(double & v) const;

/**
* Get the value of the current element as a single-precision floating point number.
Expand All @@ -429,7 +428,7 @@ class DLL_EXPORT TLVReader
* the reader is not positioned on an element.
*
*/
CHIP_ERROR Get(float & v);
CHIP_ERROR Get(float & v) const;

/**
* Get the value of the current element as a ByteSpan
Expand Down