*out = value;
return SR_OK;
}
+
+SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec,
+ const uint8_t *data)
+{
+ float value;
+ const uint8_t *ptr;
+
+ ptr = &data[spec->offset];
+
+ switch (spec->type) {
+ case BVT_UINT8:
+ value = read_u8(ptr);
+ break;
+ case BVT_BE_UINT16:
+ value = read_u16be(ptr);
+ break;
+ case BVT_BE_UINT24:
+ value = read_u24be(ptr);
+ break;
+ case BVT_BE_UINT32:
+ value = read_u32be(ptr);
+ break;
+ case BVT_BE_UINT64:
+ value = read_u64be(ptr);
+ break;
+ case BVT_BE_FLOAT:
+ value = read_fltbe(ptr);
+ break;
+ case BVT_LE_UINT16:
+ value = read_u16le(ptr);
+ break;
+ case BVT_LE_UINT24:
+ value = read_u24le(ptr);
+ break;
+ case BVT_LE_UINT32:
+ value = read_u32le(ptr);
+ break;
+ case BVT_LE_UINT64:
+ value = read_u64le(ptr);
+ break;
+ case BVT_LE_FLOAT:
+ value = read_fltle(ptr);
+ break;
+ default:
+ return SR_ERR_ARG;
+ }
+
+ if (out)
+ *out = value;
+ return SR_OK;
+}
SR_PRIV int bv_get_value_len(float *out, const struct binary_value_spec *spec,
const uint8_t *data, size_t length);
+/**
+ * Read extract a value from a binary data image, without bound check.
+ *
+ * @param[out] out Pointer to output buffer (conversion result)
+ * @param[in] spec Binary value specification
+ * @param[in] data Pointer to binary input data
+ *
+ * @return SR_OK on success, SR_ERR_* error code on failure.
+ */
+SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec,
+ const uint8_t *data);
+
/*--- crc.c -----------------------------------------------------------------*/
#define SR_CRC16_DEFAULT_INIT 0xffffU