diff --git a/stfx/stfx-library.h b/stfx/stfx-library.h index d6b75f2..2d0c7a5 100644 --- a/stfx/stfx-library.h +++ b/stfx/stfx-library.h @@ -79,9 +79,9 @@ namespace stfx { .unit("ms", 2, -1, 1) .unit("ms", 1, -10, 10) .unit("ms", 0, -1000, 1000) - .unit("seconds", 2, sToMs, msToS, -1e3, 1e3) - .unit("seconds", 1, sToMs, msToS, -1e4, 1e4) - .unit("seconds", 0, sToMs, msToS); + .unit(" sec", 2, sToMs, msToS, -1e3, 1e3) + .unit(" sec", 1, sToMs, msToS, -1e4, 1e4) + .unit(" sec", 0, sToMs, msToS); } template RangeParam & rangeSec(RangeParam ¶m) { @@ -89,9 +89,9 @@ namespace stfx { .unit("ms", 2, msToS, sToMs, -1e-3, 1e-3) .unit("ms", 1, msToS, sToMs, -1e-2, 1e-2) .unit("ms", 0, msToS, sToMs, -1e-1, 1e-1) - .unit("seconds", 2, -1, 1) - .unit("seconds", 1, -10, 10) - .unit("seconds", 0); + .unit(" sec", 2, -1, 1) + .unit(" sec", 1, -10, 10) + .unit(" sec", 0); } } diff --git a/stfx/storage/storage.h b/stfx/storage/storage.h index 67b75cb..33a9a32 100644 --- a/stfx/storage/storage.h +++ b/stfx/storage/storage.h @@ -73,7 +73,7 @@ struct StorageCborWriter { writeValue(value); } -protected: +private: signalsmith::cbor::CborWriter cbor; #define STORAGE_BASIC_INT(V) \ @@ -165,6 +165,10 @@ struct StorageCborReader { } private: + Cbor cbor; + const char *filterKeyBytes = nullptr; + size_t filterKeyLength = 0; + template void readValue(Obj &obj) { if (compact) { @@ -225,11 +229,27 @@ private: }); array.resize(length); } -protected: - Cbor cbor; - const char *filterKeyBytes = nullptr; - size_t filterKeyLength = 0; +#define STORAGE_TYPED_ARRAY(T) \ + void readValue(std::vector &array) { \ + if (cbor.isTypedArray()) { \ + array.resize(cbor.typedArrayLength()); \ + cbor.readTypedArray(array); \ + } else { \ + readValue>(array); \ + } \ + } + STORAGE_TYPED_ARRAY(uint8_t) + STORAGE_TYPED_ARRAY(int8_t) + STORAGE_TYPED_ARRAY(uint16_t) + STORAGE_TYPED_ARRAY(int16_t) + STORAGE_TYPED_ARRAY(uint32_t) + STORAGE_TYPED_ARRAY(int32_t) + STORAGE_TYPED_ARRAY(uint64_t) + STORAGE_TYPED_ARRAY(int64_t) + STORAGE_TYPED_ARRAY(float) + STORAGE_TYPED_ARRAY(double) +#undef STORAGE_TYPED_ARRAY static bool keyMatch(const char *key, const char *filterKeyBytes, size_t filterKeyLength) { for (size_t i = 0; i < filterKeyLength; ++i) {