* CommonCLI: added "get/set path.hash.mode "

This commit is contained in:
Scott Powell
2026-02-23 14:25:19 +11:00
parent 05e7b682b9
commit a66773bac0
8 changed files with 49 additions and 18 deletions

View File

@@ -10,14 +10,27 @@ Packet::Packet() {
payload_len = 0;
}
uint8_t Packet::copyPath(uint8_t* dest, const uint8_t* src, uint8_t path_len) {
bool Packet::isValidPathLen(uint8_t path_len) {
uint8_t hash_count = path_len & 63;
uint8_t hash_size = (path_len >> 6) + 1;
if (hash_count*hash_size > MAX_PATH_SIZE) {
if (hash_size == 4) return false; // Reserved for future
return hash_count*hash_size <= MAX_PATH_SIZE;
}
size_t Packet::writePath(uint8_t* dest, const uint8_t* src, uint8_t path_len) {
uint8_t hash_count = path_len & 63;
uint8_t hash_size = (path_len >> 6) + 1;
size_t len = hash_count*hash_size;
if (len > MAX_PATH_SIZE) {
MESH_DEBUG_PRINTLN("Packet::copyPath, invalid path_len=%d", (uint32_t)path_len);
return 0; // Error
}
memcpy(dest, src, hash_count*hash_size);
memcpy(dest, src, len);
return len;
}
uint8_t Packet::copyPath(uint8_t* dest, const uint8_t* src, uint8_t path_len) {
if (writePath(dest, src, path_len) == 0) return 0;
return path_len;
}