summaryrefslogtreecommitdiff
path: root/lib/stream.h
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2020-03-01 01:20:40 -0500
committerQuentin Young <qlyoung@cumulusnetworks.com>2020-04-13 13:25:25 -0400
commitc2b5a4e5ff6135b9f530dbc5a89611cd61fe6419 (patch)
tree6f342185a8343ab1b00d90539fb7a77a3841cc29 /lib/stream.h
parent3b55aba1958c78b8838ce9ee5eed865d22d2787b (diff)
lib: add STREAM_GETQ, STREAM_GETF
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/stream.h')
-rw-r--r--lib/stream.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/stream.h b/lib/stream.h
index 6fcf9a53cf..5c7d94fab8 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -215,6 +215,7 @@ extern bool stream_getl2(struct stream *s, uint32_t *l);
extern uint32_t stream_getl_from(struct stream *, size_t);
extern uint64_t stream_getq(struct stream *);
extern uint64_t stream_getq_from(struct stream *, size_t);
+bool stream_getq2(struct stream *s, uint64_t *q);
extern uint32_t stream_get_ipv4(struct stream *);
/* IEEE-754 floats */
@@ -402,6 +403,25 @@ static inline const uint8_t *ptr_get_be32(const uint8_t *ptr, uint32_t *out)
(P) = _pval; \
} while (0)
+#define STREAM_GETF(S, P) \
+ do { \
+ union { \
+ float r; \
+ uint32_t d; \
+ } _pval; \
+ if (stream_getl2((S), &_pval.d)) \
+ goto stream_failure; \
+ (P) = _pval.r; \
+ } while (0)
+
+#define STREAM_GETQ(S, P) \
+ do { \
+ uint64_t _pval; \
+ if (!stream_getq2((S), &_pval)) \
+ goto stream_failure; \
+ (P) = _pval; \
+ } while (0)
+
#define STREAM_GET(P, STR, SIZE) \
do { \
if (!stream_get2((P), (STR), (SIZE))) \