From: Greg Hudson Date: Wed, 13 Nov 2019 05:53:24 +0000 (-0500) Subject: Add k5-buf.h helpers for serializing integers X-Git-Tag: krb5-1.18-beta1~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3e08616316aff2314feb9358c5c02f9a61a67b9;p=thirdparty%2Fkrb5.git Add k5-buf.h helpers for serializing integers --- 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 */