Support reading typed arrays (not just writing them)
This commit is contained in:
parent
253e7ffbf0
commit
e295fadeb4
@ -79,9 +79,9 @@ namespace stfx {
|
|||||||
.unit("ms", 2, -1, 1)
|
.unit("ms", 2, -1, 1)
|
||||||
.unit("ms", 1, -10, 10)
|
.unit("ms", 1, -10, 10)
|
||||||
.unit("ms", 0, -1000, 1000)
|
.unit("ms", 0, -1000, 1000)
|
||||||
.unit("seconds", 2, sToMs, msToS, -1e3, 1e3)
|
.unit(" sec", 2, sToMs, msToS, -1e3, 1e3)
|
||||||
.unit("seconds", 1, sToMs, msToS, -1e4, 1e4)
|
.unit(" sec", 1, sToMs, msToS, -1e4, 1e4)
|
||||||
.unit("seconds", 0, sToMs, msToS);
|
.unit(" sec", 0, sToMs, msToS);
|
||||||
}
|
}
|
||||||
template<class RangeParam>
|
template<class RangeParam>
|
||||||
RangeParam & rangeSec(RangeParam ¶m) {
|
RangeParam & rangeSec(RangeParam ¶m) {
|
||||||
@ -89,9 +89,9 @@ namespace stfx {
|
|||||||
.unit("ms", 2, msToS, sToMs, -1e-3, 1e-3)
|
.unit("ms", 2, msToS, sToMs, -1e-3, 1e-3)
|
||||||
.unit("ms", 1, msToS, sToMs, -1e-2, 1e-2)
|
.unit("ms", 1, msToS, sToMs, -1e-2, 1e-2)
|
||||||
.unit("ms", 0, msToS, sToMs, -1e-1, 1e-1)
|
.unit("ms", 0, msToS, sToMs, -1e-1, 1e-1)
|
||||||
.unit("seconds", 2, -1, 1)
|
.unit(" sec", 2, -1, 1)
|
||||||
.unit("seconds", 1, -10, 10)
|
.unit(" sec", 1, -10, 10)
|
||||||
.unit("seconds", 0);
|
.unit(" sec", 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -73,7 +73,7 @@ struct StorageCborWriter {
|
|||||||
writeValue(value);
|
writeValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
signalsmith::cbor::CborWriter cbor;
|
signalsmith::cbor::CborWriter cbor;
|
||||||
|
|
||||||
#define STORAGE_BASIC_INT(V) \
|
#define STORAGE_BASIC_INT(V) \
|
||||||
@ -165,6 +165,10 @@ struct StorageCborReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Cbor cbor;
|
||||||
|
const char *filterKeyBytes = nullptr;
|
||||||
|
size_t filterKeyLength = 0;
|
||||||
|
|
||||||
template<class Obj>
|
template<class Obj>
|
||||||
void readValue(Obj &obj) {
|
void readValue(Obj &obj) {
|
||||||
if (compact) {
|
if (compact) {
|
||||||
@ -225,11 +229,27 @@ private:
|
|||||||
});
|
});
|
||||||
array.resize(length);
|
array.resize(length);
|
||||||
}
|
}
|
||||||
protected:
|
|
||||||
Cbor cbor;
|
|
||||||
|
|
||||||
const char *filterKeyBytes = nullptr;
|
#define STORAGE_TYPED_ARRAY(T) \
|
||||||
size_t filterKeyLength = 0;
|
void readValue(std::vector<T> &array) { \
|
||||||
|
if (cbor.isTypedArray()) { \
|
||||||
|
array.resize(cbor.typedArrayLength()); \
|
||||||
|
cbor.readTypedArray(array); \
|
||||||
|
} else { \
|
||||||
|
readValue<std::vector<T>>(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) {
|
static bool keyMatch(const char *key, const char *filterKeyBytes, size_t filterKeyLength) {
|
||||||
for (size_t i = 0; i < filterKeyLength; ++i) {
|
for (size_t i = 0; i < filterKeyLength; ++i) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user