Skip to content

Commit

Permalink
Add GetRemainingFreeLength API (#5009)
Browse files Browse the repository at this point in the history
Problems:
we need GetRemainingFreeLength to check the remaning length of tlv
buffer in im eventing feature.

SummaryOfChanges:
-- Add GetRemainingFreeLength to get the total remaining number of bytes
for current tlv writer.
  • Loading branch information
yunhanw-google authored Feb 27, 2021
1 parent 7093fde commit 8997367
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/core/CHIPTLV.h
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,12 @@ class DLL_EXPORT TLVWriter
*/
uint32_t GetLengthWritten() const { return mLenWritten; }

/**
* Returns the total remaining number of bytes for current tlv writer
*
* @return the total remaining number of bytes.
*/
uint32_t GetRemainingFreeLength() const { return mRemainingLen; }
/**
* The profile id of tags that should be encoded in implicit form.
*
Expand Down Expand Up @@ -2202,7 +2208,6 @@ class DLL_EXPORT TLVBackingStore
{
public:
virtual ~TLVBackingStore() {}

/**
* A function to provide a backing store's initial start position and data length to a reader.
*
Expand Down
4 changes: 4 additions & 0 deletions src/lib/core/tests/TestCHIPTLV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,10 +1344,14 @@ void CheckSimpleWriteRead(nlTestSuite * inSuite, void * inContext)
uint8_t buf[2048];
TLVWriter writer;
TLVReader reader;
uint32_t remainingFreedLen;

writer.Init(buf, sizeof(buf));
writer.ImplicitProfileId = TestProfile_2;

remainingFreedLen = writer.GetRemainingFreeLength();
NL_TEST_ASSERT(inSuite, sizeof(buf) == remainingFreedLen);

WriteEncoding1(inSuite, writer);

uint32_t encodedLen = writer.GetLengthWritten();
Expand Down

0 comments on commit 8997367

Please sign in to comment.