Some msgb formatting functions.
authorIngo Albrecht <prom@berlin.ccc.de>
Wed, 24 Feb 2010 01:28:11 +0000 (02:28 +0100)
committerHarald Welte <laforge@gnumonks.org>
Sun, 7 Mar 2010 10:47:09 +0000 (11:47 +0100)
src/target/firmware/include/comm/msgb.h

index 6114d4b..c89364a 100644 (file)
@@ -85,6 +85,26 @@ static inline unsigned char *msgb_put(struct msgb *msgb, unsigned int len)
        msgb->len += len;
        return tmp;
 }
+static inline void msgb_put_u32(struct msgb *msgb, uint32_t word)
+{
+       uint8_t *space = msgb_put(msgb, 4);
+       space[0] = word >> 24 & 0xFF;
+       space[1] = word >> 16 & 0xFF;
+       space[2] = word >> 8 & 0xFF;
+       space[3] = word & 0xFF;
+}
+static inline unsigned char *msgb_get(struct msgb *msgb, unsigned int len)
+{
+       unsigned char *tmp = msgb->data;
+       msgb->data += len;
+       msgb->len -= len;
+       return tmp;
+}
+static inline uint32_t msgb_get_u32(struct msgb *msgb)
+{
+       uint8_t *space = msgb_get(msgb, 4);
+       return space[0] << 24 | space[1] << 16 | space[2] << 8 | space[3];
+}
 static inline unsigned char *msgb_push(struct msgb *msgb, unsigned int len)
 {
        msgb->data -= len;