From c3e08616316aff2314feb9358c5c02f9a61a67b9 Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Wed, 13 Nov 2019 00:53:24 -0500 Subject: [PATCH] Add k5-buf.h helpers for serializing integers --- src/include/k5-buf.h | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/include/k5-buf.h b/src/include/k5-buf.h index 48e2a7d53f..f2cdb0cbe2 100644 --- a/src/include/k5-buf.h +++ b/src/include/k5-buf.h @@ -108,4 +108,58 @@ int k5_buf_status(struct k5buf *buf); */ void k5_buf_free(struct k5buf *buf); +static inline void +k5_buf_add_uint16_be(struct k5buf *buf, uint16_t val) +{ + void *p = k5_buf_get_space(buf, 2); + + if (p != NULL) + store_16_be(val, p); +} + +static inline void +k5_buf_add_uint16_le(struct k5buf *buf, uint16_t val) +{ + void *p = k5_buf_get_space(buf, 2); + + if (p != NULL) + store_16_le(val, p); +} + +static inline void +k5_buf_add_uint32_be(struct k5buf *buf, uint32_t val) +{ + void *p = k5_buf_get_space(buf, 4); + + if (p != NULL) + store_32_be(val, p); +} + +static inline void +k5_buf_add_uint32_le(struct k5buf *buf, uint32_t val) +{ + void *p = k5_buf_get_space(buf, 4); + + if (p != NULL) + store_32_le(val, p); +} + +static inline void +k5_buf_add_uint64_be(struct k5buf *buf, uint64_t val) +{ + void *p = k5_buf_get_space(buf, 8); + + if (p != NULL) + store_64_be(val, p); +} + +static inline void +k5_buf_add_uint64_le(struct k5buf *buf, uint64_t val) +{ + void *p = k5_buf_get_space(buf, 8); + + if (p != NULL) + store_64_le(val, p); +} + #endif /* K5_BUF_H */ -- 2.47.2