Skip to content

Commit 8d5eaf5

Browse files
committed
add makeBlobPath inline helper for esp32
1 parent 31ba971 commit 8d5eaf5

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

examples/companion_radio/DataStore.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -564,13 +564,16 @@ bool DataStore::deleteBlobByKey(const uint8_t key[], int key_len) {
564564
return true; // this is just a stub on NRF52/STM32 platforms
565565
}
566566
#else
567-
uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]) {
568-
char path[64];
567+
inline void makeBlobPath(const uint8_t key[], int key_len, char* path, size_t path_size) {
569568
char fname[18];
570-
571569
if (key_len > 8) key_len = 8; // just use first 8 bytes (prefix)
572570
mesh::Utils::toHex(fname, key, key_len);
573571
sprintf(path, "/bl/%s", fname);
572+
}
573+
574+
uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]) {
575+
char path[64];
576+
makeBlobPath(key, key_len, path, sizeof(path));
574577

575578
if (_fs->exists(path)) {
576579
File f = openRead(_fs, path);
@@ -585,11 +588,7 @@ uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_b
585588

586589
bool DataStore::putBlobByKey(const uint8_t key[], int key_len, const uint8_t src_buf[], uint8_t len) {
587590
char path[64];
588-
char fname[18];
589-
590-
if (key_len > 8) key_len = 8; // just use first 8 bytes (prefix)
591-
mesh::Utils::toHex(fname, key, key_len);
592-
sprintf(path, "/bl/%s", fname);
591+
makeBlobPath(key, key_len, path, sizeof(path));
593592

594593
File f = openWrite(_fs, path);
595594
if (f) {
@@ -604,11 +603,7 @@ bool DataStore::putBlobByKey(const uint8_t key[], int key_len, const uint8_t src
604603

605604
bool DataStore::deleteBlobByKey(const uint8_t key[], int key_len) {
606605
char path[64];
607-
char fname[18];
608-
609-
if (key_len > 8) key_len = 8; // just use first 8 bytes (prefix)
610-
mesh::Utils::toHex(fname, key, key_len);
611-
sprintf(path, "/bl/%s", fname);
606+
makeBlobPath(key, key_len, path, sizeof(path));
612607

613608
_fs->remove(path);
614609

0 commit comments

Comments
 (0)