diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2012-09-25 15:47:25 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2012-09-25 15:47:25 (GMT) |
commit | 6a89177036b5808ed0ce06ce0aab3af056b56984 (patch) | |
tree | 43367eb16716e1a2f074e2af07121e2723eae8d8 /src/H5Fprivate.h | |
parent | 50e3990f2a9e3bba421460d8d5cb21bb6f6e98fe (diff) | |
download | hdf5-6a89177036b5808ed0ce06ce0aab3af056b56984.zip hdf5-6a89177036b5808ed0ce06ce0aab3af056b56984.tar.gz hdf5-6a89177036b5808ed0ce06ce0aab3af056b56984.tar.bz2 |
[svn-r22807] Description:
Add encode/decode API routines for property lists: H5Pencode/H5Pdecode.
Tested on:
FreeBSD/32 8.2 (loyalty) w/gcc4.6, w/C++ & FORTRAN, in debug mode
FreeBSD/64 8.2 (freedom) w/gcc4.6, w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x,
w/C++ & FORTRAN, w/threadsafe, in debug mode
Linux/64-amd64 2.6 (koala) w/Intel compilers, w/default API=1.6.x,
w/C++ & FORTRAN, in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, w/threadsafe, in production mode
Linux/PPC 2.6 (ostrich) w/C++ & FORTRAN, w/threadsafe, in debug mode
Linux/64-ia64 2.6 (ember) w/Intel compilers, w/parallel, C++ & FORTRAN,
in production mode
Mac OS X/32 10.7.3 (amazon) in debug mode
Mac OS X/32 10.7.3 (amazon) w/C++ & FORTRAN, w/threadsafe,
in production mode
Mac OS X/32 10.7.3 (amazon) w/parallel, in debug mode
Diffstat (limited to 'src/H5Fprivate.h')
-rw-r--r-- | src/H5Fprivate.h | 68 |
1 files changed, 63 insertions, 5 deletions
diff --git a/src/H5Fprivate.h b/src/H5Fprivate.h index 7c6fae8..f9df1eb 100644 --- a/src/H5Fprivate.h +++ b/src/H5Fprivate.h @@ -27,6 +27,7 @@ #include "H5FDpublic.h" /* File drivers */ /* Private headers needed by this file */ +#include "H5Vprivate.h" /* Vectors and arrays */ /****************************/ @@ -114,6 +115,35 @@ typedef struct H5F_blk_aggr_t H5F_blk_aggr_t; /* (Assumes that the high bits of the integer are zero) */ # define UINT64ENCODE_VAR(p, n, l) ENCODE_VAR(p, uint64_t, n, l) +/* Encode a 64-bit unsigned integer and its length into a variable-sized buffer */ +/* (Assumes that the high bits of the integer are zero) */ +# define UINT64ENCODE_VARLEN(p, n) { \ + uint64_t __n = (uint64_t)(n); \ + unsigned _s = H5V_limit_enc_size(__n); \ + \ + *(p)++ = (uint8_t)_s; \ + UINT64ENCODE_VAR(p, __n, _s); \ +} + +# define H5_ENCODE_UNSIGNED(p, n) { \ + HDcompile_assert(sizeof(unsigned) == sizeof(uint32_t)); \ + UINT32ENCODE(p, n) \ +} + +/* Assumes the endianness of uint64_t is the same as double */ +# define H5_ENCODE_DOUBLE(p, n) { \ + uint64_t _n; \ + size_t _u; \ + uint8_t *_p = (uint8_t*)(p); \ + \ + HDcompile_assert(sizeof(double) == 8); \ + HDcompile_assert(sizeof(double) == sizeof(uint64_t)); \ + HDmemcpy(&_n, &n, sizeof(double)); \ + for(_u = 0; _u < sizeof(uint64_t); _u++, _n >>= 8) \ + *_p++ = (uint8_t)(_n & 0xff); \ + (p) = (uint8_t *)(p) + 8; \ +} + /* DECODE converts little endian bytes pointed by p to integer values and store * it in i. For signed values, need to do sign-extension when converting * the last byte which carries the sign bit. @@ -134,11 +164,11 @@ typedef struct H5F_blk_aggr_t H5F_blk_aggr_t; } # define INT32DECODE(p, i) { \ - (i) = ( *(p) & 0xff); (p)++; \ - (i) |= ((int32_t)(*(p) & 0xff) << 8); (p)++; \ - (i) |= ((int32_t)(*(p) & 0xff) << 16); (p)++; \ - (i) |= ((int32_t)(((*(p) & 0xff) << 24) | \ - ((*(p) & 0x80) ? ~0xffffffff : 0x0))); (p)++; \ + (i) = ((int32_t)(*(p) & (unsigned)0xff)); (p)++; \ + (i) |= ((int32_t)(*(p) & (unsigned)0xff) << 8); (p)++; \ + (i) |= ((int32_t)(*(p) & (unsigned)0xff) << 16); (p)++; \ + (i) |= ((int32_t)(((*(p) & (unsigned)0xff) << 24) | \ + ((*(p) & (unsigned)0x80) ? (unsigned)(~0xffffffff) : (unsigned)0x0))); (p)++; \ } # define UINT32DECODE(p, i) { \ @@ -190,6 +220,34 @@ typedef struct H5F_blk_aggr_t H5F_blk_aggr_t; /* (Assumes that the high bits of the integer will be zero) */ # define UINT64DECODE_VAR(p, n, l) DECODE_VAR(p, n, l) +/* Decode a 64-bit unsigned integer and its length from a variable-sized buffer */ +/* (Assumes that the high bits of the integer will be zero) */ +# define UINT64DECODE_VARLEN(p, n) { \ + unsigned _s = *(p)++; \ + \ + UINT64DECODE_VAR(p, n, _s); \ +} + +# define H5_DECODE_UNSIGNED(p, n) { \ + HDcompile_assert(sizeof(unsigned) == sizeof(uint32_t)); \ + UINT32DECODE(p, n) \ +} + +/* Assumes the endianness of uint64_t is the same as double */ +# define H5_DECODE_DOUBLE(p, n) { \ + uint64_t _n; \ + size_t _u; \ + \ + HDcompile_assert(sizeof(double) == 8); \ + HDcompile_assert(sizeof(double) == sizeof(uint64_t)); \ + _n = 0; \ + (p) += 8; \ + for(_u = 0; _u < sizeof(uint64_t); _u++) \ + _n = (_n << 8) | *(--p); \ + HDmemcpy(&(n), &_n, sizeof(double)); \ + (p) += 8; \ +} + /* Address-related macros */ #define H5F_addr_overflow(X,Z) (HADDR_UNDEF==(X) || \ HADDR_UNDEF==(X)+(haddr_t)(Z) || \ |