]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: add STREAM_GETQ, STREAM_GETF
authorQuentin Young <qlyoung@cumulusnetworks.com>
Sun, 1 Mar 2020 06:20:40 +0000 (01:20 -0500)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 13 Apr 2020 17:25:25 +0000 (13:25 -0400)
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/stream.c
lib/stream.h

index f046572f41a2c3995fed6fabfa5fe87e6b055e18..683a130e446fd0c21150f3a1cd2b6fad2c6e359b 100644 (file)
@@ -543,6 +543,27 @@ uint64_t stream_getq(struct stream *s)
        return q;
 }
 
+bool stream_getq2(struct stream *s, uint64_t *q)
+{
+       STREAM_VERIFY_SANE(s);
+
+       if (STREAM_READABLE(s) < sizeof(uint64_t)) {
+               STREAM_BOUND_WARN2(s, "get uint64");
+               return false;
+       }
+
+       *q = ((uint64_t)s->data[s->getp++]) << 56;
+       *q |= ((uint64_t)s->data[s->getp++]) << 48;
+       *q |= ((uint64_t)s->data[s->getp++]) << 40;
+       *q |= ((uint64_t)s->data[s->getp++]) << 32;
+       *q |= ((uint64_t)s->data[s->getp++]) << 24;
+       *q |= ((uint64_t)s->data[s->getp++]) << 16;
+       *q |= ((uint64_t)s->data[s->getp++]) << 8;
+       *q |= ((uint64_t)s->data[s->getp++]);
+
+       return true;
+}
+
 /* Get next long word from the stream. */
 uint32_t stream_get_ipv4(struct stream *s)
 {
index 6fcf9a53cfc56b5c18e9b95faee995449f1e9cd4..5c7d94fab8f822978e29f04767fa5c2db5c50dda 100644 (file)
@@ -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)))                          \