diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/os/kv.h | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/os/kv.h')
-rw-r--r-- | src/os/kv.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/os/kv.h b/src/os/kv.h new file mode 100644 index 000000000..64048b088 --- /dev/null +++ b/src/os/kv.h @@ -0,0 +1,76 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_OS_KV_H +#define CEPH_OS_KV_H + +#include <string> +#include "include/byteorder.h" + +// some key encoding helpers +template<typename T> +inline static void _key_encode_u32(uint32_t u, T *key) { + uint32_t bu; +#ifdef CEPH_BIG_ENDIAN + bu = u; +#elif defined(CEPH_LITTLE_ENDIAN) + bu = swab(u); +#else +# error wtf +#endif + key->append((char*)&bu, 4); +} + +template<typename T> +inline static void _key_encode_u32(uint32_t u, size_t pos, T *key) { + uint32_t bu; +#ifdef CEPH_BIG_ENDIAN + bu = u; +#elif defined(CEPH_LITTLE_ENDIAN) + bu = swab(u); +#else +# error wtf +#endif + key->replace(pos, sizeof(bu), (char*)&bu, sizeof(bu)); +} + +inline static const char *_key_decode_u32(const char *key, uint32_t *pu) { + uint32_t bu; + memcpy(&bu, key, 4); +#ifdef CEPH_BIG_ENDIAN + *pu = bu; +#elif defined(CEPH_LITTLE_ENDIAN) + *pu = swab(bu); +#else +# error wtf +#endif + return key + 4; +} + +template<typename T> +inline static void _key_encode_u64(uint64_t u, T *key) { + uint64_t bu; +#ifdef CEPH_BIG_ENDIAN + bu = u; +#elif defined(CEPH_LITTLE_ENDIAN) + bu = swab(u); +#else +# error wtf +#endif + key->append((char*)&bu, 8); +} + +inline static const char *_key_decode_u64(const char *key, uint64_t *pu) { + uint64_t bu; + memcpy(&bu, key, 8); +#ifdef CEPH_BIG_ENDIAN + *pu = bu; +#elif defined(CEPH_LITTLE_ENDIAN) + *pu = swab(bu); +#else +# error wtf +#endif + return key + 8; +} + +#endif |