-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename
src/util/message.cpp
to src/util/strings.cpp
and add appro…
…priate headers (#32379) * Move things from message, update dependencies * Fix lint * Restyle * Remove wrongly copied comment * Add another dependency * Vendor identifiers is not orphaned anymore * Move strings to ember-strings to not have overlap in names * Add include for the cpp file into its own header * Standard ordering for attribute metadata cpp * Update darwin framework xcode file * Also move the copy string functions into ember strings. header af.h and implementation in util.cpp makes no sense
- Loading branch information
Showing
21 changed files
with
199 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <app/util/attribute-metadata.h> | ||
|
||
#include <app-common/zap-generated/attribute-type.h> | ||
|
||
bool emberAfIsStringAttributeType(EmberAfAttributeType attributeType) | ||
{ | ||
return (attributeType == ZCL_OCTET_STRING_ATTRIBUTE_TYPE || attributeType == ZCL_CHAR_STRING_ATTRIBUTE_TYPE); | ||
} | ||
|
||
bool emberAfIsLongStringAttributeType(EmberAfAttributeType attributeType) | ||
{ | ||
return (attributeType == ZCL_LONG_OCTET_STRING_ATTRIBUTE_TYPE || attributeType == ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* | ||
* Copyright (c) 2020 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <app/util/ember-strings.h> | ||
|
||
#include <lib/core/CHIPEncoding.h> | ||
|
||
using namespace chip; | ||
|
||
uint8_t emberAfStringLength(const uint8_t * buffer) | ||
{ | ||
// The first byte specifies the length of the string. A length of 0xFF means | ||
// the string is invalid and there is no character data. | ||
return (buffer[0] == 0xFF ? 0 : buffer[0]); | ||
} | ||
|
||
uint16_t emberAfLongStringLength(const uint8_t * buffer) | ||
{ | ||
// The first two bytes specify the length of the long string. A length of | ||
// 0xFFFF means the string is invalid and there is no character data. | ||
uint16_t length = Encoding::LittleEndian::Get16(buffer); | ||
return (length == 0xFFFF ? 0 : length); | ||
} | ||
|
||
void emberAfCopyString(uint8_t * dest, const uint8_t * src, size_t size) | ||
{ | ||
if (src == nullptr) | ||
{ | ||
dest[0] = 0; // Zero out the length of string | ||
} | ||
else if (src[0] == 0xFF) | ||
{ | ||
dest[0] = src[0]; | ||
} | ||
else | ||
{ | ||
uint8_t length = emberAfStringLength(src); | ||
if (size < length) | ||
{ | ||
// Since we have checked that size < length, size must be able to fit into the type of length. | ||
length = static_cast<decltype(length)>(size); | ||
} | ||
memmove(dest + 1, src + 1, length); | ||
dest[0] = length; | ||
} | ||
} | ||
|
||
void emberAfCopyLongString(uint8_t * dest, const uint8_t * src, size_t size) | ||
{ | ||
if (src == nullptr) | ||
{ | ||
dest[0] = dest[1] = 0; // Zero out the length of string | ||
} | ||
else if ((src[0] == 0xFF) && (src[1] == 0xFF)) | ||
{ | ||
dest[0] = 0xFF; | ||
dest[1] = 0xFF; | ||
} | ||
else | ||
{ | ||
uint16_t length = emberAfLongStringLength(src); | ||
if (size < length) | ||
{ | ||
// Since we have checked that size < length, size must be able to fit into the type of length. | ||
length = static_cast<decltype(length)>(size); | ||
} | ||
memmove(dest + 2, src + 2, length); | ||
Encoding::LittleEndian::Put16(dest, length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include <cstddef> | ||
#include <cstdint> | ||
|
||
/* | ||
* @brief Function that determines the length of a zigbee Cluster Library string | ||
* (where the first byte is assumed to be the length). | ||
*/ | ||
uint8_t emberAfStringLength(const uint8_t * buffer); | ||
/* | ||
* @brief Function that determines the length of a zigbee Cluster Library long string. | ||
* (where the first two bytes are assumed to be the length). | ||
*/ | ||
uint16_t emberAfLongStringLength(const uint8_t * buffer); | ||
|
||
/* | ||
* @brief Function that copies a ZCL string type into a buffer. The size | ||
* parameter should indicate the maximum number of characters to copy to the | ||
* destination buffer not including the length byte. | ||
*/ | ||
void emberAfCopyString(uint8_t * dest, const uint8_t * src, size_t size); | ||
|
||
/* | ||
* @brief Function that copies a ZCL long string into a buffer. The size | ||
* parameter should indicate the maximum number of characters to copy to the | ||
* destination buffer not including the length bytes. | ||
*/ | ||
void emberAfCopyLongString(uint8_t * dest, const uint8_t * src, size_t size); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.